Skip to content

Commit

Permalink
Use parametrize in test_format_url
Browse files Browse the repository at this point in the history
  • Loading branch information
Mews committed Jun 19, 2024
1 parent c566fb8 commit 83e30ef
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions tests/networking/test_formatter.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
from tiny_web_crawler.networking.formatter import format_url, DEFAULT_SCHEME

def test_format_url() -> None:
assert (
format_url("/test", "http://example.com")
== "http://example.com/test"
)

assert (
format_url("http://example.com/test", "http://example.com")
== "http://example.com/test"
)
import pytest

assert (
format_url('path1/path2', 'http://example.com')
== 'http://example.com/path1/path2'
)

assert (
format_url('/path1/path2', 'http://example.com')
== 'http://example.com/path1/path2'
)
from tiny_web_crawler.networking.formatter import format_url, DEFAULT_SCHEME

assert (
format_url('path.com', 'http://example.com')
== DEFAULT_SCHEME + 'path.com'
)
@pytest.mark.parametrize(
"url, base_url, expected",
[
("/test", "http://example.com", "http://example.com/test"),
("http://example.com/test", "http://example.com", "http://example.com/test"),
("path1/path2", "http://example.com", "http://example.com/path1/path2"),
("/path1/path2", "http://example.com", "http://example.com/path1/path2"),
("path.com", "http://example.com", f"{DEFAULT_SCHEME}path.com"),
]
)
def test_format_url(url: str, base_url: str, expected: str) -> None:
assert format_url(url, base_url) == expected

0 comments on commit 83e30ef

Please # to comment.