jeudi 4 juin 2015

Unit Testing with Variable Inputs

I have the following code that performs unit tests on code I developed for matching reg expressions in all the files within a main directory and each sub-directory.

I am building units tests to make sure it performs well but I am very new to unit testing.

I have the following code:

class TestRegexMatches(unittest.TestCase):

def __init__(self,root_dir):
    self.path = root_dir

def testEmptyRegex(self):
    # Can't match negative look-ahead
    key = re.compile('(?!)')
    self.assertEqual(sum(tm.search_for_regex_match(self.path,key).values()),0)

def testIntersection(self):
    key1 = re.compile('[abc]')
    key2 = re.compile('[^abc]')
    self.assertNotEqual(tm.search_for_regex_match(self.path,key1),
                        tm.search_for_regex_match(self.path,key2))


if __name__ == '__main__':
    test_obj = TestRegexMatches('/home/luis/test')
    unittest.main()

This code currently doesn't work. Normally, one would not have the init constructor for the unit tests but I want to be able to give the tests different directories to search under for different tests instead of hard coding the path in the tm.search_for_regex_match function.

Aucun commentaire:

Enregistrer un commentaire