summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2009-03-08 13:03:02 +1100
committerRobert Collins <robertc@robertcollins.net>2009-03-08 13:03:02 +1100
commit34c91dd7b913bfd9bf8e22772398e1c10e000dcf (patch)
tree67c0a2f67e604d6ed9129cfadd5fceecbdf97ba3
parent86ce5aa1f3b33f73cd73f4628e5b854c3d9a7978 (diff)
downloadtestscenarios-git-34c91dd7b913bfd9bf8e22772398e1c10e000dcf.tar.gz
Start on TestWithScenarios.
-rw-r--r--HACKING8
-rw-r--r--lib/testscenarios/__init__.py2
-rw-r--r--lib/testscenarios/testcase.py27
-rw-r--r--lib/testscenarios/tests/__init__.py10
-rw-r--r--lib/testscenarios/tests/test_testcase.py35
5 files changed, 80 insertions, 2 deletions
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 <robertc@robertcollins.net>
+#
+# 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 <robertc@robertcollins.net>
+#
+# 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()
+
+
+