[Opensrf-commits] r2244 - in trunk/src/python: . osrf tests (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon May 9 01:19:55 EDT 2011


Author: dbs
Date: 2011-05-09 01:19:51 -0400 (Mon, 09 May 2011)
New Revision: 2244

Added:
   trunk/src/python/tests/net_obj_test.py
   trunk/src/python/tests/test_coverage.py
   trunk/src/python/tests/testobj.py
Modified:
   trunk/src/python/Makefile.am
   trunk/src/python/osrf/net_obj.py
   trunk/src/python/tests/json_test.py
Log:
Add Python unit testing and coverage report to "make check"

If --enable-python is included in the arguments to configure, "make check"
runs all Python unit tests using nosetests and generates a testing coverage
report for all Python code.

The original json_test.py is factored out to provide a separate file for
testing osrf.net_obj vs. osrf.json vs. osrf.*, when we eventually get there.

Signed-off-by: Dan Scott <dan at coffeecode.net>


Modified: trunk/src/python/Makefile.am
===================================================================
--- trunk/src/python/Makefile.am	2011-05-08 18:17:53 UTC (rev 2243)
+++ trunk/src/python/Makefile.am	2011-05-09 05:19:51 UTC (rev 2244)
@@ -2,6 +2,9 @@
 
 DISTCLEANFILES = Makefile.in Makefile
 
+check:
+	nosetests --with-coverage --cover-package=osrf
+
 all-local:
 	@echo $@
 	python @srcdir@/setup.py build

Modified: trunk/src/python/osrf/net_obj.py
===================================================================
--- trunk/src/python/osrf/net_obj.py	2011-05-08 18:17:53 UTC (rev 2243)
+++ trunk/src/python/osrf/net_obj.py	2011-05-09 05:19:51 UTC (rev 2244)
@@ -176,7 +176,7 @@
                 exec(estr) 
                 return obj
 
-        # dict, but not a registered NetworObject
+        # dict, but not a registered NetworkObject
         for key, value in obj.iteritems():
             obj[key] = parse_net_object(value)
 

Modified: trunk/src/python/tests/json_test.py
===================================================================
--- trunk/src/python/tests/json_test.py	2011-05-08 18:17:53 UTC (rev 2243)
+++ trunk/src/python/tests/json_test.py	2011-05-09 05:19:51 UTC (rev 2244)
@@ -2,35 +2,8 @@
 sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
 
 import osrf.json, osrf.net_obj, unittest
+from testobj import TestObject
 
-class TestObject(object):
-    def __init__(self):
-        self.int = 1
-        self.string = "two"
-        self.array = [1,2,3,4]
-        self.dict = {'foo': 'bar', 'key': 'value'}
-        self.true = True
-        self.false = False
-        self.null = None
-
-class CheckNetworkEncoder(unittest.TestCase):
-    """Tests the NetworkEncoder JSON encoding extension"""
-
-    def setUp(self):
-        osrf.net_obj.register_hint('osrfMessage', ['threadTrace', 'locale', 'type', 'payload'], 'hash')
-        self.testo = TestObject()
-        self.ne = osrf.json.NetworkEncoder()
-
-    def test_connect(self):
-        test_json = self.ne.default(
-            osrf.net_obj.NetworkObject.osrfMessage({
-                    'threadTrace' : 0,
-                    'type' : "CONNECT"
-                } 
-            )
-        )
-        self.assertEqual(test_json, {'__p': {'threadTrace': 0, 'type': 'CONNECT'}, '__c': 'osrfMessage'})
-
 class CheckObjectToJSON(unittest.TestCase):
     """Tests the osrf.json.to_json() method that converts Python objects into JSON"""
     def setUp(self):

Added: trunk/src/python/tests/net_obj_test.py
===================================================================
--- trunk/src/python/tests/net_obj_test.py	                        (rev 0)
+++ trunk/src/python/tests/net_obj_test.py	2011-05-09 05:19:51 UTC (rev 2244)
@@ -0,0 +1,61 @@
+import sys, os
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
+
+import osrf.json, osrf.net_obj, unittest
+from testobj import TestObject
+
+class CheckNetworkEncoder(unittest.TestCase):
+    """Tests the NetworkEncoder JSON encoding extension"""
+
+    def setUp(self):
+        osrf.net_obj.register_hint('osrfMessage', ['threadTrace', 'locale', 'type', 'payload'], 'hash')
+        self.testo = TestObject()
+        self.ne = osrf.json.NetworkEncoder()
+
+    def test_connect(self):
+        test_json = self.ne.default(
+            osrf.net_obj.NetworkObject.osrfMessage({
+                    'threadTrace' : 0,
+                    'type' : "CONNECT"
+                } 
+            )
+        )
+        self.assertEqual(test_json, {'__p': 
+            {'threadTrace': 0, 'type': 'CONNECT'},
+            '__c': 'osrfMessage'}
+        )
+
+    def test_connect_array(self):
+        test_json = self.ne.default(
+            osrf.net_obj.NetworkObject.osrfMessage({
+                    'threadTrace' : 0,
+                    'type' : "CONNECT",
+                    'protocol' : "array"
+                } 
+            )
+        )
+        self.assertEqual(test_json, {'__p':
+            {'threadTrace': 0, 'protocol': 'array', 'type': 'CONNECT'},
+            '__c': 'osrfMessage'}
+        )
+
+    def test_connect_to_xml(self):
+        test_json = self.ne.default(
+            osrf.net_obj.NetworkObject.osrfMessage({
+                    'threadTrace' : 0,
+                    'type' : "CONNECT"
+                } 
+            )
+        )
+        self.assertEqual(
+            osrf.net_obj.to_xml(test_json), 
+            "<object><element key='__p'><object><element key='threadTrace'>"
+            "<number>0</number></element><element key='type'>"
+            "<string>CONNECT</string></element></object></element>"
+            "<element key='__c'><string>osrfMessage</string></element></object>"
+        )
+
+
+if __name__ == '__main__':
+    unittest.main()
+

Added: trunk/src/python/tests/test_coverage.py
===================================================================
--- trunk/src/python/tests/test_coverage.py	                        (rev 0)
+++ trunk/src/python/tests/test_coverage.py	2011-05-09 05:19:51 UTC (rev 2244)
@@ -0,0 +1,30 @@
+"""
+Trigger nosetests to give us a complete coverage statement
+
+nosetests only reports on the modules that are imported in
+the tests it finds; this file serves as a placeholder until
+we actually provide unit test coverage of the core files.
+"""
+
+import osrf.app
+import osrf.cache
+import osrf.conf
+import osrf.const
+import osrf.ex
+import osrf.gateway
+# Triggers an exception if mod_python is not installed
+#import osrf.http_translator
+import osrf.json
+import osrf.log
+import osrf.net_obj
+import osrf.net
+import osrf.server
+import osrf.ses
+import osrf.set
+import osrf.stack
+import osrf.system
+import osrf.xml_obj
+import unittest
+
+if __name__ == '__main__':
+    unittest.main()

Added: trunk/src/python/tests/testobj.py
===================================================================
--- trunk/src/python/tests/testobj.py	                        (rev 0)
+++ trunk/src/python/tests/testobj.py	2011-05-09 05:19:51 UTC (rev 2244)
@@ -0,0 +1,11 @@
+class TestObject(object):
+    def __init__(self):
+        self.int = 1
+        self.string = "two"
+        self.array = [1,2,3,4]
+        self.dict = {'foo': 'bar', 'key': 'value'}
+        self.true = True
+        self.false = False
+        self.null = None
+
+



More information about the opensrf-commits mailing list