1
1
import os .path
2
2
3
+ import pytest
4
+
3
5
from gs_api_client import Configuration
4
6
from examples .configloader import load_config
5
7
6
8
7
9
CURRENT_DIR = os .path .dirname (os .path .realpath (__file__ ))
8
10
11
+
9
12
def test_debug_is_disabled_by_default ():
10
13
config = Configuration ()
11
14
assert not config .debug
@@ -17,11 +20,45 @@ def test_tls_certs_are_verified_by_default():
17
20
18
21
19
22
def test_load_config_from_yaml ():
20
- """" Make sure we can load a config from a given YAML file."""
23
+ """Make sure we can load a config from a given YAML file."""
21
24
22
25
example_config = os .path .join (CURRENT_DIR , "example-config.yaml" )
23
26
res = load_config (example_config )
24
27
assert isinstance (res , list )
25
28
assert len (res ) == 2
29
+ assert isinstance (res [0 ], dict )
26
30
assert res [0 ]["name" ] == "default"
27
31
assert res [1 ]["name" ] == "something-else"
32
+
33
+
34
+ def test_load_config_handles_non_existing_file ():
35
+ """ "Ensure load_config raises FileNotFoundError."""
36
+
37
+ with pytest .raises (FileNotFoundError ):
38
+ load_config ("fufu.yaml" )
39
+
40
+
41
+ def test_load_config_checks_for_bogus_input ():
42
+ """ "Ensure load_config checks it's input."""
43
+
44
+ with pytest .raises (AssertionError ):
45
+ load_config (42 )
46
+
47
+ with pytest .raises (AssertionError ):
48
+ load_config ("" )
49
+
50
+
51
+ def test_load_config_propagates_parsing_errors ():
52
+ """ "Ensure load_config raises any error during parsing."""
53
+
54
+ import yaml
55
+
56
+ not_a_yaml_file = os .path .join (CURRENT_DIR , "test_config.py" )
57
+ with pytest .raises (yaml .YAMLError ):
58
+ load_config (not_a_yaml_file )
59
+
60
+
61
+ def test_load_config_has_doc_string ():
62
+ """ "Make sure load_config is documented."""
63
+
64
+ assert load_config .__doc__
0 commit comments