-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
83 lines (69 loc) · 2.58 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- coding: utf-8 -*-
"""
(cre) module post-installation tests.
"""
import unittest
import cre
def simple_search(pattern, string):
"""
Perform pattern search without compiling pattern.
"""
return True if cre.search(pattern, string) else False
def compiled_pattern_search(pattern, string):
"""
Perform compiled pattern search.
"""
cp = cre.compile(pattern)
return True if cp.search(string) else None
class CRETests(unittest.TestCase):
"""
(cre) module basic tests.
"""
pat_s = 'Кракозя.*'
pat_s1 = '^акозя.*'
pat_b = b'^.*unintelligible.*$'
pat_u = u'.*characters'
str_s = 'Кракозябры means unintelligible sequence of characters'
str_b = b'krakozyabry means unintelligible sequence of characters'
str_u = u'Кракозябры means unintelligible sequence of characters'
def test_simple_search(self):
"""
Test pattern search without compiling pattern.
"""
self.assertTrue(simple_search(self.pat_s, self.str_s),
'{0} should match with {1}'
.format(self.pat_s, self.str_s))
self.assertFalse(simple_search(self.pat_s1, self.str_s),
'{0} should not match with {1}'
.format(self.pat_s1, self.str_s))
def test_compiled_pattern_search(self):
"""
Test pattern search with compiled pattern.
"""
self.assertTrue(compiled_pattern_search(self.pat_s, self.str_s),
'{0} should match with {1}'
.format(self.pat_s, self.str_s))
self.assertFalse(compiled_pattern_search(self.pat_s1, self.str_s),
'{0} should not match with {1}'
.format(self.pat_s1, self.str_s))
def test_string_params(self):
"""
Test strings as parameters.
"""
self.assertTrue(simple_search(self.pat_s, self.str_s),
'{0} should match with {1}'
.format(self.pat_s, self.str_s))
def test_byte_params(self):
"""
Test bytes as parameters.
"""
self.assertTrue(simple_search(self.pat_b, self.str_b),
'{0} should match with {1}'
.format(self.pat_b, self.str_b))
def test_unicode_params(self):
"""
Test unicodes as parameters.
"""
self.assertTrue(simple_search(self.pat_u, self.str_u),
u'{0} should match with {1}'
.format(self.pat_u, self.str_u))