TestElementPad   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 35
loc 35
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_valid() 12 12 3
A test_not_valid() 19 19 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
Duplication introduced by
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