-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_config.py
More file actions
82 lines (66 loc) · 2.52 KB
/
test_config.py
File metadata and controls
82 lines (66 loc) · 2.52 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
"""test suite for spiderexpress.Configuration"""
from typing import Dict
import pytest
import yaml
from spiderexpress import Configuration
from spiderexpress.types import from_dict
# pylint: disable=W0621
def test_parse_configuration_from_file():
"""Should parse a configuration from a YAML file."""
with open(
"tests/stubs/sevens_grader_random_test.pe.yml", "r", encoding="utf8"
) as file:
config = yaml.safe_load(file)
assert from_dict(Configuration, config) is not None
def test_parse_configuration_from_dict():
"""Should parse a configuration from a file."""
config = from_dict(Configuration, {"project_name": "test", "seeds": {}})
assert config is not None
assert config.project_name == "test"
assert config.db_url == "sqlite:///test.db"
assert config.max_iteration == 10000
assert config.empty_seeds == "stop"
assert config.layers == {}
assert config.seeds == {}
def test_fail_to_open_seeds_from_file():
"""Should fail to parse a configuration from a file."""
with pytest.raises(FileNotFoundError):
from_dict(Configuration, {"seed_file": "non_existent_file"})
def test_open_seeds_from_file():
"""Should parse a configuration from a file with a seed file."""
config = from_dict(Configuration, {"seed_file": "tests/stubs/seeds.json"})
assert config is not None
assert config.seeds == {"test": ["1", "2", "3"]}
@pytest.mark.parametrize(
["configuration"],
[
pytest.param(
{
"layers": {
"test": {
"connector": {"csv": {"n": 1}},
"routers": [],
"sampler": {"random": {"n": 1}},
}
},
"seeds": {"test": ["1", "13"]},
},
id="empty_router",
),
],
)
def test_parse_layer_configuration(configuration: Dict):
"""Should parse a layer configuration."""
config = from_dict(Configuration, configuration)
assert config is not None
assert config.project_name == "spider"
assert config.db_url == "sqlite:///spider.db"
assert config.max_iteration == 10000
assert config.empty_seeds == "stop"
assert config.seeds == {"test": ["1", "13"]}
def test_layers_must_have_a_router_configuration():
"""Should fail to parse a configuration without a router configuration."""
with pytest.raises(ValueError):
from_dict(
Configuration, {"layers": {"test": {}}, "seeds": {"test": ["1", "13"]}}
)