[Checkins] SVN: manuel/branches/chrism-codeblocks/src/manuel/tests Add tests for codeblock change.

Chris McDonough chrism at plope.com
Sat Dec 26 10:14:47 EST 2009


Log message for revision 107094:
  Add tests for codeblock change.
  

Changed:
  A   manuel/branches/chrism-codeblocks/src/manuel/tests/
  A   manuel/branches/chrism-codeblocks/src/manuel/tests/__init__.py
  A   manuel/branches/chrism-codeblocks/src/manuel/tests/test_codeblocks.py
  A   manuel/branches/chrism-codeblocks/src/manuel/tests/test_doctests.py
  D   manuel/branches/chrism-codeblocks/src/manuel/tests.py

-=-
Added: manuel/branches/chrism-codeblocks/src/manuel/tests/__init__.py
===================================================================
--- manuel/branches/chrism-codeblocks/src/manuel/tests/__init__.py	                        (rev 0)
+++ manuel/branches/chrism-codeblocks/src/manuel/tests/__init__.py	2009-12-26 15:14:47 UTC (rev 107094)
@@ -0,0 +1 @@
+# package

Added: manuel/branches/chrism-codeblocks/src/manuel/tests/test_codeblocks.py
===================================================================
--- manuel/branches/chrism-codeblocks/src/manuel/tests/test_codeblocks.py	                        (rev 0)
+++ manuel/branches/chrism-codeblocks/src/manuel/tests/test_codeblocks.py	2009-12-26 15:14:47 UTC (rev 107094)
@@ -0,0 +1,70 @@
+import unittest
+
+_NO_ROLES = """\
+.. code-block:: python
+
+   def foo(abc):
+       return 1
+"""
+
+_WITH_ROLES = """\
+.. code-block:: python
+   :linenos:
+   :other:
+
+   def foo(abc):
+       return 1
+"""
+
+class Test_find_code_blocks(unittest.TestCase):
+    def _callFUT(self, document):
+        from manuel.codeblock import find_code_blocks
+        return find_code_blocks(document)
+
+    def test_start_end_no_roles(self):
+        region = DummyRegion(_NO_ROLES)
+        document = DummyDocument([region])
+        self._callFUT(document)
+        self.assertEqual(document.claimed, [region])
+        self.assertEqual(region.parsed.code.co_names, ('foo',))
+
+    def test_start_end_with_roles(self):
+        region = DummyRegion(_WITH_ROLES)
+        document = DummyDocument([region])
+        self._callFUT(document)
+        self.assertEqual(document.claimed, [region])
+        self.assertEqual(region.parsed.code.co_names, ('foo',))
+
+    def test_start_end_multiple_regions(self):
+        region1 = DummyRegion(_WITH_ROLES)
+        region2 = DummyRegion(_NO_ROLES)
+        document = DummyDocument([region1, region2])
+        self._callFUT(document)
+        self.assertEqual(document.claimed, [region1, region2])
+        self.assertEqual(region1.parsed.code.co_names, ('foo',))
+        self.assertEqual(region2.parsed.code.co_names, ('foo',))
+
+class DummyRegion(object):
+    lineno = 1
+    def __init__(self, source):
+        self.source = source
+
+class DummyDocument(object):
+    location = 0
+    def __init__(self, regions):
+        self._regions = regions
+        self.claimed = []
+
+    def find_regions(self, start, end):
+        return self._regions
+
+    def claim_region(self, region):
+        self.claimed.append(region)
+    
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(Test_find_code_blocks))
+    return suite
+
+if __name__ == '__main__':
+    unittest.main()

