Skip to content

Commit

Permalink
added unit test to test nose plugin's translation of features to test…
Browse files Browse the repository at this point in the history
… cases;

ensure that test method names reflect scenario names.
  • Loading branch information
dexterous committed Sep 21, 2011
1 parent 75b4949 commit 94251d0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion freshen/noseplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def loadTestsFromFile(self, filename, indexes=[]):
for i, sc in enumerate(feat.iter_scenarios()):
if (not indexes or (i + 1) in indexes):
if self.tagmatcher.check_match(sc.tags + feat.tags):
test_class = type(feat.name, (self._loadTestForFeature(feat), ), {})
test_class = type(feat.name, (self._loadTestForFeature(feat), ), {sc.name: lambda self: self.runScenario()})
yield test_class(StepsRunner(step_registry), step_registry, feat, sc, ctx)
cnt += 1

Expand Down
2 changes: 1 addition & 1 deletion freshen/test/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def setUp(self):
return self._run_deferred(hooks)

@inlineCallbacks
def runTest(self):
def runScenario(self):
"""Run the test."""
steps = []
for step in self.scenario.iter_steps():
Expand Down
4 changes: 2 additions & 2 deletions freshen/test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, step_runner, step_registry, feature, scenario, feature_suite)
self.step_runner = step_runner

self.description = feature.name + ": " + scenario.name
super(FreshenTestCase, self).__init__()
super(FreshenTestCase, self).__init__(scenario.name)

def setUp(self):
#log.debug("Clearing scenario context")
Expand All @@ -71,5 +71,5 @@ def runStep(self, step, discard_frames=0):
raise ExceptionWrapper(sys.exc_info(), step, discard_frames)
self.runAfterStepHooks()

def runTest(self):
def runScenario(self):
raise NotImplementedError('Must be implemented by subclasses')
2 changes: 1 addition & 1 deletion freshen/test/pyunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self):
for hook_impl in self.step_registry.get_hooks('before', self.scenario.get_tags()):
hook_impl.run(self.scenario)

def runTest(self):
def runScenario(self):
for step in self.scenario.iter_steps():
self.runStep(step, 3)
self.last_step = None
Expand Down
14 changes: 12 additions & 2 deletions other_tests/tests_freshen_nose_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class TestFreshenTestCaseName(unittest.TestCase):

def test_should_subclass_FreshenTestCase_with_feature_name(self):
def _make_plugin(self):
plugin = FreshenNosePlugin()
parser = OptionParser()

Expand All @@ -17,8 +17,18 @@ def test_should_subclass_FreshenTestCase_with_feature_name(self):
(options, args) = parser.parse_args()

plugin.configure(options, None)
return plugin

test_generator = plugin.loadTestsFromFile('resources/valid_no_tags_no_use_only.feature')
def test_should_use_feature_name_as_class_name_when_subclassing_FreshenTestCase(self):
plugin = self._make_plugin()
test_generator = plugin.loadTestsFromFile('./resources/valid_no_tags_no_use_only.feature')
test_instance = test_generator.next()

self.assertEquals(test_instance.__class__.__name__, 'Independence of the counter.')

def test_should_use_scenario_name_as_method_name_when_subclassing_FreshenTestCase(self):
plugin = self._make_plugin()
test_generator = plugin.loadTestsFromFile('./resources/valid_no_tags_no_use_only.feature')
test_instance = test_generator.next()

self.assertNotEqual(getattr(test_instance, 'Print counter', None), None)

0 comments on commit 94251d0

Please sign in to comment.