[Python-checkins] cpython (2.7): Use more appropriate asserts in re tests.

serhiy.storchaka python-checkins at python.org
Sun Sep 14 15:44:06 CEST 2014


http://hg.python.org/cpython/rev/fe8ba0ade9a3
changeset:   92419:fe8ba0ade9a3
branch:      2.7
parent:      92412:301c672ceca6
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Sep 14 16:19:37 2014 +0300
summary:
  Use more appropriate asserts in re tests.

files:
  Lib/test/test_re.py |  118 ++++++++++++++++----------------
  1 files changed, 59 insertions(+), 59 deletions(-)


diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -31,12 +31,12 @@
         self.assertEqual(re.search('x*', 'axx').span(), (0, 0))
         self.assertEqual(re.search('x+', 'axx').span(0), (1, 3))
         self.assertEqual(re.search('x+', 'axx').span(), (1, 3))
-        self.assertEqual(re.search('x', 'aaa'), None)
+        self.assertIsNone(re.search('x', 'aaa'))
         self.assertEqual(re.match('a*', 'xxx').span(0), (0, 0))
         self.assertEqual(re.match('a*', 'xxx').span(), (0, 0))
         self.assertEqual(re.match('x*', 'xxxa').span(0), (0, 3))
         self.assertEqual(re.match('x*', 'xxxa').span(), (0, 3))
-        self.assertEqual(re.match('a+', 'xxx'), None)
+        self.assertIsNone(re.match('a+', 'xxx'))
 
     def bump_num(self, matchobj):
         int_value = int(matchobj.group(0))
@@ -284,8 +284,8 @@
                          ('(', 'a'))
         self.assertEqual(re.match('^(\()?([^()]+)(?(1)\))$', 'a').groups(),
                          (None, 'a'))
-        self.assertEqual(re.match('^(\()?([^()]+)(?(1)\))$', 'a)'), None)
-        self.assertEqual(re.match('^(\()?([^()]+)(?(1)\))$', '(a'), None)
+        self.assertIsNone(re.match('^(\()?([^()]+)(?(1)\))$', 'a)'))
+        self.assertIsNone(re.match('^(\()?([^()]+)(?(1)\))$', '(a'))
         self.assertEqual(re.match('^(?:(a)|c)((?(1)b|d))$', 'ab').groups(),
                          ('a', 'b'))
         self.assertEqual(re.match('^(?:(a)|c)((?(1)b|d))$', 'cd').groups(),
@@ -301,8 +301,8 @@
                          ('a', 'b', 'c'))
         self.assertEqual(p.match('ad').groups(),
                          ('a', None, 'd'))
-        self.assertEqual(p.match('abd'), None)
-        self.assertEqual(p.match('ac'), None)
+        self.assertIsNone(p.match('abd'))
+        self.assertIsNone(p.match('ac'))
 
 
     def test_re_groupref(self):
@@ -310,8 +310,8 @@
                          ('|', 'a'))
         self.assertEqual(re.match(r'^(\|)?([^()]+)\1?$', 'a').groups(),
                          (None, 'a'))
-        self.assertEqual(re.match(r'^(\|)?([^()]+)\1$', 'a|'), None)
-        self.assertEqual(re.match(r'^(\|)?([^()]+)\1$', '|a'), None)
+        self.assertIsNone(re.match(r'^(\|)?([^()]+)\1$', 'a|'))
+        self.assertIsNone(re.match(r'^(\|)?([^()]+)\1$', '|a'))
         self.assertEqual(re.match(r'^(?:(a)|c)(\1)$', 'aa').groups(),
                          ('a', 'a'))
         self.assertEqual(re.match(r'^(?:(a)|c)(\1)?$', 'c').groups(),
@@ -329,10 +329,10 @@
                          "second first second first")
 
     def test_repeat_minmax(self):
