Skip to content

Commit 1a5bd6b

Browse files
committed
Clarify py2/py3 support in tests using six
1 parent b1189c7 commit 1a5bd6b

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
test_suite='tests',
1616
scripts = [],
1717
packages = ['verbalexpressions'],
18+
tests_require = ['six'],
1819
classifiers = [
1920
'License :: OSI Approved :: MIT License',
2021
'Programming Language :: Python',

tests/verbal_expressions_test.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# -*- encoding: utf-8 -*-
22
import unittest
3-
from verbalexpressions import VerEx
43
import re
5-
import sys
4+
5+
import six
6+
7+
import verbalexpressions
8+
69

710
class VerExTest(unittest.TestCase):
811
'''
912
Tests for verbal_expressions.py
1013
'''
1114

1215
def setUp(self):
13-
self.v = VerEx()
14-
if sys.version_info[0] < 3:
15-
self.assertRegex = self.assertRegexpMatches
16-
self.assertNotRegex = self.assertNotRegexpMatches
16+
self.v = verbalexpressions.VerEx()
1717

1818
def tearDown(self):
1919
self.v = None
@@ -28,117 +28,117 @@ def test_should_render_verex_list_as_string(self):
2828
def test_should_match_characters_in_range(self):
2929
self.exp = self.v.start_of_line().range('a', 'c').regex()
3030
for character in ['a', 'b', 'c']:
31-
self.assertRegex(character, self.exp)
31+
six.assertRegex(self, character, self.exp)
3232

3333
def test_should_not_match_characters_outside_of_range(self):
3434
self.exp = self.v.start_of_line().range('a', 'c').regex()
35-
self.assertNotRegex('d', self.exp)
35+
self.assertNotRegexpMatches('d', self.exp)
3636

3737
def test_should_match_characters_in_extended_range(self):
3838
self.exp = self.v.start_of_line().range('a', 'b', 'X', 'Z').regex()
3939
for character in ['a', 'b']:
40-
self.assertRegex(character, self.exp)
40+
six.assertRegex(self, character, self.exp)
4141
for character in ['X', 'Y', 'Z']:
42-
self.assertRegex(character, self.exp)
42+
six.assertRegex(self, character, self.exp)
4343

4444
def test_should_not_match_characters_outside_of_extended_range(self):
4545
self.exp = self.v.start_of_line().range('a', 'b', 'X', 'Z').regex()
46-
self.assertNotRegex('c', self.exp)
47-
self.assertNotRegex('W', self.exp)
46+
self.assertNotRegexpMatches('c', self.exp)
47+
self.assertNotRegexpMatches('W', self.exp)
4848

4949

5050
def test_should_match_start_of_line(self):
5151
self.exp = self.v.start_of_line().regex()
52-
self.assertRegex('text ', self.exp, 'Not started :(')
52+
six.assertRegex(self, 'text ', self.exp, 'Not started :(')
5353

5454
def test_should_match_end_of_line(self):
5555
self.exp = self.v.start_of_line().end_of_line().regex()
56-
self.assertRegex('', self.exp, 'It\'s not the end!')
56+
six.assertRegex(self, '', self.exp, 'It\'s not the end!')
5757

5858
def test_should_match_anything(self):
5959
self.exp = self.v.start_of_line().anything().end_of_line().regex()
60-
self.assertRegex('!@#$%¨&*()__+{}', self.exp, 'Not so anything...')
60+
six.assertRegex(self, '!@#$%¨&*()__+{}', self.exp, 'Not so anything...')
6161

6262
def test_should_match_anything_but_specified_element_when_element_is_not_found(self):
6363
self.exp = self.v.start_of_line().anything_but('X').end_of_line().regex()
64-
self.assertRegex('Y Files', self.exp, 'Found the X!')
64+
six.assertRegex(self, 'Y Files', self.exp, 'Found the X!')
6565

6666
def test_should_not_match_anything_but_specified_element_when_specified_element_is_found(self):
6767
self.exp = self.v.start_of_line().anything_but('X').end_of_line().regex()
68-
self.assertNotRegex('VerEX', self.exp, 'Didn\'t found the X :(')
68+
self.assertNotRegexpMatches('VerEX', self.exp, 'Didn\'t found the X :(')
6969

7070
def test_should_find_element(self):
7171
self.exp = self.v.start_of_line().find('Wally').end_of_line().regex()
72-
self.assertRegex('Wally', self.exp, '404! Wally not Found!')
72+
six.assertRegex(self, 'Wally', self.exp, '404! Wally not Found!')
7373

7474
def test_should_not_find_missing_element(self):
7575
self.exp = self.v.start_of_line().find('Wally').end_of_line().regex()
76-
self.assertNotRegex('Wall-e', self.exp, 'DAFUQ is Wall-e?')
76+
self.assertNotRegexpMatches('Wall-e', self.exp, 'DAFUQ is Wall-e?')
7777

7878
def test_should_match_when_maybe_element_is_present(self):
7979
self.exp = self.v.start_of_line().find('Python2.').maybe('7').end_of_line().regex()
80-
self.assertRegex('Python2.7', self.exp, 'Version doesn\'t match!')
80+
six.assertRegex(self, 'Python2.7', self.exp, 'Version doesn\'t match!')
8181

8282
def test_should_match_when_maybe_element_is_missing(self):
8383
self.exp = self.v.start_of_line().find('Python2.').maybe('7').end_of_line().regex()
84-
self.assertRegex('Python2.', self.exp, 'Version doesn\'t match!')
84+
six.assertRegex(self, 'Python2.', self.exp, 'Version doesn\'t match!')
8585

8686
def test_should_match_on_any_when_element_is_found(self):
8787
self.exp = self.v.start_of_line().any('Q').anything().end_of_line().regex()
88-
self.assertRegex('Query', self.exp, 'No match found!')
88+
six.assertRegex(self, 'Query', self.exp, 'No match found!')
8989

9090
def test_should_not_match_on_any_when_element_is_not_found(self):
9191
self.exp = self.v.start_of_line().any('Q').anything().end_of_line().regex()
92-
self.assertNotRegex('W', self.exp, 'I\'ve found it!')
92+
self.assertNotRegexpMatches('W', self.exp, 'I\'ve found it!')
9393

9494
def test_should_match_when_line_break_present(self):
9595
self.exp = self.v.start_of_line().anything().line_break().anything().end_of_line().regex()
96-
self.assertRegex('Marco \n Polo', self.exp, 'Give me a break!!')
96+
six.assertRegex(self, 'Marco \n Polo', self.exp, 'Give me a break!!')
9797

9898
def test_should_match_when_line_break_and_carriage_return_present(self):
9999
self.exp = self.v.start_of_line().anything().line_break().anything().end_of_line().regex()
100-
self.assertRegex('Marco \r\n Polo', self.exp, 'Give me a break!!')
100+
six.assertRegex(self, 'Marco \r\n Polo', self.exp, 'Give me a break!!')
101101

102102
def test_should_not_match_when_line_break_is_missing(self):
103103
self.exp = self.v.start_of_line().anything().line_break().anything().end_of_line().regex()
104-
self.assertNotRegex('Marco Polo', self.exp, 'There\'s a break here!')
104+
self.assertNotRegexpMatches('Marco Polo', self.exp, 'There\'s a break here!')
105105

106106
def test_should_match_when_tab_present(self):
107107
self.exp = self.v.start_of_line().anything().tab().end_of_line().regex()
108-
self.assertRegex('One tab only ', self.exp, 'No tab here!')
108+
six.assertRegex(self, 'One tab only ', self.exp, 'No tab here!')
109109

110110
def test_should_not_match_when_tab_is_missing(self):
111111
self.exp = self.v.start_of_line().anything().tab().end_of_line().regex()
112112
self.assertFalse(re.match(self.exp, 'No tab here'), 'There\'s a tab here!')
113113

114114
def test_should_match_when_word_present(self):
115115
self.exp = self.v.start_of_line().anything().word().end_of_line().regex()
116-
self.assertRegex('Oneword', self.exp, 'Not just a word!')
116+
six.assertRegex(self, 'Oneword', self.exp, 'Not just a word!')
117117

118118
def test_not_match_when_two_words_are_present_instead_of_one(self):
119119
self.exp = self.v.start_of_line().anything().tab().end_of_line().regex()
120120
self.assertFalse(re.match(self.exp, 'Two words'), 'I\'ve found two of them')
121121

122122
def test_should_match_when_or_condition_fulfilled(self):
123123
self.exp = self.v.start_of_line().anything().find('G').OR().find('h').end_of_line().regex()
124-
self.assertRegex('Github', self.exp, 'Octocat not found')
124+
six.assertRegex(self, 'Github', self.exp, 'Octocat not found')
125125

126126
def test_should_not_match_when_or_condition_not_fulfilled(self):
127127
self.exp = self.v.start_of_line().anything().find('G').OR().find('h').end_of_line().regex()
128128
self.assertFalse(re.match(self.exp, 'Bitbucket'), 'Bucket not found')
129129

130130
def test_should_match_on_upper_case_when_lower_case_is_given_and_any_case_is_true(self):
131131
self.exp = self.v.start_of_line().find('THOR').end_of_line().with_any_case(True).regex()
132-
self.assertRegex('thor', self.exp, 'Upper case Thor, please!')
132+
six.assertRegex(self, 'thor', self.exp, 'Upper case Thor, please!')
133133

134134
def test_should_match_multiple_lines(self):
135135
self.exp = self.v.start_of_line().anything().find('Pong').anything().end_of_line().search_one_line(True).regex()
136-
self.assertRegex('Ping \n Pong \n Ping', self.exp, 'Pong didn\'t answer')
136+
six.assertRegex(self, 'Ping \n Pong \n Ping', self.exp, 'Pong didn\'t answer')
137137

138138
def test_should_match_email_address(self):
139139
self.exp = self.v.start_of_line().word().then('@').word().then('.').word().end_of_line().regex()
140-
self.assertRegex('[email protected]', self.exp, 'Not a valid email')
140+
six.assertRegex(self, '[email protected]', self.exp, 'Not a valid email')
141141

142142
def test_should_match_url(self):
143143
self.exp = self.v.start_of_line().then('http').maybe('s').then('://').maybe('www.').word().then('.').word().maybe('/').end_of_line().regex()
144-
self.assertRegex('https://www.google.com/', self.exp, 'Not a valid email')
144+
six.assertRegex(self, 'https://www.google.com/', self.exp, 'Not a valid email')

0 commit comments

Comments
 (0)