summaryrefslogtreecommitdiffstats
path: root/tests/unit/test_eos_version.py
blob: 82f126947892a84e4551211b4dc5aef91cb27503 (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/python
# coding: utf-8 -*-
# pylint: disable=logger-format-interpolation
# pylint: disable=dangerous-default-value
# flake8: noqa: W503
# flake8: noqa: W1202

from __future__ import absolute_import, division, print_function

import sys

import pytest
from loguru import logger

from eos_downloader.models.version import BASE_VERSION_STR, EosVersion
from tests.lib.dataset import eos_version
from tests.lib.fixtures import generate_test_ids_list

logger.remove()
logger.add(sys.stderr, level="DEBUG")


@pytest.mark.parametrize(
    "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version")
)
def test_eos_version_from_str(EOS_VERSION):
    version = EosVersion.from_str(EOS_VERSION["version"])
    if EOS_VERSION["is_valid"]:
        assert version.major == EOS_VERSION["major"]
        assert version.minor == EOS_VERSION["minor"]
        assert version.patch == EOS_VERSION["patch"]
        assert version.rtype == EOS_VERSION["rtype"]
    else:
        assert str(version) == BASE_VERSION_STR


@pytest.mark.parametrize(
    "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version")
)
def test_eos_version_to_str(EOS_VERSION):
    version = EosVersion(**EOS_VERSION)
    if EOS_VERSION["is_valid"]:
        assert version.major == EOS_VERSION["major"]
        assert version.minor == EOS_VERSION["minor"]
        assert version.patch == EOS_VERSION["patch"]
        assert version.rtype == EOS_VERSION["rtype"]


@pytest.mark.parametrize(
    "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version")
)
def test_eos_version_branch(EOS_VERSION):
    if EOS_VERSION["is_valid"]:
        version = EosVersion(**EOS_VERSION)
        assert version.branch == f'{EOS_VERSION["major"]}.{EOS_VERSION["minor"]}'


@pytest.mark.parametrize(
    "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version")
)
def test_eos_version_eq_operator(EOS_VERSION):
    if not EOS_VERSION["is_valid"]:
        pytest.skip("not a valid version to test")
    version = EosVersion(**EOS_VERSION)
    logger.warning(f"version is: {version.dict()}")
    assert version == version


@pytest.mark.parametrize(
    "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version")
)
def test_eos_version_ge_operator(EOS_VERSION):
    if not EOS_VERSION["is_valid"]:
        pytest.skip("not a valid version to test")
    version = EosVersion(**EOS_VERSION)
    version_b = EosVersion.from_str(BASE_VERSION_STR)
    assert version >= version_b


@pytest.mark.parametrize(
    "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version")
)
def test_eos_version_gs_operator(EOS_VERSION):
    if not EOS_VERSION["is_valid"]:
        pytest.skip("not a valid version to test")
    version = EosVersion(**EOS_VERSION)
    version_b = EosVersion.from_str(BASE_VERSION_STR)
    assert version > version_b


@pytest.mark.parametrize(
    "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version")
)
def test_eos_version_le_operator(EOS_VERSION):
    if not EOS_VERSION["is_valid"]:
        pytest.skip("not a valid version to test")
    version = EosVersion(**EOS_VERSION)
    version_b = EosVersion.from_str(BASE_VERSION_STR)
    assert version_b <= version


@pytest.mark.parametrize(
    "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version")
)
def test_eos_version_ls_operator(EOS_VERSION):
    if not EOS_VERSION["is_valid"]:
        pytest.skip("not a valid version to test")
    version = EosVersion(**EOS_VERSION)
    version_b = EosVersion.from_str(BASE_VERSION_STR)
    assert version_b < version


@pytest.mark.parametrize(
    "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version")
)
def test_eos_version_ne_operator(EOS_VERSION):
    if not EOS_VERSION["is_valid"]:
        pytest.skip("not a valid version to test")
    version = EosVersion(**EOS_VERSION)
    version_b = EosVersion.from_str(BASE_VERSION_STR)
    assert version_b != version


@pytest.mark.parametrize(
    "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version")
)
def test_eos_version_match(EOS_VERSION):
    if not EOS_VERSION["is_valid"]:
        pytest.skip("not a valid version to test")
    version = EosVersion(**EOS_VERSION)
    assert version.match(f'=={EOS_VERSION["version"]}')
    assert version.match(f"!={BASE_VERSION_STR}")
    assert version.match(f">={BASE_VERSION_STR}")
    assert version.match(f">{BASE_VERSION_STR}")
    assert version.match("<=4.99.0F")
    assert version.match("<4.99.0F")


@pytest.mark.parametrize(
    "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version")
)
def test_eos_version_is_in_branch(EOS_VERSION):
    if not EOS_VERSION["is_valid"]:
        pytest.skip("not a valid version to test")
    version = EosVersion(**EOS_VERSION)
    assert version.is_in_branch(f"{EOS_VERSION['major']}.{EOS_VERSION['minor']}")


@pytest.mark.parametrize(
    "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version")
)
def test_eos_version_match_exception(EOS_VERSION):
    if not EOS_VERSION["is_valid"]:
        pytest.skip("not a valid version to test")
    with pytest.raises(Exception) as e_info:
        version = EosVersion(**EOS_VERSION)
        assert version.match(f'+={EOS_VERSION["version"]}')
        logger.info(f"receive exception: {e_info}")


@pytest.mark.parametrize(
    "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version")
)
def test_eos_version_compare_exception(EOS_VERSION):
    if not EOS_VERSION["is_valid"]:
        pytest.skip("not a valid version to test")
    with pytest.raises(Exception) as e_info:
        version = EosVersion(**EOS_VERSION)
        version._compare(BASE_VERSION_STR)
        logger.info(f"receive exception: {e_info}")