From 94251d061f1f0dc99ac99cfc9396b83a1dc9b148 Mon Sep 17 00:00:00 2001 From: Saager Mhatre Date: Thu, 15 Sep 2011 19:09:08 +0530 Subject: [PATCH] added unit test to test nose plugin's translation of features to test cases; ensure that test method names reflect scenario names. --- freshen/noseplugin.py | 2 +- freshen/test/async.py | 2 +- freshen/test/base.py | 4 ++-- freshen/test/pyunit.py | 2 +- other_tests/tests_freshen_nose_plugin.py | 14 ++++++++++++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/freshen/noseplugin.py b/freshen/noseplugin.py index ab93fc9..3e6635f 100644 --- a/freshen/noseplugin.py +++ b/freshen/noseplugin.py @@ -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 diff --git a/freshen/test/async.py b/freshen/test/async.py index 7cf150b..c525248 100644 --- a/freshen/test/async.py +++ b/freshen/test/async.py @@ -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(): diff --git a/freshen/test/base.py b/freshen/test/base.py index 228ab20..08dac29 100644 --- a/freshen/test/base.py +++ b/freshen/test/base.py @@ -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") @@ -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') diff --git a/freshen/test/pyunit.py b/freshen/test/pyunit.py index b76cbfa..cb785a9 100644 --- a/freshen/test/pyunit.py +++ b/freshen/test/pyunit.py @@ -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 diff --git a/other_tests/tests_freshen_nose_plugin.py b/other_tests/tests_freshen_nose_plugin.py index caf13d7..a8eab6f 100644 --- a/other_tests/tests_freshen_nose_plugin.py +++ b/other_tests/tests_freshen_nose_plugin.py @@ -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() @@ -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)