summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJonathan Lange <jml@mumak.net>2007-01-14 17:35:05 +1100
committerJonathan Lange <jml@mumak.net>2007-01-14 17:35:05 +1100
commitf7c5ccbc7732ff89c07da3bb822d7ab95542ca7c (patch)
tree6fd93e243a812de0179d3d63382a21ea373cb51f /python
parent46661c83dee2138c9918798f36d8b40edab5ffad (diff)
parentcb1a0a2e928473ea68649c09b3691886ac93b57a (diff)
downloadsubunit-git-f7c5ccbc7732ff89c07da3bb822d7ab95542ca7c.tar.gz
Make ExecTestCase test docstrings/paths relative to the test module they
are defined in.
Diffstat (limited to 'python')
-rw-r--r--python/subunit/__init__.py18
-rw-r--r--python/subunit/tests/test_test_protocol.py13
2 files changed, 27 insertions, 4 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py
index d97a15b..7a04eb9 100644
--- a/python/subunit/__init__.py
+++ b/python/subunit/__init__.py
@@ -27,6 +27,21 @@ def test_suite():
import subunit.tests
return subunit.tests.test_suite()
+
+def join_dir(base_path, path):
+ """
+ Returns an absolute path to C{path}, calculated relative to the parent
+ of C{base_path}.
+
+ @param base_path: A path to a file or directory.
+ @param path: An absolute path, or a path relative to the containing
+ directory of C{base_path}.
+
+ @return: An absolute path to C{path}.
+ """
+ return os.path.join(os.path.dirname(os.path.abspath(base_path)), path)
+
+
class TestProtocolServer(object):
"""A class for receiving results from a TestProtocol client."""
@@ -278,7 +293,8 @@ class ExecTestCase(unittest.TestCase):
"""
unittest.TestCase.__init__(self, methodName)
testMethod = getattr(self, methodName)
- self.script = testMethod.__doc__
+ self.script = join_dir(sys.modules[self.__class__.__module__].__file__,
+ testMethod.__doc__)
def countTestCases(self):
return 1
diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py
index 2530f25..1ee4886 100644
--- a/python/subunit/tests/test_test_protocol.py
+++ b/python/subunit/tests/test_test_protocol.py
@@ -19,6 +19,7 @@
import unittest
from StringIO import StringIO
+import os
import subunit
import sys
@@ -561,14 +562,15 @@ class TestExecTestCase(unittest.TestCase):
class SampleExecTestCase(subunit.ExecTestCase):
def test_sample_method(self):
- """./python/subunit/tests/sample-script.py"""
+ """sample-script.py"""
# the sample script runs three tests, one each
# that fails, errors and succeeds
def test_construct(self):
test = self.SampleExecTestCase("test_sample_method")
- self.assertEqual(test.script, "./python/subunit/tests/sample-script.py")
+ self.assertEqual(test.script,
+ subunit.join_dir(__file__, 'sample-script.py'))
def test_run(self):
runner = MockTestProtocolServerClient()
@@ -593,11 +595,16 @@ class TestExecTestCase(unittest.TestCase):
def test_count_test_cases(self):
"""TODO run the child process and count responses to determine the count."""
+ def test_sibpath(self):
+ sibling = subunit.sibpath(__file__, 'foo')
+ expected = '%s/foo' % (os.path.split(__file__)[0],)
+ self.assertEqual(sibling, expected)
+
class DoExecTestCase(subunit.ExecTestCase):
def test_working_script(self):
- """./python/subunit/tests/sample-two-script.py"""
+ """sample-two-script.py"""
class TestIsolatedTestCase(unittest.TestCase):