-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_config.py
More file actions
98 lines (78 loc) · 2.54 KB
/
test_config.py
File metadata and controls
98 lines (78 loc) · 2.54 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import runez
from pickley import bstrap, CFG
SAMPLE_CONFIG = """
base: {base}
cli: # empty
{meta}/config.json:
bundle:
dev: tox mgit
dev2: bundle:dev pipenv
delivery: wrap
include: custom.json
index: https://pypi-mirror.mycompany.net/pypi
pinned:
mgit: 1.2.1
tox:
delivery: custom-delivery
index: custom-index
install_timeout: 42
python: 2.8.1
version: 3.2.1
{meta}/custom.json:
delivery: wrap
foo: bar
include:
- bogus.json
- /dev/null/non-existent-config-file.json
install_timeout: 250
python: /dev/null/foo
version_check_delay: 15
defaults:
delivery: wrap
install_timeout: 1800
version_check_delay: 300
"""
def grab_sample(name):
path = runez.to_path(runez.DEV.tests_path("samples", name))
for item in path.iterdir():
runez.copy(item, f"{bstrap.DOT_META}/{item.name}")
CFG.set_cli("config.json", None, None, None, None)
CFG.set_base(".")
assert str(CFG.configs[0]) == "cli (0 values)"
def test_bogus_config(temp_cfg):
grab_sample("bogus-config")
assert CFG.resolved_bundle("") == []
assert CFG.resolved_bundle("foo") == ["foo"]
assert CFG.resolved_bundle("bundle:dev") == ["tox", "mgit"]
assert CFG.resolved_bundle("bundle:dev2") == ["tox", "mgit", "pipenv"]
assert CFG.pip_conf is None
assert CFG.pip_conf_index == bstrap.DEFAULT_MIRROR
actual = CFG.represented().strip()
expected = SAMPLE_CONFIG.strip().format(
base=runez.short(CFG.base),
meta=runez.short(CFG.meta),
)
assert actual == expected
def test_good_config(cli):
grab_sample("good-config")
assert CFG.resolved_bundle("bundle:dev") == ["tox", "poetry", "mgit", "pipenv"]
assert CFG.resolved_bundle("bundle:dev3") == ["mgit"]
cli.run("diagnostics")
assert cli.succeeded
assert "pip.conf : -missing-" in cli.logged
cli.run("config")
assert cli.succeeded
assert "dev2: bundle:dev3 pipenv" in cli.logged
assert "mgit: 1.2.1" in cli.logged
cli.run("-n install bundle:dev3")
assert cli.succeeded
assert "Would wrap mgit -> .pk/mgit-1.2.1/bin/mgit" in cli.logged
cli.run("-n install bundle:foo")
assert cli.failed
assert "Can't install 'bundle:foo', not configured" in cli.logged
def test_despecced():
assert CFG.despecced("mgit") == ("mgit", None)
assert CFG.despecced("mgit==1.0.0") == ("mgit", "1.0.0")
assert CFG.despecced(" mgit == 1.0.0 ") == ("mgit", "1.0.0")
assert CFG.despecced("mgit==") == ("mgit", None)
assert CFG.despecced(" mgit == ") == ("mgit", None)