1 | #!/usr/bin/env python3 |
||
2 | |||
3 | """Tests for the elementbase class""" |
||
4 | |||
5 | import unittest |
||
6 | |||
7 | from starstruct.elementnum import ElementNum |
||
8 | |||
9 | |||
10 | # pylint: disable=line-too-long,invalid-name |
||
11 | View Code Duplication | class TestElementNum(unittest.TestCase): |
|
0 ignored issues
–
show
Duplication
introduced
by
![]() |
|||
12 | """ElementNum module tests""" |
||
13 | |||
14 | def test_valid(self): |
||
15 | """Test field formats that are valid ElementNum elements.""" |
||
16 | |||
17 | test_fields = [ |
||
18 | ('a', '3b'), # 3 byte number: 0, 2^24-1 |
||
19 | ('b', 'H'), # unsigned short: 0, 65535 |
||
20 | ('c', '4Q'), # 32 signed byte number: (super big number) |
||
21 | ('d', 'l'), # signed long: -2^31, 2^31-1 |
||
22 | ] |
||
23 | |||
24 | for field in test_fields: |
||
25 | with self.subTest(field): # pylint: disable=no-member |
||
26 | out = ElementNum.valid(field) |
||
27 | self.assertTrue(out) |
||
28 | |||
29 | def test_not_valid(self): |
||
30 | """Test field formats that are not valid ElementNum elements.""" |
||
31 | |||
32 | test_fields = [ |
||
33 | ('a', '4x'), # 4 pad bytes |
||
34 | ('b', 'z'), # invalid |
||
35 | ('c', '1'), # invalid |
||
36 | ('d', '9S'), # invalid (must be lowercase) |
||
37 | ('e', '/'), # invalid |
||
38 | ('f', '?'), # invalid |
||
39 | ] |
||
40 | |||
41 | for field in test_fields: |
||
42 | with self.subTest(field): # pylint: disable=no-member |
||
43 | out = ElementNum.valid(field) |
||
44 | self.assertFalse(out) |
||
45 |