-        self.assertEqual(re.match("^(\w){1}$", "abc"), None)
-        self.assertEqual(re.match("^(\w){1}?$", "abc"), None)
-        self.assertEqual(re.match("^(\w){1,2}$", "abc"), None)
-        self.assertEqual(re.match("^(\w){1,2}?$", "abc"), None)
+        self.assertIsNone(re.match("^(\w){1}$", "abc"))
+        self.assertIsNone(re.match("^(\w){1}?$", "abc"))
+        self.assertIsNone(re.match("^(\w){1,2}$", "abc"))
+        self.assertIsNone(re.match("^(\w){1,2}?$", "abc"))
 
         self.assertEqual(re.match("^(\w){3}$", "abc").group(1), "c")
         self.assertEqual(re.match("^(\w){1,3}$", "abc").group(1), "c")
@@ -343,29 +343,29 @@
         self.assertEqual(re.match("^(\w){1,4}?$", "abc").group(1), "c")
         self.assertEqual(re.match("^(\w){3,4}?$", "abc").group(1), "c")
 
-        self.assertEqual(re.match("^x{1}$", "xxx"), None)
-        self.assertEqual(re.match("^x{1}?$", "xxx"), None)
-        self.assertEqual(re.match("^x{1,2}$", "xxx"), None)
-        self.assertEqual(re.match("^x{1,2}?$", "xxx"), None)
+        self.assertIsNone(re.match("^x{1}$", "xxx"))
+        self.assertIsNone(re.match("^x{1}?$", "xxx"))
+        self.assertIsNone(re.match("^x{1,2}$", "xxx"))
+        self.assertIsNone(re.match("^x{1,2}?$", "xxx"))
 
-        self.assertNotEqual(re.match("^x{3}$", "xxx"), None)
-        self.assertNotEqual(re.match("^x{1,3}$", "xxx"), None)
-        self.assertNotEqual(re.match("^x{1,4}$", "xxx"), None)
-        self.assertNotEqual(re.match("^x{3,4}?$", "xxx"), None)
-        self.assertNotEqual(re.match("^x{3}?$", "xxx"), None)
-        self.assertNotEqual(re.match("^x{1,3}?$", "xxx"), None)
-        self.assertNotEqual(re.match("^x{1,4}?$", "xxx"), None)
-        self.assertNotEqual(re.match("^x{3,4}?$", "xxx"), None)
+        self.assertTrue(re.match("^x{3}$", "xxx"))
+        self.assertTrue(re.match("^x{1,3}$", "xxx"))
+        self.assertTrue(re.match("^x{1,4}$", "xxx"))
+        self.assertTrue(re.match("^x{3,4}?$", "xxx"))
+        self.assertTrue(re.match("^x{3}?$", "xxx"))
+        self.assertTrue(re.match("^x{1,3}?$", "xxx"))
+        self.assertTrue(re.match("^x{1,4}?$", "xxx"))
+        self.assertTrue(re.match("^x{3,4}?$", "xxx"))
 
-        self.assertEqual(re.match("^x{}$", "xxx"), None)
-        self.assertNotEqual(re.match("^x{}$", "x{}"), None)
+        self.assertIsNone(re.match("^x{}$", "xxx"))
+        self.assertTrue(re.match("^x{}$", "x{}"))
 
     def test_getattr(self):
         self.assertEqual(re.match("(a)", "a").pos, 0)
         self.assertEqual(re.match("(a)", "a").endpos, 1)
         self.assertEqual(re.match("(a)", "a").string, "a")
         self.assertEqual(re.match("(a)", "a").regs, ((0, 1), (0, 1)))
-        self.assertNotEqual(re.match("(a)", "a").re, None)
+        self.assertTrue(re.match("(a)", "a").re)
 
     def test_special_escapes(self):
         self.assertEqual(re.search(r"\b(b.)\b",
@@ -382,14 +382,14 @@
                                    "abc bcd bc abxd", re.UNICODE).group(1), "bx")
         self.assertEqual(re.search(r"^abc$", "\nabc\n", re.M).group(0), "abc")
         self.assertEqual(re.search(r"^\Aabc\Z$", "abc", re.M).group(0), "abc")
-        self.assertEqual(re.search(r"^\Aabc\Z$", "\nabc\n", re.M), None)
+        self.assertIsNone(re.search(r"^\Aabc\Z$", "\nabc\n", re.M))
         self.assertEqual(re.search(r"\b(b.)\b",
                                    u"abcd abc bcd bx").group(1), "bx")
         self.assertEqual(re.search(r"\B(b.)\B",
                                    u"abc bcd bc abxd").group(1), "bx")
         self.assertEqual(re.search(r"^abc$", u"\nabc\n", re.M).group(0), "abc")
         self.assertEqual(re.search(r"^\Aabc\Z$", u"abc", re.M).group(0), "abc")
