Package openid :: Package test :: Module test_urinorm
[frames] | no frames]

Source Code for Module openid.test.test_urinorm

 1  import os 
 2  import unittest 
 3  import openid.urinorm 
 4   
5 -class UrinormTest(unittest.TestCase):
6 - def __init__(self, desc, case, expected):
7 unittest.TestCase.__init__(self) 8 self.desc = desc 9 self.case = case 10 self.expected = expected
11
12 - def shortDescription(self):
13 return self.desc
14
15 - def runTest(self):
16 try: 17 actual = openid.urinorm.urinorm(self.case) 18 except ValueError, why: 19 self.assertEqual(self.expected, 'fail', why) 20 else: 21 self.assertEqual(actual, self.expected)
22
23 - def parse(cls, full_case):
24 desc, case, expected = full_case.split('\n') 25 case = unicode(case, 'utf-8') 26 27 return cls(desc, case, expected)
28 29 parse = classmethod(parse)
30 31
32 -def parseTests(test_data):
33 result = [] 34 35 cases = test_data.split('\n\n') 36 for case in cases: 37 case = case.strip() 38 39 if case: 40 result.append(UrinormTest.parse(case)) 41 42 return result
43
44 -def pyUnitTests():
45 here = os.path.dirname(os.path.abspath(__file__)) 46 test_data_file_name = os.path.join(here, 'urinorm.txt') 47 test_data_file = file(test_data_file_name) 48 test_data = test_data_file.read() 49 test_data_file.close() 50 51 tests = parseTests(test_data) 52 return unittest.TestSuite(tests)
53