Skip to content

Commit

Permalink
replace deprecated unittest assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
sameerraghuram committed Feb 9, 2017
1 parent 98646f8 commit da93ab6
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions tests/verbal_expressions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,125 +16,125 @@ def tearDown(self):
self.exp = None

def test_should_render_verex_as_string(self):
self.assertEquals(str(self.v.add('^$')), '^$')
self.assertEqual(str(self.v.add('^$')), '^$')

def test_should_render_verex_list_as_string(self):
self.assertEquals(str(self.v.add(['^', '[0-9]', '$'])), '^[0-9]$')
self.assertEqual(str(self.v.add(['^', '[0-9]', '$'])), '^[0-9]$')

def test_should_match_characters_in_range(self):
self.exp = self.v.start_of_line().range('a', 'c').regex()
for character in ['a', 'b', 'c']:
self.assertRegexpMatches(character, self.exp)
self.assertRegex(character, self.exp)

def test_should_not_match_characters_outside_of_range(self):
self.exp = self.v.start_of_line().range('a', 'c').regex()
self.assertNotRegexpMatches('d', self.exp)
self.assertNotRegex('d', self.exp)

def test_should_match_characters_in_extended_range(self):
self.exp = self.v.start_of_line().range('a', 'b', 'X', 'Z').regex()
for character in ['a', 'b']:
self.assertRegexpMatches(character, self.exp)
self.assertRegex(character, self.exp)
for character in ['X', 'Y', 'Z']:
self.assertRegexpMatches(character, self.exp)
self.assertRegex(character, self.exp)

def test_should_not_match_characters_outside_of_extended_range(self):
self.exp = self.v.start_of_line().range('a', 'b', 'X', 'Z').regex()
self.assertNotRegexpMatches('c', self.exp)
self.assertNotRegexpMatches('W', self.exp)
self.assertNotRegex('c', self.exp)
self.assertNotRegex('W', self.exp)


def test_should_match_start_of_line(self):
self.exp = self.v.start_of_line().regex()
self.assertRegexpMatches('text ', self.exp, 'Not started :(')
self.assertRegex('text ', self.exp, 'Not started :(')

def test_should_match_end_of_line(self):
self.exp = self.v.start_of_line().end_of_line().regex()
self.assertRegexpMatches('', self.exp, 'It\'s not the end!')
self.assertRegex('', self.exp, 'It\'s not the end!')

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

def test_should_match_anything_but_specified_element_when_element_is_not_found(self):
self.exp = self.v.start_of_line().anything_but('X').end_of_line().regex()
self.assertRegexpMatches('Y Files', self.exp, 'Found the X!')
self.assertRegex('Y Files', self.exp, 'Found the X!')

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

def test_should_find_element(self):
self.exp = self.v.start_of_line().find('Wally').end_of_line().regex()
self.assertRegexpMatches('Wally', self.exp, '404! Wally not Found!')
self.assertRegex('Wally', self.exp, '404! Wally not Found!')

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

def test_should_match_when_maybe_element_is_present(self):
self.exp = self.v.start_of_line().find('Python2.').maybe('7').end_of_line().regex()
self.assertRegexpMatches('Python2.7', self.exp, 'Version doesn\'t match!')
self.assertRegex('Python2.7', self.exp, 'Version doesn\'t match!')

def test_should_match_when_maybe_element_is_missing(self):
self.exp = self.v.start_of_line().find('Python2.').maybe('7').end_of_line().regex()
self.assertRegexpMatches('Python2.', self.exp, 'Version doesn\'t match!')
self.assertRegex('Python2.', self.exp, 'Version doesn\'t match!')

def test_should_match_on_any_when_element_is_found(self):
self.exp = self.v.start_of_line().any('Q').anything().end_of_line().regex()
self.assertRegexpMatches('Query', self.exp, 'No match found!')
self.assertRegex('Query', self.exp, 'No match found!')

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

def test_should_match_when_line_break_present(self):
self.exp = self.v.start_of_line().anything().line_break().anything().end_of_line().regex()
self.assertRegexpMatches('Marco \n Polo', self.exp, 'Give me a break!!')
self.assertRegex('Marco \n Polo', self.exp, 'Give me a break!!')

def test_should_match_when_line_break_and_carriage_return_present(self):
self.exp = self.v.start_of_line().anything().line_break().anything().end_of_line().regex()
self.assertRegexpMatches('Marco \r\n Polo', self.exp, 'Give me a break!!')
self.assertRegex('Marco \r\n Polo', self.exp, 'Give me a break!!')

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

def test_should_match_when_tab_present(self):
self.exp = self.v.start_of_line().anything().tab().end_of_line().regex()
self.assertRegexpMatches('One tab only ', self.exp, 'No tab here!')
self.assertRegex('One tab only ', self.exp, 'No tab here!')

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

def test_should_match_when_word_present(self):
self.exp = self.v.start_of_line().anything().word().end_of_line().regex()
self.assertRegexpMatches('Oneword', self.exp, 'Not just a word!')
self.assertRegex('Oneword', self.exp, 'Not just a word!')

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

def test_should_match_when_or_condition_fulfilled(self):
self.exp = self.v.start_of_line().anything().find('G').OR().find('h').end_of_line().regex()
self.assertRegexpMatches('Github', self.exp, 'Octocat not found')
self.assertRegex('Github', self.exp, 'Octocat not found')

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

def test_should_match_on_upper_case_when_lower_case_is_given_and_any_case_is_true(self):
self.exp = self.v.start_of_line().find('THOR').end_of_line().with_any_case(True).regex()
self.assertRegexpMatches('thor', self.exp, 'Upper case Thor, please!')
self.assertRegex('thor', self.exp, 'Upper case Thor, please!')

def test_should_match_multiple_lines(self):
self.exp = self.v.start_of_line().anything().find('Pong').anything().end_of_line().search_one_line(True).regex()
self.assertRegexpMatches('Ping \n Pong \n Ping', self.exp, 'Pong didn\'t answer')
self.assertRegex('Ping \n Pong \n Ping', self.exp, 'Pong didn\'t answer')

def test_should_match_email_address(self):
self.exp = self.v.start_of_line().word().then('@').word().then('.').word().end_of_line().regex()
self.assertRegexpMatches('[email protected]', self.exp, 'Not a valid email')
self.assertRegex('[email protected]', self.exp, 'Not a valid email')

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

0 comments on commit da93ab6

Please sign in to comment.