-        self.assertEqual(re.search(r"^\Aabc\Z$", u"\nabc\n", re.M), None)
+        self.assertIsNone(re.search(r"^\Aabc\Z$", u"\nabc\n", re.M))
         self.assertEqual(re.search(r"\d\D\w\W\s\S",
                                    "1aa! a").group(0), "1aa! a")
         self.assertEqual(re.search(r"\d\D\w\W\s\S",
@@ -409,10 +409,10 @@
         self.assertFalse(re.match(r"\B", "abc"))
         # However, an empty string contains no word boundaries, and also no
         # non-boundaries.
-        self.assertEqual(re.search(r"\B", ""), None)
+        self.assertIsNone(re.search(r"\B", ""))
         # This one is questionable and different from the perlre behaviour,
         # but describes current behavior.
-        self.assertEqual(re.search(r"\b", ""), None)
+        self.assertIsNone(re.search(r"\b", ""))
         # A single word-character string has two boundaries, but no
         # non-boundary gaps.
         self.assertEqual(len(re.findall(r"\b", "a")), 2)
@@ -434,8 +434,8 @@
     def test_big_codesize(self):
         # Issue #1160
         r = re.compile('|'.join(('%d'%x for x in range(10000))))
-        self.assertIsNotNone(r.match('1000'))
-        self.assertIsNotNone(r.match('9999'))
+        self.assertTrue(r.match('1000'))
+        self.assertTrue(r.match('9999'))
 
     def test_anyall(self):
         self.assertEqual(re.match("a.b", "a\nb", re.DOTALL).group(0),
@@ -569,26 +569,26 @@
 
     def test_flags(self):
         for flag in [re.I, re.M, re.X, re.S, re.L]:
-            self.assertNotEqual(re.compile('^pattern$', flag), None)
+            self.assertTrue(re.compile('^pattern$', flag))
 
     def test_sre_character_literals(self):
         for i in [0, 8, 16, 32, 64, 127, 128, 255]:
-            self.assertNotEqual(re.match(r"\%03o" % i, chr(i)), None)
-            self.assertNotEqual(re.match(r"\%03o0" % i, chr(i)+"0"), None)
-            self.assertNotEqual(re.match(r"\%03o8" % i, chr(i)+"8"), None)
-            self.assertNotEqual(re.match(r"\x%02x" % i, chr(i)), None)
-            self.assertNotEqual(re.match(r"\x%02x0" % i, chr(i)+"0"), None)
-            self.assertNotEqual(re.match(r"\x%02xz" % i, chr(i)+"z"), None)
+            self.assertTrue(re.match(r"\%03o" % i, chr(i)))
+            self.assertTrue(re.match(r"\%03o0" % i, chr(i)+"0"))
+            self.assertTrue(re.match(r"\%03o8" % i, chr(i)+"8"))
+            self.assertTrue(re.match(r"\x%02x" % i, chr(i)))
+            self.assertTrue(re.match(r"\x%02x0" % i, chr(i)+"0"))
+            self.assertTrue(re.match(r"\x%02xz" % i, chr(i)+"z"))
         self.assertRaises(re.error, re.match, "\911", "")
 
     def test_sre_character_class_literals(self):
         for i in [0, 8, 16, 32, 64, 127, 128, 255]:
-            self.assertNotEqual(re.match(r"[\%03o]" % i, chr(i)), None)
-            self.assertNotEqual(re.match(r"[\%03o0]" % i, chr(i)), None)
-            self.assertNotEqual(re.match(r"[\%03o8]" % i, chr(i)), None)
-            self.assertNotEqual(re.match(r"[\x%02x]" % i, chr(i)), None)
-            self.assertNotEqual(re.match(r"[\x%02x0]" % i, chr(i)), None)
-            self.assertNotEqual(re.match(r"[\x%02xz]" % i, chr(i)), None)
+            self.assertTrue(re.match(r"[\%03o]" % i, chr(i)))
+            self.assertTrue(re.match(r"[\%03o0]" % i, chr(i)))
+            self.assertTrue(re.match(r"[\%03o8]" % i, chr(i)))
+            self.assertTrue(re.match(r"[\x%02x]" % i, chr(i)))
+            self.assertTrue(re.match(r"[\x%02x0]" % i, chr(i)))
+            self.assertTrue(re.match(r"[\x%02xz]" % i, chr(i)))
         self.assertRaises(re.error, re.match, "[\911]", "")
 
     def test_bug_113254(self):
@@ -598,7 +598,7 @@
 
     def test_bug_527371(self):
         # bug described in patches 527371/672491
-        self.assertEqual(re.match(r'(a)?a','a').lastindex, None)
+        self.assertIsNone(re.match(r'(a)?a','a').lastindex)
         self.assertEqual(re.match(r'(a)(b)?b','ab').lastindex, 1)
         self.assertEqual(re.match(r'(?P<a>a)(?P<b>b)?b','ab').lastgroup, 'a')
         self.assertEqual(re.match("(?P<a>a(b))", "ab").lastgroup, 'a')
@@ -655,7 +655,7 @@
             (r"\s+", None),
             ])
 
-        self.assertNotEqual(scanner.scanner.scanner("").pattern, None)
+        self.assertTrue(scanner.scanner.scanner("").pattern)
 
         self.assertEqual(scanner.scan("sum = 3*foo + 312.50 + bar"),
                          (['sum', 'op=', 3, 'op*', 'foo', 'op+', 312.5,
@@ -704,7 +704,7 @@
             self.skipTest('no problem if we have no unicode')
         class my_unicode(unicode): pass
         pat = re.compile(my_unicode("abc"))
-        self.assertEqual(pat.match("xyz"), None)
+        self.assertIsNone(pat.match("xyz"))
 
     def test_finditer(self):
         iter = re.finditer(r":+", "a:b::c:::d")
@@ -716,8 +716,8 @@
             unicode
         except NameError:
             self.skipTest('no problem if we have no unicode')
-        self.assertTrue(re.compile('bug_926075') is not
-                     re.compile(eval("u'bug_926075'")))
+        self.assertIsNot(re.compile('bug_926075'),
+                         re.compile(eval("u'bug_926075'")))
 
     def test_bug_931848(self):
         try:
@@ -735,7 +735,7 @@
 
         scanner = re.compile(r"\s").scanner("a b")
         self.assertEqual(scanner.search().span(), (1, 2))
-        self.assertEqual(scanner.search(), None)
+        self.assertIsNone(scanner.search())
 
     def test_bug_817234(self):
         iter = re.finditer(r".*", "asdf")
@@ -769,7 +769,7 @@
         import array
         for typecode in 'cbBuhHiIlLfd':
             a = array.array(typecode)
-            self.assertEqual(re.compile("bla").match(a), None)
+            self.assertIsNone(re.compile("bla").match(a))
             self.assertEqual(re.compile("").match(a).groups(), ())
 
     def test_inline_flags(self):
@@ -779,27 +779,27 @@
 
         p = re.compile(upper_char, re.I | re.U)
         q = p.match(lower_char)
-        self.assertNotEqual(q, None)
+        self.assertTrue(q)
 
         p = re.compile(lower_char, re.I | re.U)
         q = p.match(upper_char)
-        self.assertNotEqual(q, None)
+        self.assertTrue(q)
 
         p = re.compile('(?i)' + upper_char, re.U)
         q = p.match(lower_char)
-        self.assertNotEqual(q, None)
+        self.assertTrue(q)
 
         p = re.compile('(?i)' + lower_char, re.U)
         q = p.match(upper_char)
-        self.assertNotEqual(q, None)
+        self.assertTrue(q)
 
         p = re.compile('(?iu)' + upper_char)
         q = p.match(lower_char)
-        self.assertNotEqual(q, None)
+        self.assertTrue(q)
 
         p = re.compile('(?iu)' + lower_char)
         q = p.match(upper_char)
-        self.assertNotEqual(q, None)
+        self.assertTrue(q)
 
     def test_dollar_matches_twice(self):
         "$ matches the end of string, and just before the terminating \n"

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list