-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_config.py
More file actions
76 lines (48 loc) · 1.91 KB
/
test_config.py
File metadata and controls
76 lines (48 loc) · 1.91 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
import os.path
import shutil
import pytest
from gs_api_client import Configuration
from examples.configloader import load_config
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
def test_debug_is_disabled_by_default():
config = Configuration()
assert not config.debug
def test_tls_certs_are_verified_by_default():
config = Configuration()
assert config.verify_ssl
def test_load_config_from_yaml():
"""Make sure we can load a config from a given YAML file."""
example_config = os.path.join(CURRENT_DIR, "example-config.yaml")
res = load_config(example_config)
assert isinstance(res, list)
assert len(res) == 2
assert isinstance(res[0], dict)
assert res[0]["name"] == "default"
assert res[1]["name"] == "something-else"
def test_load_config_works_without_fileext(tmp_path):
"""Ensure load_config does not interpret file path or file name."""
example_config = os.path.join(CURRENT_DIR, "example-config.yaml")
dest = tmp_path / "a"
shutil.copyfile(example_config, dest)
res = load_config(dest)
assert isinstance(res, list)
assert len(res) == 2
def test_load_config_handles_non_existing_file():
""" "Ensure load_config raises FileNotFoundError."""
with pytest.raises(FileNotFoundError):
load_config("fufu.yaml")
def test_load_config_checks_for_bogus_input():
""" "Ensure load_config checks it's input."""
with pytest.raises(AssertionError):
load_config(42)
with pytest.raises(AssertionError):
load_config("")
def test_load_config_propagates_parsing_errors():
""" "Ensure load_config raises any error during parsing."""
import yaml
not_a_yaml_file = os.path.join(CURRENT_DIR, "test_config.py")
with pytest.raises(yaml.YAMLError):
load_config(not_a_yaml_file)
def test_load_config_has_doc_string():
""" "Make sure load_config is documented."""
assert load_config.__doc__