-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_including.py
More file actions
74 lines (57 loc) · 2.56 KB
/
test_including.py
File metadata and controls
74 lines (57 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import pathlib
import pytest
def test_resolve_dependencies_files():
from mxdev.including import resolve_dependencies
base = pathlib.Path(__file__).parent / "data"
file_list = resolve_dependencies(base / "file01.ini", base)
assert len(file_list) == 4
assert file_list[0].name == "file03.ini"
assert file_list[1].name == "file02.ini"
assert file_list[2].name == "file04.ini"
assert file_list[3].name == "file01.ini"
def test_resolve_dependencies_http(tmp_path, httpretty):
from mxdev.including import resolve_dependencies
base = pathlib.Path(__file__).parent / "data"
with open(base / "file_with_http_include02.ini") as fio:
httpretty.register_uri(
httpretty.GET,
"http://www.example.com/file_with_http_include02.ini",
fio.read(),
status=200,
)
with open(base / "file_with_http_include03.ini") as fio:
httpretty.register_uri(
httpretty.GET,
"http://www.example.com/file_with_http_include03.ini",
fio.read(),
status=200,
)
file_list = resolve_dependencies(base / "file_with_http_include01.ini", tmp_path)
assert len(file_list) == 4
def test_resolve_dependencies_filenotfound(tmp_path):
from mxdev.including import resolve_dependencies
base = pathlib.Path(__file__).parent / "data"
with pytest.raises(FileNotFoundError):
resolve_dependencies(base / "file__not_found.ini", tmp_path)
def test_read_with_included():
from mxdev.including import read_with_included
base = pathlib.Path(__file__).parent / "data"
cfg = read_with_included(base / "file01.ini")
assert cfg["settings"]["test"] == "1"
assert cfg["settings"]["unique_1"] == "1"
assert cfg["settings"]["unique_2"] == "2"
assert cfg["settings"]["unique_3"] == "3"
assert cfg["settings"]["unique_4"] == "4"
def test_resolve_dependencies_windows_path(tmp_path):
"""Test that Windows absolute paths with drive letters are handled correctly.
On Windows, paths like 'D:\\path\\to\\file.ini' should be treated as
file paths, not URLs (even though urlparse() interprets 'D:' as a scheme).
"""
from mxdev.including import resolve_dependencies
# Create a test file with no includes
test_file = tmp_path / "test_config.ini"
test_file.write_text("[settings]\ntest = value\n")
# Test with the actual path (on Windows this would be like D:\...\test_config.ini)
file_list = resolve_dependencies(str(test_file), str(tmp_path))
assert len(file_list) == 1
assert file_list[0] == test_file