Copied: manuel/branches/chrism-codeblocks/src/manuel/tests/test_doctests.py (from rev 107064, manuel/branches/chrism-codeblocks/src/manuel/tests.py)
===================================================================
--- manuel/branches/chrism-codeblocks/src/manuel/tests/test_doctests.py	                        (rev 0)
+++ manuel/branches/chrism-codeblocks/src/manuel/tests/test_doctests.py	2009-12-26 15:14:47 UTC (rev 107094)
@@ -0,0 +1,92 @@
+from zope.testing import renormalizing
+import manuel
+import manuel.capture
+import manuel.codeblock
+import manuel.doctest
+import manuel.ignore
+import manuel.testcase
+import manuel.testing
+import os.path
+import re
+import unittest
+
+#doctest = manuel.absolute_import('doctest')
+from zope.testing import doctest
+
+
+def get_abs_path(p):
+    def fake():
+        pass
+    # this contorted dance is neccesitated by me wanting to be able to run the
+    # tests with "bin/py src/manuel/tests.py" since bin/py uses execfile, which
+    # means that __file__ -- which I'd normally use here -- will be "bin/py"
+    # not the path to *this* module
+    here = os.path.dirname(fake.func_code.co_filename)
+    return os.path.join(os.getcwd(), here, p)
+
+_NO_ROLES = """\
+Stuff
+
+.. code-block:: python
+
+   def foo(abc):
+       return 1
+
+More stuff
+"""
+
+_WITH_ROLES = """\
+Stuff
+
+.. code-block:: python
+
+   def foo(abc):
+       return 1
+
+More stuff.
+"""
+
+class Test_find_code_blocks(unittest.TestCase):
+    def _callFUT(self, document):
+        from manuel.codeblock import find_code_blocks
+        return find_code_blocks(document)
+
+    def test_start_end_no_roles(self):
+        region = Region(_NO_ROLES)
+        document = DummyDocument([region])
+        self._callFUT(document)
+
+class Region(object):
+    lineno = 1
+    def __init__(self, source):
+        self.source = source
+
+class DummyDocument(object):
+    def __init__(self, regions):
+        self._regions = regions
+        self.claimed = []
+
+    def find_regions(self, start, end):
+        return self._regions
+
+    def claim_region(self, region):
+        self.claimed.append(region)
+    
+def test_suite():
+    optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
+    checker = renormalizing.RENormalizing([
+        (re.compile(r'<zope\.testing\.doctest\.'), '<doctest.'),
+        ])
+
+    tests = ['../../index.txt', '../table-example.txt', '../README.txt',
+             '../bugs.txt', '../capture.txt']
+
+    m = manuel.ignore.Manuel()
+    m += manuel.doctest.Manuel(optionflags=optionflags, checker=checker)
+    m += manuel.codeblock.Manuel()
+    m += manuel.capture.Manuel()
+    return manuel.testing.TestSuite(m, *tests)
+
+
+if __name__ == '__main__':
+    unittest.TextTestRunner().run(test_suite())

Deleted: manuel/branches/chrism-codeblocks/src/manuel/tests.py
===================================================================
--- manuel/branches/chrism-codeblocks/src/manuel/tests.py	2009-12-26 15:10:21 UTC (rev 107093)
+++ manuel/branches/chrism-codeblocks/src/manuel/tests.py	2009-12-26 15:14:47 UTC (rev 107094)
@@ -1,45 +0,0 @@
-from zope.testing import renormalizing
-import manuel
-import manuel.capture
-import manuel.codeblock
-import manuel.doctest
-import manuel.ignore
-import manuel.testcase
-import manuel.testing
-import os.path
-import re
-import unittest
-
-#doctest = manuel.absolute_import('doctest')
-from zope.testing import doctest
-
-
-def get_abs_path(p):
-    def fake():
-        pass
-    # this contorted dance is neccesitated by me wanting to be able to run the
-    # tests with "bin/py src/manuel/tests.py" since bin/py uses execfile, which
-    # means that __file__ -- which I'd normally use here -- will be "bin/py"
-    # not the path to *this* module
-    here = os.path.dirname(fake.func_code.co_filename)
-    return os.path.join(os.getcwd(), here, p)
-
-
-def test_suite():
-    optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
-    checker = renormalizing.RENormalizing([
-        (re.compile(r'<zope\.testing\.doctest\.'), '<doctest.'),
-        ])
-
-    tests = ['../index.txt', 'table-example.txt', 'README.txt', 'bugs.txt',
-        'capture.txt']
-
-    m = manuel.ignore.Manuel()
-    m += manuel.doctest.Manuel(optionflags=optionflags, checker=checker)
-    m += manuel.codeblock.Manuel()
-    m += manuel.capture.Manuel()
-    return manuel.testing.TestSuite(m, *tests)
-
-
-if __name__ == '__main__':
-    unittest.TextTestRunner().run(test_suite())



More information about the checkins mailing list