forked from ionelmc/python-hunter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_config.py
More file actions
58 lines (50 loc) · 2.5 KB
/
test_config.py
File metadata and controls
58 lines (50 loc) · 2.5 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
import os
import pytest
import hunter
@pytest.fixture(autouse=True)
def cleanup():
hunter._default_trace_args = None
hunter._default_config.clear()
yield
hunter._default_trace_args = None
hunter._default_config.clear()
@pytest.mark.parametrize('config', [
('foobar', (('x',), {'y': 1}), {},
'''Failed to load hunter config from PYTHONHUNTERCONFIG 'foobar': NameError'''),
('foobar=1', (('x',), {'y': 1}), {}, '''Discarded config from PYTHONHUNTERCONFIG foobar=1: '''),
('foobar=1, force_colors=1', (('x',), {'y': 1}), {'force_colors': 1},
'''Discarded config from PYTHONHUNTERCONFIG foobar=1: '''),
('klass=123', (('x',), {'y': 1}), {'klass': 123}, ''),
('stream=123', (('x',), {'y': 1}), {'stream': 123}, ''),
('force_colors=123', (('x',), {'y': 1}), {'force_colors': 123}, ''),
('filename_alignment=123', (('x',), {'y': 1}), {'filename_alignment': 123}, ''),
('thread_alignment=123', (('x',), {'y': 1}), {'thread_alignment': 123}, ''),
('repr_limit=123', (('x',), {'y': 1}), {'repr_limit': 123}, ''),
('stdlib=0', (('x',), {'y': 1, 'stdlib': 0}), {}, ''),
('clear_env_var=1', (('x',), {'y': 1, 'clear_env_var': 1}), {}, ''),
('threading_support=1', (('x',), {'y': 1, 'threading_support': 1}), {}, ''),
('threads_support=1', (('x',), {'y': 1, 'threads_support': 1}), {}, ''),
('thread_support=1', (('x',), {'y': 1, 'thread_support': 1}), {}, ''),
('threadingsupport=1', (('x',), {'y': 1, 'threadingsupport': 1}), {}, ''),
('threadssupport=1', (('x',), {'y': 1, 'threadssupport': 1}), {}, ''),
('threadsupport=1', (('x',), {'y': 1, 'threadsupport': 1}), {}, ''),
('threading=1', (('x',), {'y': 1, 'threading': 1}), {}, ''),
('threads=1', (('x',), {'y': 1, 'threads': 1}), {}, ''),
('thread=1', (('x',), {'y': 1, 'thread': 1}), {}, ''),
('', (('x',), {'y': 1}), {}, ''),
], ids=lambda x: repr(x))
def test_config(monkeypatch, config, capsys):
env, result, defaults, stderr = config
monkeypatch.setitem(os.environ, 'PYTHONHUNTERCONFIG', env)
hunter.load_config()
assert hunter._apply_config(('x',), {'y': 1}) == result
assert hunter._default_config == defaults
output = capsys.readouterr()
assert output.err.startswith(stderr)
def test_empty_config(monkeypatch, capsys):
monkeypatch.setitem(os.environ, 'PYTHONHUNTERCONFIG', ' ')
hunter.load_config()
assert hunter._apply_config((), {}) == ((), {})
assert hunter._default_config == {}
output = capsys.readouterr()
assert output.err == ''