AssertRegexMatches equivalent in python 2.4

Say I have a regex

REGEX = re.compile('.*foo{')

How do you write unit test that matches a rowset with python 2.4?

I know in python 2.7. I can use assertRegexMatches, unfortunately this does not work in 2.4: /

I use self.assertEqual for the rest of my tests.

Cheers, M

+3
source share
4 answers

Since you asked about a rowset, not a single row

def createMatcher( self, regex ):
    def matchCheck( argument ):
        self.assertTrue( regex.match( argument ) )
    return matchCheck

Then in your function:

map( self.createMatcher( REGEX ), mySetOfStrings )
+2
source
self.assertTrue(REGEX.match(text))
+4
source

, :

assertTrue(REGEX.match(data))

, , :

assertTrue(REGEX.search(data))

. , , TestCase , .

+2

For testing earlier versions of Python, I prefer to use unittest2: http://pypi.python.org/pypi/unittest2/

This is the backport of unittestsupported by Michael Ford, the same developer who supports the stdlib version.

+1
source

Source: https://habr.com/ru/post/1760796/


All Articles