105
105
class TestApplyScenario(testtools.TestCase):
107
def test_apply_scenario_sets_id_and_attributes(self):
108
super(TestApplyScenario, self).setUp()
110
self.scenario_name = 'demo'
111
self.scenario_attrs = {'foo': 'bar'}
112
self.scenario = (self.scenario_name, self.scenario_attrs)
108
114
class ReferenceTest(unittest.TestCase):
109
115
def test_pass(self):
111
test = ReferenceTest("test_pass")
112
result = apply_scenario(('demo', {'foo': 'bar'}), test)
114
'testscenarios.tests.test_scenarios.ReferenceTest.test_pass(demo)',
116
self.assertEqual('bar', result.foo)
117
def test_pass_with_docstring(self):
118
""" The test that always passes.
120
This test case has a PEP 257 conformant docstring,
121
with its first line being a brief synopsis and the
122
rest of the docstring explaining that this test
123
does nothing but pass unconditionally.
128
self.ReferenceTest = ReferenceTest
130
def test_sets_specified_id(self):
131
raw_test = self.ReferenceTest('test_pass')
132
raw_id = "testscenarios.tests.test_scenarios.ReferenceTest.test_pass"
133
scenario_name = self.scenario_name
134
expect_id = "%(raw_id)s(%(scenario_name)s)" % vars()
135
modified_test = apply_scenario(self.scenario, raw_test)
136
self.assertEqual(expect_id, modified_test.id())
138
def test_sets_specified_attributes(self):
139
raw_test = self.ReferenceTest('test_pass')
140
modified_test = apply_scenario(self.scenario, raw_test)
141
self.assertEqual('bar', modified_test.foo)
143
def test_appends_scenario_name_to_short_description(self):
144
raw_test = self.ReferenceTest('test_pass_with_docstring')
145
modified_test = apply_scenario(self.scenario, raw_test)
146
raw_doc = self.ReferenceTest.test_pass_with_docstring.__doc__
147
raw_desc = raw_doc.split("\n")[0].strip()
148
scenario_name = self.scenario_name
149
expect_desc = "%(raw_desc)s (%(scenario_name)s)" % vars()
150
self.assertEqual(expect_desc, modified_test.shortDescription())
119
152
class TestApplyScenarios(testtools.TestCase):