class TestPluginSpecWithFoobazAndStandardPluginsEnabled( TestPluginSpecWithFoobaz): plugins = [ Spec(), nose.plugins.skip.Skip(), nose.plugins.deprecated.Deprecated() ]
class TestPluginSpecWithFileEnabled(SpecPluginTestCase): activate = '--with-spec' args = ['--spec-file', tempfile.NamedTemporaryFile(delete=False).name] plugins = [Spec()] suitename = 'foobar' test_lines = [ "Baz bar", "- does this and that", "Foobar", "- can be automatically documented", "- is a singleton" ] def test_does_output_default_output_if_spec_file_given(self): for line in self.test_lines: self.failIfContainsInOutput(line) self.assertIn("...", self.output, "Default nosetests output shouldn't be silenced") def test_does_output_spec_output_to_file_if_spec_file_given(self): with open(self.args[1], 'r') as spec_file: file_content = spec_file.read() for line in self.test_lines: self.assertIn(line, file_content) @classmethod def tearDownClass(cls): os.unlink(cls.args[1])
class TestPluginSpecWithDoctestsButDisabled(SpecPluginTestCase): activate = '--with-spec' args = ['--with-doctest', '--doctest-tests'] # no --spec-doctests option plugins = [Spec(), nose.plugins.doctests.Doctest()] suitename = 'doctests' def test_doesnt_build_specifications_for_doctests_when_spec_doctests_option_wasnt_set( self): self.failIfContainsInOutput("test_doctests") self.failIfContainsInOutput("2 + 3 returns 5")
class TestPluginSpecWithDoctests(SpecPluginTestCase): activate = '--with-spec' args = ['--with-doctest', '--doctest-tests', '--spec-doctests'] plugins = [Spec(), nose.plugins.doctests.Doctest()] suitename = 'doctests' expected_test_doctests_output = """test_doctests - 2 + 3 returns 5 - None is nothing - foobar throws "NameError: name 'foobar' is not defined" """ def test_builds_specifications_for_doctests(self): self.assertContainsInOutput(self.expected_test_doctests_output)
class SpecPluginTestCase(PluginTester, unittest.TestCase): activate = '--with-spec' plugins = [Spec()] def _get_suitepath(self): return 'tests/spec_test_cases/test_%s.py' % self.suitename suitepath = property(_get_suitepath) def assertContains(self, needle, haystack): assert needle in haystack,\ "Failed to find:\n\n%s\ninside\n%s\n" % \ (prepend_in_each_line(needle), prepend_in_each_line(haystack)) def assertContainsInOutput(self, string): self.assertContains(string, str(self.output)) def failIfContains(self, needle, haystack): assert needle not in haystack,\ "Found:\n\n%s\ninside\n%s\n" % \ (prepend_in_each_line(needle), prepend_in_each_line(haystack)) def failIfContainsInOutput(self, string): self.failIfContains(string, str(self.output))