Skip to content

Commit 9915c73

Browse files
committed
test: Update Environment tests for Windows
1 parent d498ae3 commit 9915c73

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

tests/test_environ.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import re
4+
import time
45
from unittest.mock import patch
56

67
import pytest
@@ -23,48 +24,54 @@ def test_get_settings(environ):
2324
assert re.search(r"^\S+j1\.log$", settings["LOG_FILE"])
2425

2526
if environ.items_dir:
26-
feeds = json.loads(settings["FEEDS"])
27+
feeds = json.loads(settings.pop("FEEDS"))
2728
path, value = feeds.popitem()
2829

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

3335

3436
@pytest.mark.parametrize(
35-
("items_dir", "expected"),
37+
("items_dir", "pattern"),
3638
[
3739
(
3840
"https://host.example/path?query=value#fragment",
39-
"https://host.example/path/p1/s1/j1.jl?query=value#fragment",
41+
r"https://host\.example/path/p1/s1/j1\.jl\?query=value#fragment",
4042
),
4143
(
4244
"https://host.example/path/",
4345
"https://host.example/path/p1/s1/j1.jl", # no double slashes
4446
),
4547
(
4648
"file:/root.dir/path?ignored#ignored",
47-
"file:///root.dir/path/p1/s1/j1.jl",
49+
r"file:///([A-Z]:/)?root\.dir/path/p1/s1/j1\.jl",
4850
),
4951
(
5052
"file://hostname/root.dir/path?ignored#ignored",
51-
"file:///root.dir/path/p1/s1/j1.jl",
53+
r"file:///([A-Z]:/)?root.dir/path/p1/s1/j1.jl",
5254
),
5355
(
5456
"file:///root.dir/path?ignored#ignored",
55-
"file:///root.dir/path/p1/s1/j1.jl",
57+
r"file:///([A-Z]:/)?root.dir/path/p1/s1/j1.jl",
5658
),
5759
],
5860
)
5961
@patch("os.listdir", lambda _: [])
6062
@patch("os.makedirs", lambda _: _)
61-
def test_get_settings_url(items_dir, expected):
63+
def test_get_settings_url(items_dir, pattern):
6264
config = Config(values={"logs_dir": "", "items_dir": items_dir})
6365
environ = Environment(config, initenv={})
6466

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

67-
assert settings == {"FEEDS": f'{{"{expected}": {{"format": "jsonlines"}}}}'}
71+
assert settings == {}
72+
assert feeds == {}
73+
assert re.search(pattern, path)
74+
assert value == {"format": "jsonlines"}
6875

6976

7077
@pytest.mark.parametrize("values", [{"items_dir": "../items"}, {"logs_dir": "../logs"}])
@@ -96,6 +103,7 @@ def test_jobs_to_keep(chdir):
96103

97104
(directory / "j1.a").touch()
98105
(directory / "j2.b").touch()
106+
time.sleep(0.000001)
99107
(directory / "j3.c").touch()
100108
(directory / "j4.d").touch()
101109

0 commit comments

Comments
 (0)