From 456a72762dba322282be49fbb7c6ef522cacb369 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sun, 14 Jan 2007 16:56:23 +1100 Subject: Add sibpath --- python/subunit/__init__.py | 5 +++++ python/subunit/tests/test_test_protocol.py | 6 ++++++ 2 files changed, 11 insertions(+) (limited to 'python/subunit') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index d97a15b..caab176 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -27,6 +27,11 @@ def test_suite(): import subunit.tests return subunit.tests.test_suite() + +def sibpath(path, sibling): + return os.path.join(os.path.dirname(os.path.abspath(path)), sibling) + + class TestProtocolServer(object): """A class for receiving results from a TestProtocol client.""" diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 2530f25..e6d6f0d 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 @@ -593,6 +594,11 @@ 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): -- cgit v1.2.1 From 501ba57871b35bab0bce1da4b72f7990a4f9dc14 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sun, 14 Jan 2007 17:02:10 +1100 Subject: Make ExecTestCase test docstring/paths relative to the module they are defined in. --- python/subunit/__init__.py | 3 ++- python/subunit/tests/test_test_protocol.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'python/subunit') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index caab176..f56f724 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -283,7 +283,8 @@ class ExecTestCase(unittest.TestCase): """ unittest.TestCase.__init__(self, methodName) testMethod = getattr(self, methodName) - self.script = testMethod.__doc__ + self.script = sibpath(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 e6d6f0d..4cd693d 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -562,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.sibpath(__file__, 'sample-script.py')) def test_run(self): runner = MockTestProtocolServerClient() @@ -603,7 +604,7 @@ class TestExecTestCase(unittest.TestCase): class DoExecTestCase(subunit.ExecTestCase): def test_working_script(self): - """./python/subunit/tests/sample-two-script.py""" + """sample-two-script.py""" class TestIsolatedTestCase(unittest.TestCase): -- cgit v1.2.1 From cb1a0a2e928473ea68649c09b3691886ac93b57a Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sun, 14 Jan 2007 17:33:52 +1100 Subject: Rename sibpath to join_dir, and add a docstring. --- python/subunit/__init__.py | 18 ++++++++++++++---- python/subunit/tests/test_test_protocol.py | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'python/subunit') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index f56f724..7a04eb9 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -28,8 +28,18 @@ def test_suite(): return subunit.tests.test_suite() -def sibpath(path, sibling): - return os.path.join(os.path.dirname(os.path.abspath(path)), sibling) +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): @@ -283,8 +293,8 @@ class ExecTestCase(unittest.TestCase): """ unittest.TestCase.__init__(self, methodName) testMethod = getattr(self, methodName) - self.script = sibpath(sys.modules[self.__class__.__module__].__file__, - 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 4cd693d..1ee4886 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -570,7 +570,7 @@ class TestExecTestCase(unittest.TestCase): def test_construct(self): test = self.SampleExecTestCase("test_sample_method") self.assertEqual(test.script, - subunit.sibpath(__file__, 'sample-script.py')) + subunit.join_dir(__file__, 'sample-script.py')) def test_run(self): runner = MockTestProtocolServerClient() -- cgit v1.2.1