From 34c91dd7b913bfd9bf8e22772398e1c10e000dcf Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Sun, 8 Mar 2009 13:03:02 +1100 Subject: Start on TestWithScenarios. --- HACKING | 8 ++++++++ lib/testscenarios/__init__.py | 2 ++ lib/testscenarios/testcase.py | 27 ++++++++++++++++++++++++ lib/testscenarios/tests/__init__.py | 10 +++++++-- lib/testscenarios/tests/test_testcase.py | 35 ++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 lib/testscenarios/testcase.py create mode 100644 lib/testscenarios/tests/test_testcase.py diff --git a/HACKING b/HACKING index fb1a1bf..d93b90c 100644 --- a/HACKING +++ b/HACKING @@ -27,3 +27,11 @@ Coding standards PEP-8 coding style please, though I'm not nitpicky. Make sure that 'make check' passes before sending in a patch. + +Code arrangement +++++++++++++++++ + +The ``testscenarios`` module should simply import classes and functions from +more specific modules, rather than becoming large and bloated itself. For +instance, TestWithScenarios lives in testscenarios.testcase, and is imported in +the testscenarios __init__.py. diff --git a/lib/testscenarios/__init__.py b/lib/testscenarios/__init__.py index a4f338d..57b49b4 100644 --- a/lib/testscenarios/__init__.py +++ b/lib/testscenarios/__init__.py @@ -32,6 +32,8 @@ methods for details. import unittest +from testscenarios.testcase import TestWithScenarios + def test_suite(): import testscenarios.tests diff --git a/lib/testscenarios/testcase.py b/lib/testscenarios/testcase.py new file mode 100644 index 0000000..f8c0e8e --- /dev/null +++ b/lib/testscenarios/testcase.py @@ -0,0 +1,27 @@ +# testscenarios: extensions to python unittest to allow declarative +# dependency injection ('scenarios') by tests. +# Copyright (C) 2009 Robert Collins +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +__all__ = [ + 'TestWithScenarios', + ] + +import unittest + +class TestWithScenarios(unittest.TestCase): + """A TestCase with support for scenarios via a scenarios attribute.""" diff --git a/lib/testscenarios/tests/__init__.py b/lib/testscenarios/tests/__init__.py index 98cfb11..1777e74 100644 --- a/lib/testscenarios/tests/__init__.py +++ b/lib/testscenarios/tests/__init__.py @@ -17,6 +17,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +import sys import unittest import testscenarios @@ -24,11 +25,16 @@ import testscenarios def test_suite(): result = unittest.TestSuite() - return result + standard_tests = unittest.TestSuite() + module = sys.modules['testscenarios.tests'] + loader = unittest.TestLoader() + return load_tests(standard_tests, module, loader) def load_tests(standard_tests, module, loader): - test_modules = [] + test_modules = [ + 'testcase', + ] prefix = "testscenarios.tests.test_" test_mod_names = [prefix + test_module for test_module in test_modules] standard_tests.addTests(loader.loadTestsFromNames(test_mod_names)) diff --git a/lib/testscenarios/tests/test_testcase.py b/lib/testscenarios/tests/test_testcase.py new file mode 100644 index 0000000..f5c7cef --- /dev/null +++ b/lib/testscenarios/tests/test_testcase.py @@ -0,0 +1,35 @@ +# testscenarios: extensions to python unittest to allow declarative +# dependency injection ('scenarios') by tests. +# Copyright (C) 2009 Robert Collins +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +import unittest + +import testscenarios + + +class TestTestWithScenarios(unittest.TestCase): + + def test_no_scenarios_no_error(self): + class ReferenceTest(testscenarios.TestWithScenarios): + def test_pass(self): + pass + test = ReferenceTest("test_pass") + result = test.run() + + + -- cgit v1.2.1