Commits

Anonymous committed c7fdecb

Fix and improve tests, now to run all tests simply run run_all_tests.py from inside tests. Fix accidential bugs in previous commits: in message.py and xmlschema.py

Comments (0)

Files changed (12)

                         continue
                     else:
                         raise ValueError("Non-nillable parameter %s is not "
-                                         "present %name" %
-                                         setattr(p, name, val))
+                                         "present" % name)
+                setattr(p, name, val)
 
         # set default ns to save space
         # this does not work with xml qualified/unqualified, need a hack
         imports.extend(self.schema.findall('.//{%s}include' %
                                            xmlnamespace.NS_XSD))
         for schema in imports:
-            loc = schema.get('schemdaLocation', None)
+            loc = schema.get('schemaLocation', None)
             # basically says that types from that namespace will be used, no real
             # import, i.e. the real schema was defined already
             if loc is None:

tests/__init__.py

 # -*- coding: utf-8 -*-
-
-import unittest
-import os
-
-test_dir = os.path.abspath(os.path.dirname(__file__))
-path_join = lambda f: os.path.join(test_dir, f)
-
-
-class BaseTest(unittest.TestCase):
-
-    test_files = {
-        'test.wsdl': path_join('test.wsdl'),
-        'test.xml': path_join('test.xml'),
-        'schema.xml': path_join('schema.xml'),
-        'schema2.xml': path_join('schema2.xml'),
-        'schema3.xml': path_join('schema3.xml'),
-    }
-
-if __name__ == '__main__':
-    unittest.main()
+# -*- coding: utf-8 -*-
+# base.py - basic stuff for tests, part of osa.
+# Copyright 2013 Sergey Bozhenkov, boz at ipp.mpg.de
+# Licensed under GPLv3 or later, see the COPYING file.
+
+import unittest
+import os
+
+test_dir = os.path.abspath(os.path.dirname(__file__))
+path_join = lambda f: os.path.join(test_dir, f)
+
+
+class BaseTest(unittest.TestCase):
+
+    test_files = {
+        'test.wsdl': path_join('test.wsdl'),
+        'test.xml': path_join('test.xml'),
+        'schema.xml': path_join('schema.xml'),
+        'schema2.xml': path_join('schema2.xml'),
+        'schema3.xml': path_join('schema3.xml'),
+    }

tests/run_all_tests.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# run_all_tests.py - run all tests, part of osa.
+# Copyright 2013 Sergey Bozhenkov, boz at ipp.mpg.de
+# Licensed under GPLv3 or later, see the COPYING file.
+
+import unittest
+from test_xmlparser import TestXMLParser
+from test_xmltypes_primitive import TestPrimitive
+from test_xmltypes_complex import TestClassSerializer
+from test_xmlschema import TestXMLSchema
+from test_wsdl import TestWSDL
+from test_message import TestMessage
+from test_client import TestClient
+
+if __name__ == '__main__':
+    unittest.main()

tests/test_client.py

 # Copyright 2013 Sergey Bozhenkov, boz at ipp.mpg.de
 # Licensed under GPLv3 or later, see the COPYING file.
 
+
 import os
 import sys
-# for x in sys.path:
-#     if x.find("osa") != -1:
-#         sys.path.remove(x)
-sys.path.append("../")
-
-import unittest
-# import xml.etree.cElementTree as etree
+sys.path.insert(0, "../")
 from osa.client import Client
 from osa.wsdl import *
 from osa.method import *
 from osa.xmltypes import *
-from . import BaseTest
+from tests.base import BaseTest
+import unittest
 if sys.version_info.major < 3:
     from urllib2 import urlopen, HTTPError, URLError
 else:

tests/test_message.py

 # Licensed under GPLv3 or later, see the COPYING file.
 
 import sys
-# for x in sys.path:
-#     if x.find("osa") != -1:
-#         sys.path.remove(x)
-sys.path.append("../")
-
-import unittest
-import xml.etree.cElementTree as etree
+sys.path.insert(0, "../")
 from osa.xmlschema import *
 from osa.xmlparser import *
 from osa.message import *
-
-from . import BaseTest
+from tests.base import BaseTest
+import xml.etree.cElementTree as etree
+import unittest
 
 
 class TestMessage(BaseTest):
         self.assertEqual(res.__class__.__name__, "Name")
         self.assertEqual(res.firstName, "kolo")
         self.assertEqual(res.lastName, "bok")
-

tests/test_wsdl.py

 # Licensed under GPLv3 or later, see the COPYING file.
 
 import sys
-for x in sys.path:
-    if x.find("osa") != -1:
-        sys.path.remove(x)
-sys.path.append("../")
-
-import unittest
-import xml.etree.cElementTree as etree
+sys.path.insert(0, "../")
 from osa.wsdl import *
 from osa.method import *
 from osa.message import *
 from osa.xmltypes import *
