Skip to content

Commit

Permalink
test: Update Environment tests for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jul 25, 2024
1 parent d498ae3 commit a19d7e2
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions tests/test_environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,54 @@ def test_get_settings(environ):
assert re.search(r"^\S+j1\.log$", settings["LOG_FILE"])

if environ.items_dir:
feeds = json.loads(settings["FEEDS"])
feeds = json.loads(settings.pop("FEEDS"))
path, value = feeds.popitem()

assert list(settings) == ["LOG_FILE"]
assert feeds == {}
assert re.search(r"^file:///\S+j1\.jl$", path)
assert value == {"format": "jsonlines"}


@pytest.mark.parametrize(
("items_dir", "expected"),
("items_dir", "pattern"),
[
(
"https://host.example/path?query=value#fragment",
"https://host.example/path/p1/s1/j1.jl?query=value#fragment",
r"https://host\.example/path/p1/s1/j1\.jl\?query=value#fragment",
),
(
"https://host.example/path/",
"https://host.example/path/p1/s1/j1.jl", # no double slashes
),
(
"file:/root.dir/path?ignored#ignored",
"file:///root.dir/path/p1/s1/j1.jl",
r"file:///([A-Z]:/)?root\.dir/path/p1/s1/j1\.jl",
),
(
"file://hostname/root.dir/path?ignored#ignored",
"file:///root.dir/path/p1/s1/j1.jl",
r"file:///([A-Z]:/)?root.dir/path/p1/s1/j1.jl",
),
(
"file:///root.dir/path?ignored#ignored",
"file:///root.dir/path/p1/s1/j1.jl",
r"file:///([A-Z]:/)?root.dir/path/p1/s1/j1.jl",
),
],
)
@patch("os.listdir", lambda _: [])
@patch("os.makedirs", lambda _: _)
def test_get_settings_url(items_dir, expected):
def test_get_settings_url(items_dir, pattern):
config = Config(values={"logs_dir": "", "items_dir": items_dir})
environ = Environment(config, initenv={})

settings = environ.get_settings({"_project": "p1", "_spider": "s1", "_job": "j1"})
feeds = json.loads(settings.pop("FEEDS"))
path, value = feeds.popitem()

assert settings == {"FEEDS": f'{{"{expected}": {{"format": "jsonlines"}}}}'}
assert settings == {}
assert feeds == {}
assert re.search(pattern, path)
assert value == {"format": "jsonlines"}


@pytest.mark.parametrize("values", [{"items_dir": "../items"}, {"logs_dir": "../logs"}])
Expand Down

0 comments on commit a19d7e2

Please sign in to comment.