1 from openid
.consumer
.html_parse
import parseLinkAttrs
8 optional
= parts
[0] == 'Link*:'
9 assert optional
or parts
[0] == 'Link:'
12 for attr
in parts
[1:]:
13 k
, v
= attr
.split('=', 1)
20 attrs
[k
] = (attr_optional
, v
)
22 return (optional
, attrs
)
25 header
, markup
= s
.split('\n\n', 1)
26 lines
= header
.split('\n')
28 assert name
.startswith('Name: ')
30 return desc
, markup
, map(parseLink
, lines
)
35 cases
= s
.split('\n\n\n')
37 tests_line
, _
= header
.split('\n', 1)
38 k
, v
= tests_line
.split(': ')
39 assert k
== 'Num Tests'
42 for case
in cases
[:-1]:
43 desc
, markup
, links
= parseCase(case
)
44 tests
.append((desc
, markup
, links
, case
))
46 return num_tests
, tests
48 class _LinkTest(unittest
.TestCase
):
49 def __init__(self
, desc
, case
, expected
, raw
):
50 unittest
.TestCase
.__init
__(self
)
53 self
.expected
= expected
56 def shortDescription(self
):
60 actual
= parseLinkAttrs(self
.case
)
62 for optional
, exp_link
in self
.expected
:
68 for k
, (o
, v
) in exp_link
.items():
70 act_v
= act_link
.get(k
)
76 if optional
and v
!= act_v
:
79 self
.assertEqual(v
, act_v
)
83 assert i
== len(actual
)
86 here
= os
.path
.dirname(os
.path
.abspath(__file__
))
87 test_data_file_name
= os
.path
.join(here
, 'linkparse.txt')
88 test_data_file
= codecs
.open(test_data_file_name
, 'r', 'utf-8')
89 test_data
= test_data_file
.read()
90 test_data_file
.close()
92 num_tests
, test_cases
= parseTests(test_data
)
94 tests
= [_LinkTest(*case
) for case
in test_cases
]
96 def test_parseSucceeded():
97 assert len(test_cases
) == num_tests
, (len(test_cases
), num_tests
)
99 check_desc
= 'Check that we parsed the correct number of test cases'
100 check
= unittest
.FunctionTestCase(
101 test_parseSucceeded
, description
=check_desc
)
102 tests
.insert(0, check
)
104 return unittest
.TestSuite(tests
)
106 if __name__
== '__main__':
107 suite
= pyUnitTests()
108 runner
= unittest
.TextTestRunner()