Commits

Arve Knudsen committed 0c263c7

Testing of doctests plugin: test also loading from Python module

  • Participants
  • Parent commits 144b946
  • Branches test-doctests

Comments (0)

Files changed (3)

nose2/plugins/doctests.py

         if ext in self.extensions:
             suite = doctest.DocFileTest(path, module_relative=False)
             event.extraTests.append(suite)
+            # XXX: Return from here, since we know now this isn't a module from
+            # which to load doctests?
         elif not loader.VALID_MODULE_NAME.match(os.path.basename(path)):
             return
 

nose2/tests/_common.py

 import os.path
 import tempfile
 import shutil
+import sys
 
 class TestCase(unittest2.TestCase):
     """TestCase extension.
         
         if self._RUN_IN_TEMP:
             self.__orig_dir = os.getcwd()
-            self.__work_dir = tempfile.mkdtemp()
+            work_dir = self.__work_dir = tempfile.mkdtemp()
             os.chdir(self.__work_dir)
+            # Make sure it's possible to import modules from current directory
+            sys.path.insert(0, work_dir)
 
     def tearDown(self):
         super(TestCase, self).tearDown()

nose2/tests/test_doctests.py

 """Test doctests plugin."""
 import doctest
+import unittest
+import os.path
 
 from ..plugins import doctests
 
             self.assertTrue(isinstance(test, doctest.DocFileCase))
             self.assertEqual(repr(test), fh.name)
 
+        # Excercise loading of doctests from Python code
+        fh = open('docs.py', 'wb')
+        try:
+            fh.write("""\
+\"\"\"
+>>> 2 == 2
+True
+\"\"\"
+""")
+        finally:
+            fh.close()
+        
+        event = FakeHandleFileEvent(fh.name)
+        plug.handleFile(event)
+        testsuite, = event.extraTests
+        test, = list(testsuite)
+        self.assertEqual(repr(test), '%s ()' % os.path.splitext(fh.name)[0])
+
 
     def __create(self):
         """Create a DocTestLoader instance."""