-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathtest_datastructures.py
More file actions
81 lines (71 loc) · 2.08 KB
/
test_datastructures.py
File metadata and controls
81 lines (71 loc) · 2.08 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
# Copyright (C) 2021-2026 NV Access Limited
# This file may be used under the terms of the GNU General Public License, version 2 or later.
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html
from src.transform.datastructures import MajorMinorPatch
import unittest
class TestMajorMinorPatch(unittest.TestCase):
def test_compare(self):
"""Test comparing versions"""
self.assertLess(MajorMinorPatch(13, 2), MajorMinorPatch(13, 2, 1))
self.assertGreater(MajorMinorPatch(3, 2, 1), MajorMinorPatch(1, 2, 3))
def test_patch_optional(self):
"""Test that the patch number is optional and 0 by default"""
self.assertEqual(MajorMinorPatch(13, 2, 0), MajorMinorPatch(13, 2))
def test_toStr(self):
"""Test converting versions to string"""
self.assertEqual(str(MajorMinorPatch(1, 3, 4)), "1.3.4")
self.assertEqual(str(MajorMinorPatch(13, 2, 0)), "13.2.0")
def test_toStr_patch_optional(self):
"""Confirm that versions as string always include the patch number, 0 by default.
Even if the patch isn't specified, it should be included
so that the output is consistent - e.g. /views/en/2021.1.3/addonId/stable.json"""
self.assertEqual(str(MajorMinorPatch(13, 2)), "13.2.0")
def test_fromDict(self):
"""Test creating versions from dictionaries"""
self.assertEqual(
MajorMinorPatch(2, 3, 4),
MajorMinorPatch(
**{
"major": 2,
"minor": 3,
"patch": 4,
},
),
)
self.assertEqual(
MajorMinorPatch(2, 3, 0),
MajorMinorPatch(
**{
"major": 2,
"minor": 3,
"patch": 0,
},
),
)
def test_fromDict_patch_optional(self):
"""Test creating versions from dictionaries where the patch is not supplied"""
self.assertEqual(
MajorMinorPatch(2, 3, 0),
MajorMinorPatch(
**{
"major": 2,
"minor": 3,
},
),
)
def test_fromDict_throws(self):
"""Test creating versions from invalid dictionaries"""
with self.assertRaises(TypeError):
MajorMinorPatch(
**{
"patch": 2,
"minor": 2,
},
)
with self.assertRaises(TypeError):
MajorMinorPatch(
**{
"major": 2,
"patch": 2,
},
)