Commits

Felipe Prenholato  committed b71d012

Better handling of files in tests, using full path instead relative path, so it
work better with any test command (nose, pytest, etc)

  • Participants
  • Parent commits 55ac7c7

Comments (0)

Files changed (7)

File 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()

File tests/test_client.py

 # for x in sys.path:
 #     if x.find("osa") != -1:
 #         sys.path.remove(x)
-# sys.path.append("../")
+sys.path.append("../")
 
 import unittest
-import xml.etree.cElementTree as etree
-from osa.client import *
+# import xml.etree.cElementTree as etree
+from osa.client import Client
 from osa.wsdl import *
 from osa.method import *
 from osa.xmltypes import *
-import sys
+from . import BaseTest
 if sys.version_info.major < 3:
     from urllib2 import urlopen, HTTPError, URLError
 else:
 test_path = os.path.abspath(os.path.dirname(__file__))
 
 
-class TestClient(unittest.TestCase):
+class TestClient(BaseTest):
 
     def setUp(self):
-        self.client = Client("%s/test.wsdl" % test_path)
+        self.client = Client(self.test_files['test.wsdl'])
 
     def tearDown(self):
         self.client = None
             self.client.service.faultyThing()
         except RuntimeError as e:
             self.assertFalse(str(e).find('4u!') == -1)
-
-
-if __name__ == '__main__':
-    unittest.main()

File 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)
+# for x in sys.path:
+#     if x.find("osa") != -1:
+#         sys.path.remove(x)
 sys.path.append("../")
 
 import unittest
 from osa.xmlparser import *
 from osa.message import *
 
-class TestMessage(unittest.TestCase):
+from . import BaseTest
+
+
+class TestMessage(BaseTest):
+
     def setUp(self):
-        root = parse_qualified_from_url("schema.xml")
+        root = parse_qualified_from_url(self.test_files["schema.xml"])
         schema = XMLSchemaParser(root)
         xtypes = schema.get_list_of_defined_types()
         self.types = XMLSchemaParser.convert_xmltypes_to_python(xtypes)
+
     def tearDown(self):
         self.types = None
+
     def test_toxml(self):
-        message = Message("{vostok}msg", [["add", self.types["{vostok}Person"]],
-                                  ["params", self.types["{vostok}Name"]],
-                                  ["params", self.types["{sever}Car"]],
-                                  ])
+        message = Message("{vostok}msg",
+                          [["add", self.types["{vostok}Person"]],
+                           ["params", self.types["{vostok}Name"]],
+                           ["params", self.types["{sever}Car"]]])
 
         #empty
         root = etree.Element("root")
         self.assertEqual(res.firstName, "kolo")
         self.assertEqual(res.lastName, "bok")
 
-
-if __name__ == '__main__':
-    unittest.main()

File tests/test_wsdl.py

 import unittest
 import xml.etree.cElementTree as etree
 from osa.wsdl import *
-from osa.method import * 
-from osa.message import * 
+from osa.method import *
+from osa.message import *
 from osa.xmltypes import *
 
 wsdl_url = 'test.wsdl'
 ns1 = "de.mpg.ipp.hgw.boz.gsoap.helloworld"
 ns2 = "de.mpg.ipp.hgw.boz.gsoap.helloworld.types"
 
+
 class TestWSDL(unittest.TestCase):
     def test_reading(self):
         w = WSDLParser(wsdl_url)

File tests/test_xmlparser.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)
+import os
+# 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
 from osa.xmlparser import *
 
-class TestXMLParser(unittest.TestCase):
+from . import BaseTest
+
+
+class TestXMLParser(BaseTest):
     def test_ns_attr_parsing(self):
-        root = parse_qualified_from_url("test.xml", attr=["a"])
+        root = parse_qualified_from_url(self.test_files["test.xml"],
+                                        attr=["a"])
         self.assertEqual(root.get("bok"), "ns:round")
         self.assertEqual(root[0].get("a"), "{39kingdom}angry")
-
-if __name__ == '__main__':
-    unittest.main()

File tests/test_xmlschema.py

 import xml.etree.cElementTree as etree
 from osa.xmlschema import *
 from osa.xmlparser import *
+from . import BaseTest
 
-class TestXMLSchema(unittest.TestCase):
+
+class TestXMLSchema(BaseTest):
     def setUp(self):
-        root = parse_qualified_from_url("schema.xml")
+        root = parse_qualified_from_url(self.test_files["schema.xml"])
         self.schema = XMLSchemaParser(root)
     def tearDown(self):
         self.schema = None

File tests/test_xmltypes_primitive.py

 import unittest
 import xml.etree.cElementTree as etree
 
+from . import BaseTest
+
 ns_test = 'test_namespace'
 
-class TestPrimitive(unittest.TestCase):
+
+class TestPrimitive(BaseTest):
+
     def test_string(self):
         s = XMLString("value")
         element = etree.Element('test')
         self.assertEqual(element.text, 'value')
         value = XMLString().from_xml(element)
         self.assertEqual(value, 'value')
-    
+
     def test_stringenumeration(self):
         XMLStringEnumeration._allowedValues = ["me", "you"]
         s1 = XMLStringEnumeration("me")
         v = inst.from_xml(element)
         self.assertEqual(v.__class__.__name__, "str")
         self.assertEqual(v, "10.0")
-
-
-
-
-
-if __name__ == '__main__':
-    unittest.main()