+from tests.base import BaseTest
+import xml.etree.cElementTree as etree
+import unittest
 
 wsdl_url = 'test.wsdl'
 ns1 = "de.mpg.ipp.hgw.boz.gsoap.helloworld"
 
 
 class TestWSDL(unittest.TestCase):
+
     def test_reading(self):
         w = WSDLParser(wsdl_url)
         self.assertEqual(w.wsdl_url, wsdl_url)
             b = bs[n]
             self.assertTrue(s is b)
             self.assertEqual(s.location, "http://lxpowerboz:88/services/cpp/HelloWorldService")
-
-
-if __name__ == '__main__':
-    unittest.main()

tests/test_xmlparser.py

 # Licensed under GPLv3 or later, see the COPYING file.
 
 import sys
-import os
-# for x in sys.path:
-#     if x.find("osa") != -1:
-#         sys.path.remove(x)
-sys.path.append("../")
-
+sys.path.insert(0, "../")
+from osa.xmlparser import *
+from tests.base import BaseTest
+import xml.etree.cElementTree as etree
 import unittest
-import xml.etree.cElementTree as etree
-from osa.xmlparser import *
-
-from . import BaseTest
 
 
 class TestXMLParser(BaseTest):
+
     def test_ns_attr_parsing(self):
         root = parse_qualified_from_url(self.test_files["test.xml"],
                                         attr=["a"])

tests/test_xmlschema.py

 # Licensed under GPLv3 or later, see the COPYING file.
 
 import sys
-for x in sys.path:
-    if x.find("osa") != -1:
-        sys.path.remove(x)
-sys.path.append("../")
-
-import unittest
-import xml.etree.cElementTree as etree
+sys.path.insert(0, "../")
 from osa.xmlschema import *
 from osa.xmlparser import *
-from . import BaseTest
+from tests.base import BaseTest
+import xml.etree.cElementTree as etree
+import unittest
 
 
 class TestXMLSchema(BaseTest):
+
     def setUp(self):
         root = parse_qualified_from_url(self.test_files["schema.xml"])
         self.schema = XMLSchemaParser(root)
+
     def tearDown(self):
         self.schema = None
+
     def test_get_list_of_types(self):
         res = self.schema.get_list_of_defined_types()
         self.assertTrue("{vostok}Name" in res)
         self.assertTrue("{sever}Car" in res)
         self.assertEqual(res["{sever}Car"].tag, "{%s}complexType" %xmlnamespace.NS_XSD)
         self.assertEqual(res["{sever}Car"].get("name"), "Car")
+
     def test_convert(self):
         xtypes = self.schema.get_list_of_defined_types()
         types = XMLSchemaParser.convert_xmltypes_to_python(xtypes)
         self.assertTrue(hasattr(types["{sever}Car"], "weight"))
         self.assertEqual(types["{sever}Car"]._namespace, "sever")
         self.assertEqual(types["{sever}Car"].__class__.__name__, "ComplexTypeMeta")
-if __name__ == '__main__':
-    unittest.main()

tests/test_xmltypes_complex.py

 # Licensed under GPLv3 or later, see the COPYING file.
 
 import sys
-for x in sys.path:
-    if x.find("osa") != -1:
-        sys.path.remove(x)
-sys.path.append("../")
-
+sys.path.insert(0, "../")
+from osa.xmltypes import *
+from osa.xmlnamespace import *
+from tests.base import BaseTest
+import xml.etree.cElementTree as etree
 import unittest
 
-import xml.etree.cElementTree as etree
-
-from osa.xmltypes import *
-from osa.xmlnamespace import *
 
 ns_test = 'test_namespace'
 
         element = element[0]
         element.set("{%s}type" %NS_XSI, 'Address')
 
-        XMLAny._types = {'Person':Person, 'Address':Address, 'Level4':Level4,
-                        'Level3':Level3, 'Level2': Level2, 'Level1':Level1}
+        XMLAny._types.update({'Person':Person, 'Address':Address,
+                              'Level4':Level4, 'Level3':Level3,
+                              'Level2': Level2, 'Level1':Level1})
 
         r = XMLAny().from_xml(element)
         self.assertTrue(isinstance(r, Address))
         b = Address.from_file(fname)
         self.assertEqual(b, a)
         self.assertTrue(b is not a)
-
-if __name__ == '__main__':
-    unittest.main()

tests/test_xmltypes_primitive.py

 # Licensed under GPLv3 or later, see the COPYING file.
 
 import sys
-for x in sys.path:
-    if x.find("osa") != -1:
-        sys.path.remove(x)
-sys.path.append("../")
+sys.path.insert(0, "../")
+from osa.xmltypes import *
+from tests.base import BaseTest
+from datetime import datetime
+import xml.etree.cElementTree as etree
+import unittest
 
-from osa.xmltypes import *
-from datetime import datetime
-import unittest
-import xml.etree.cElementTree as etree
-
-from . import BaseTest
 
 ns_test = 'test_namespace'