Issues (43)

starstruct/tests/test_elementpad.py (1 issue)

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