1- # -*- encoding: utf-8 -*-
21import unittest
32import re
43
87
98
109class VerExTest (unittest .TestCase ):
11- '''
12- Tests for verbal_expressions.py
13- '''
10+ """ Tests for verbal_expressions.py """
1411
1512 if six .PY3 :
1613 assertNotRegexpMatches = unittest .TestCase .assertNotRegex
@@ -23,125 +20,242 @@ def tearDown(self):
2320 self .exp = None
2421
2522 def test_should_render_verex_as_string (self ):
26- self .assertEqual (str (self .v .add ('^$' )), '^$' )
23+ self .assertEqual (str (self .v .add ("^$" )), "^$" )
2724
2825 def test_should_render_verex_list_as_string (self ):
29- self .assertEqual (str (self .v .add (['^' , ' [0-9]' , '$' ])), ' ^[0-9]$' )
26+ self .assertEqual (str (self .v .add (["^" , " [0-9]" , "$" ])), " ^[0-9]$" )
3027
3128 def test_should_match_characters_in_range (self ):
32- self .exp = self .v .start_of_line ().range ('a' , 'c' ).regex ()
33- for character in ['a' , 'b' , 'c' ]:
29+ self .exp = self .v .start_of_line ().range ("a" , "c" ).regex ()
30+ for character in ["a" , "b" , "c" ]:
3431 six .assertRegex (self , character , self .exp )
3532
3633 def test_should_not_match_characters_outside_of_range (self ):
37- self .exp = self .v .start_of_line ().range ('a' , 'c' ).regex ()
38- self .assertNotRegexpMatches ('d' , self .exp )
34+ self .exp = self .v .start_of_line ().range ("a" , "c" ).regex ()
35+ self .assertNotRegexpMatches ("d" , self .exp )
3936
4037 def test_should_match_characters_in_extended_range (self ):
41- self .exp = self .v .start_of_line ().range ('a' , 'b' , 'X' , 'Z' ).regex ()
42- for character in ['a' , 'b' ]:
38+ self .exp = self .v .start_of_line ().range ("a" , "b" , "X" , "Z" ).regex ()
39+ for character in ["a" , "b" ]:
4340 six .assertRegex (self , character , self .exp )
44- for character in ['X' , 'Y' , 'Z' ]:
41+ for character in ["X" , "Y" , "Z" ]:
4542 six .assertRegex (self , character , self .exp )
4643
4744 def test_should_not_match_characters_outside_of_extended_range (self ):
48- self .exp = self .v .start_of_line ().range ('a' , 'b' , 'X' , 'Z' ).regex ()
49- self .assertNotRegexpMatches ('c' , self .exp )
50- self .assertNotRegexpMatches ('W' , self .exp )
51-
45+ self .exp = self .v .start_of_line ().range ("a" , "b" , "X" , "Z" ).regex ()
46+ self .assertNotRegexpMatches ("c" , self .exp )
47+ self .assertNotRegexpMatches ("W" , self .exp )
5248
5349 def test_should_match_start_of_line (self ):
5450 self .exp = self .v .start_of_line ().regex ()
55- six .assertRegex (self , ' text ' , self .exp , ' Not started :(' )
51+ six .assertRegex (self , " text " , self .exp , " Not started :(" )
5652
5753 def test_should_match_end_of_line (self ):
5854 self .exp = self .v .start_of_line ().end_of_line ().regex ()
59- six .assertRegex (self , '' , self .exp , 'It \ ' s not the end!' )
55+ six .assertRegex (self , "" , self .exp , "It 's not the end!" )
6056
6157 def test_should_match_anything (self ):
6258 self .exp = self .v .start_of_line ().anything ().end_of_line ().regex ()
63- six .assertRegex (self , '!@#$%¨&*()__+{}' , self .exp , 'Not so anything...' )
64-
65- def test_should_match_anything_but_specified_element_when_element_is_not_found (self ):
66- self .exp = self .v .start_of_line ().anything_but ('X' ).end_of_line ().regex ()
67- six .assertRegex (self , 'Y Files' , self .exp , 'Found the X!' )
68-
69- def test_should_not_match_anything_but_specified_element_when_specified_element_is_found (self ):
70- self .exp = self .v .start_of_line ().anything_but ('X' ).end_of_line ().regex ()
71- self .assertNotRegexpMatches ('VerEX' , self .exp , 'Didn\' t found the X :(' )
59+ six .assertRegex (
60+ self , "!@#$%¨&*()__+{}" , self .exp , "Not so anything..."
61+ )
62+
63+ def test_should_match_anything_but_specified_element_when_element_is_not_found (
64+ self
65+ ):
66+ self .exp = (
67+ self .v .start_of_line ().anything_but ("X" ).end_of_line ().regex ()
68+ )
69+ six .assertRegex (self , "Y Files" , self .exp , "Found the X!" )
70+
71+ def test_should_not_match_anything_but_specified_element_when_specified_element_is_found (
72+ self
73+ ):
74+ self .exp = (
75+ self .v .start_of_line ().anything_but ("X" ).end_of_line ().regex ()
76+ )
77+ self .assertNotRegexpMatches ("VerEX" , self .exp , "Didn't found the X :(" )
7278
7379 def test_should_find_element (self ):
74- self .exp = self .v .start_of_line ().find (' Wally' ).end_of_line ().regex ()
75- six .assertRegex (self , ' Wally' , self .exp , ' 404! Wally not Found!' )
80+ self .exp = self .v .start_of_line ().find (" Wally" ).end_of_line ().regex ()
81+ six .assertRegex (self , " Wally" , self .exp , " 404! Wally not Found!" )
7682
7783 def test_should_not_find_missing_element (self ):
78- self .exp = self .v .start_of_line ().find (' Wally' ).end_of_line ().regex ()
79- self .assertNotRegexpMatches (' Wall-e' , self .exp , ' DAFUQ is Wall-e?' )
84+ self .exp = self .v .start_of_line ().find (" Wally" ).end_of_line ().regex ()
85+ self .assertNotRegexpMatches (" Wall-e" , self .exp , " DAFUQ is Wall-e?" )
8086
8187 def test_should_match_when_maybe_element_is_present (self ):
82- self .exp = self .v .start_of_line ().find ('Python2.' ).maybe ('7' ).end_of_line ().regex ()
83- six .assertRegex (self , 'Python2.7' , self .exp , 'Version doesn\' t match!' )
88+ self .exp = (
89+ self .v .start_of_line ()
90+ .find ("Python2." )
91+ .maybe ("7" )
92+ .end_of_line ()
93+ .regex ()
94+ )
95+ six .assertRegex (self , "Python2.7" , self .exp , "Version doesn't match!" )
8496
8597 def test_should_match_when_maybe_element_is_missing (self ):
86- self .exp = self .v .start_of_line ().find ('Python2.' ).maybe ('7' ).end_of_line ().regex ()
87- six .assertRegex (self , 'Python2.' , self .exp , 'Version doesn\' t match!' )
98+ self .exp = (
99+ self .v .start_of_line ()
100+ .find ("Python2." )
101+ .maybe ("7" )
102+ .end_of_line ()
103+ .regex ()
104+ )
105+ six .assertRegex (self , "Python2." , self .exp , "Version doesn't match!" )
88106
89107 def test_should_match_on_any_when_element_is_found (self ):
90- self .exp = self .v .start_of_line ().any ('Q' ).anything ().end_of_line ().regex ()
91- six .assertRegex (self , 'Query' , self .exp , 'No match found!' )
108+ self .exp = (
109+ self .v .start_of_line ().any ("Q" ).anything ().end_of_line ().regex ()
110+ )
111+ six .assertRegex (self , "Query" , self .exp , "No match found!" )
92112
93113 def test_should_not_match_on_any_when_element_is_not_found (self ):
94- self .exp = self .v .start_of_line ().any ('Q' ).anything ().end_of_line ().regex ()
95- self .assertNotRegexpMatches ('W' , self .exp , 'I\' ve found it!' )
114+ self .exp = (
115+ self .v .start_of_line ().any ("Q" ).anything ().end_of_line ().regex ()
116+ )
117+ self .assertNotRegexpMatches ("W" , self .exp , "I've found it!" )
96118
97119 def test_should_match_when_line_break_present (self ):
98- self .exp = self .v .start_of_line ().anything ().line_break ().anything ().end_of_line ().regex ()
99- six .assertRegex (self , 'Marco \n Polo' , self .exp , 'Give me a break!!' )
120+ self .exp = (
121+ self .v .start_of_line ()
122+ .anything ()
123+ .line_break ()
124+ .anything ()
125+ .end_of_line ()
126+ .regex ()
127+ )
128+ six .assertRegex (self , "Marco \n Polo" , self .exp , "Give me a break!!" )
100129
101130 def test_should_match_when_line_break_and_carriage_return_present (self ):
102- self .exp = self .v .start_of_line ().anything ().line_break ().anything ().end_of_line ().regex ()
103- six .assertRegex (self , 'Marco \r \n Polo' , self .exp , 'Give me a break!!' )
131+ self .exp = (
132+ self .v .start_of_line ()
133+ .anything ()
134+ .line_break ()
135+ .anything ()
136+ .end_of_line ()
137+ .regex ()
138+ )
139+ six .assertRegex (self , "Marco \r \n Polo" , self .exp , "Give me a break!!" )
104140
105141 def test_should_not_match_when_line_break_is_missing (self ):
106- self .exp = self .v .start_of_line ().anything ().line_break ().anything ().end_of_line ().regex ()
107- self .assertNotRegexpMatches ('Marco Polo' , self .exp , 'There\' s a break here!' )
142+ self .exp = (
143+ self .v .start_of_line ()
144+ .anything ()
145+ .line_break ()
146+ .anything ()
147+ .end_of_line ()
148+ .regex ()
149+ )
150+ self .assertNotRegexpMatches (
151+ "Marco Polo" , self .exp , "There's a break here!"
152+ )
108153
109154 def test_should_match_when_tab_present (self ):
110- self .exp = self .v .start_of_line ().anything ().tab ().end_of_line ().regex ()
111- six .assertRegex (self , 'One tab only ' , self .exp , 'No tab here!' )
155+ self .exp = (
156+ self .v .start_of_line ().anything ().tab ().end_of_line ().regex ()
157+ )
158+ six .assertRegex (self , "One tab only " , self .exp , "No tab here!" )
112159
113160 def test_should_not_match_when_tab_is_missing (self ):
114- self .exp = self .v .start_of_line ().anything ().tab ().end_of_line ().regex ()
115- self .assertFalse (re .match (self .exp , 'No tab here' ), 'There\' s a tab here!' )
161+ self .exp = (
162+ self .v .start_of_line ().anything ().tab ().end_of_line ().regex ()
163+ )
164+ self .assertFalse (
165+ re .match (self .exp , "No tab here" ), "There's a tab here!"
166+ )
116167
117168 def test_should_match_when_word_present (self ):
118- self .exp = self .v .start_of_line ().anything ().word ().end_of_line ().regex ()
119- six .assertRegex (self , 'Oneword' , self .exp , 'Not just a word!' )
169+ self .exp = (
170+ self .v .start_of_line ().anything ().word ().end_of_line ().regex ()
171+ )
172+ six .assertRegex (self , "Oneword" , self .exp , "Not just a word!" )
120173
121174 def test_not_match_when_two_words_are_present_instead_of_one (self ):
122- self .exp = self .v .start_of_line ().anything ().tab ().end_of_line ().regex ()
123- self .assertFalse (re .match (self .exp , 'Two words' ), 'I\' ve found two of them' )
175+ self .exp = (
176+ self .v .start_of_line ().anything ().tab ().end_of_line ().regex ()
177+ )
178+ self .assertFalse (
179+ re .match (self .exp , "Two words" ), "I've found two of them"
180+ )
124181
125182 def test_should_match_when_or_condition_fulfilled (self ):
126- self .exp = self .v .start_of_line ().anything ().find ('G' ).OR ().find ('h' ).end_of_line ().regex ()
127- six .assertRegex (self , 'Github' , self .exp , 'Octocat not found' )
183+ self .exp = (
184+ self .v .start_of_line ()
185+ .anything ()
186+ .find ("G" )
187+ .OR ()
188+ .find ("h" )
189+ .end_of_line ()
190+ .regex ()
191+ )
192+ six .assertRegex (self , "Github" , self .exp , "Octocat not found" )
128193
129194 def test_should_not_match_when_or_condition_not_fulfilled (self ):
130- self .exp = self .v .start_of_line ().anything ().find ('G' ).OR ().find ('h' ).end_of_line ().regex ()
131- self .assertFalse (re .match (self .exp , 'Bitbucket' ), 'Bucket not found' )
132-
133- def test_should_match_on_upper_case_when_lower_case_is_given_and_any_case_is_true (self ):
134- self .exp = self .v .start_of_line ().find ('THOR' ).end_of_line ().with_any_case (True ).regex ()
135- six .assertRegex (self , 'thor' , self .exp , 'Upper case Thor, please!' )
195+ self .exp = (
196+ self .v .start_of_line ()
197+ .anything ()
198+ .find ("G" )
199+ .OR ()
200+ .find ("h" )
201+ .end_of_line ()
202+ .regex ()
203+ )
204+ self .assertFalse (re .match (self .exp , "Bitbucket" ), "Bucket not found" )
205+
206+ def test_should_match_on_upper_case_when_lower_case_is_given_and_any_case_is_true (
207+ self
208+ ):
209+ self .exp = (
210+ self .v .start_of_line ()
211+ .find ("THOR" )
212+ .end_of_line ()
213+ .with_any_case (True )
214+ .regex ()
215+ )
216+ six .assertRegex (self , "thor" , self .exp , "Upper case Thor, please!" )
136217
137218 def test_should_match_multiple_lines (self ):
138- self .exp = self .v .start_of_line ().anything ().find ('Pong' ).anything ().end_of_line ().search_one_line (True ).regex ()
139- six .assertRegex (self , 'Ping \n Pong \n Ping' , self .exp , 'Pong didn\' t answer' )
219+ self .exp = (
220+ self .v .start_of_line ()
221+ .anything ()
222+ .find ("Pong" )
223+ .anything ()
224+ .end_of_line ()
225+ .search_one_line (True )
226+ .regex ()
227+ )
228+ six .assertRegex (
229+ self , "Ping \n Pong \n Ping" , self .exp , "Pong didn't answer"
230+ )
140231
141232 def test_should_match_email_address (self ):
142- self .exp = self .v .start_of_line ().word ().then ('@' ).word ().then ('.' ).word ().end_of_line ().regex ()
143- six .assertRegex (self , 'mail@mail.com' , self .exp , 'Not a valid email' )
233+ self .exp = (
234+ self .v .start_of_line ()
235+ .word ()
236+ .then ("@" )
237+ .word ()
238+ .then ("." )
239+ .word ()
240+ .end_of_line ()
241+ .regex ()
242+ )
243+ six .assertRegex (self , "mail@mail.com" , self .exp , "Not a valid email" )
144244
145245 def test_should_match_url (self ):
146- self .exp = self .v .start_of_line ().then ('http' ).maybe ('s' ).then ('://' ).maybe ('www.' ).word ().then ('.' ).word ().maybe ('/' ).end_of_line ().regex ()
147- six .assertRegex (self , 'https://www.google.com/' , self .exp , 'Not a valid email' )
246+ self .exp = (
247+ self .v .start_of_line ()
248+ .then ("http" )
249+ .maybe ("s" )
250+ .then ("://" )
251+ .maybe ("www." )
252+ .word ()
253+ .then ("." )
254+ .word ()
255+ .maybe ("/" )
256+ .end_of_line ()
257+ .regex ()
258+ )
259+ six .assertRegex (
260+ self , "https://www.google.com/" , self .exp , "Not a valid email"
261+ )
0 commit comments