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