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