TestPlumdUtilsFilter   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 3
Bugs 2 Features 1
Metric Value
c 3
b 2
f 1
dl 0
loc 70
rs 10
wmc 22

5 Methods

Rating   Name   Duplication   Size   Complexity  
B test_filter_normal_nondigits() 0 12 6
A test_filter_normal_digits() 0 11 4
A test_filter_normal_empty() 0 11 2
B test_filter_normal_noargs() 0 13 5
B test_filter_normal_random() 0 12 5
1
import os
2
import sys
3
import random
4
PY3 = sys.version_info > (3,)
5
6
import string
7
import unittest
8
9
MAX_DIFF = 8192
10
FILE_PATH = os.path.realpath(__file__)
11
PATH = os.path.dirname(FILE_PATH)
12
sys.path.insert(0, os.path.realpath(os.path.join(PATH, "../../../")))
13
import plumd.util
14
15
16
class TestPlumdUtilsFilter(unittest.TestCase):
17
18
19
    def test_filter_normal_digits(self):
20
        """ensure filter properly filtering for digits"""
21
        # chars to keep - only digits
22
        kchars = string.digits
23
        # chars to test - all chars
24
        test = "".join(char for char in map(chr, range(256)))
25
        fobj = plumd.util.Filter(kchars)
26
        result = fobj.process(test)
27
        # any non-digits found?
28
        check = "".join(char for char in result if char not in kchars)
29
        self.assertEquals(check, "")
30
31
32
    def test_filter_normal_nondigits(self):
33
        """ensure filter properly filtering for digits"""
34
        # chars to keep - only non-digits
35
        kchars = "".join(char for char in map(chr, range(256)) \
36
                         if char not in string.digits)
37
        # chars to test - all chars
38
        test = "".join(char for char in map(chr, range(256)))
39
        fobj = plumd.util.Filter(kchars)
40
        result = fobj.process(test)
41
        # any non-digits found?
42
        check = "".join(char for char in result if char not in kchars)
43
        self.assertEquals(check, "")
44
45
46
    def test_filter_normal_noargs(self):
47
        """ensure filter properly filtering for defaults"""
48
        if PY3:
49
            kchars = string.ascii_letters + string.digits + "_-"
50
        else:
51
            kchars = string.letters + string.digits + "_-"
0 ignored issues
show
Bug introduced by
The Module string does not seem to have a member named letters.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
52
        # chars to test - all chars
53
        test = "".join(char for char in map(chr, range(256)))
54
        fobj = plumd.util.Filter()
55
        result = fobj.process(test)
56
        # any non-digits found?
57
        check = "".join(char for char in result if char not in kchars)
58
        self.assertEquals(check, "")
59
60
61
    def test_filter_normal_empty(self):
62
        """ensure filter properly filtering for none values"""
63
        if PY3:
64
            kchars = string.ascii_letters + string.digits + "_-"
0 ignored issues
show
Unused Code introduced by
The variable kchars seems to be unused.
Loading history...
65
        else:
66
            kchars = string.letters + string.digits + "_-"
0 ignored issues
show
Bug introduced by
The Module string does not seem to have a member named letters.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
67
        # chars to test - all chars
68
        test = ""
69
        fobj = plumd.util.Filter()
70
        result = fobj.process(test)
71
        self.assertEquals(result, "")
72
73
74
    def test_filter_normal_random(self):
75
        """ensure filter properly filtering for random characters"""
76
        kchars = ""
77
        while(len(kchars) < 128):
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after while.
Loading history...
78
            kchars += chr(random.randrange(0, 256))
79
        # chars to test - all chars
80
        test = "".join(char for char in map(chr, range(256)))
81
        fobj = plumd.util.Filter(kchars)
82
        result = fobj.process(test)
83
        # any non-digits found?
84
        check = "".join(char for char in result if char not in kchars)
85
        self.assertEquals(check, "")
86
87
88
if __name__ == '__main__':
89
    unittest.main()
90