-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_version.py
80 lines (55 loc) · 2.22 KB
/
test_version.py
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
from collections import OrderedDict
import pytest
from buildrunner.config import loader
from buildrunner.config.loader import (
BuildRunnerVersionError,
ConfigVersionFormatError,
ConfigVersionTypeError,
)
buildrunner_version = "2.0.701"
config_version = "2.0"
@pytest.fixture(name="config")
def fixture_config_file():
config = OrderedDict({"version": config_version})
yield config
@pytest.fixture(name="version_file", autouse=True)
def fixture_setup_version_file(tmp_path):
version_file = tmp_path / "version.py"
version_file.write_text(f"__version__ = '{buildrunner_version}'")
original_path = loader.VERSION_FILE_PATH
loader.VERSION_FILE_PATH = str(version_file)
yield str(version_file)
loader.VERSION_FILE_PATH = original_path
def test_valid_version_file(config):
loader._validate_version(config=config)
def test_missing_version_file(config):
# No exception for a missing version file it just prints a warning
loader.VERSION_FILE_PATH = "bogus"
loader._validate_version(config=config)
def test_missing_version_in_version_file(config, version_file):
with open(version_file, "w") as file:
file.truncate()
with pytest.raises(BuildRunnerVersionError):
loader._validate_version(config=config)
def test_invalid_delim_version(config, version_file):
with open(version_file, "w") as file:
file.truncate()
file.write("__version__: '1.3.4'")
with pytest.raises(ConfigVersionFormatError):
loader._validate_version(config=config)
def test_invalid_config_number_version(config, version_file):
with open(version_file, "w") as file:
file.truncate()
file.write("__version__ = '1'")
with pytest.raises(ConfigVersionFormatError):
loader._validate_version(config=config)
def test_invalid_config_version_type(config, version_file):
with open(version_file, "w") as file:
file.truncate()
file.write("__version__ = 'two.zero.five'")
with pytest.raises(ConfigVersionTypeError):
loader._validate_version(config=config)
def test_bad_version(config):
config = OrderedDict({"version": 2.1})
with pytest.raises(ConfigVersionFormatError):
loader._validate_version(config=config)