Ejemplo n.º 1
0
 def assert_serialization_works(self, scope_location,
                                json_instance_location, format):
     self.scope = SimplTypesScope(Format.JSON, scope_location)
     simpl_object = self.scope.deserialize_file(json_instance_location,
                                                format)
     serialized_original = open(json_instance_location).read()
     serialized_now = self.scope.serialize(simpl_object, format)
     self.assertTrue(serialized_original, serialized_now)
Ejemplo n.º 2
0
class TestScopesAndInstances(unittest.TestCase):
    """
        This test class tests xml and json serialization from serialized typescopes 
        and json and xml instances of objects in thoses typescopes.
    """
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def assert_serialization_works(self, scope_location,
                                   json_instance_location, format):
        self.scope = SimplTypesScope(Format.JSON, scope_location)
        simpl_object = self.scope.deserialize_file(json_instance_location,
                                                   format)
        serialized_original = open(json_instance_location).read()
        serialized_now = self.scope.serialize(simpl_object, format)
        self.assertTrue(serialized_original, serialized_now)

    def test_choice(self):
        for filename in os.listdir(scopes_and_instances_location):
            if scope_end in filename:
                scope_name = filename.split(scope_end)[0]
                print scope_name
                print scopes_and_instances_location
                scope_spot = scopes_and_instances_location + scope_name + scope_end
                print scope_spot
                instance = scopes_and_instances_location + scope_name + ".json"
                print instance
                instance_xml = scopes_and_instances_location + scope_name + ".xml"
                print instance_xml
                self.assert_serialization_works(scope_spot, instance,
                                                Format.JSON)
                self.assert_serialization_works(scope_spot, instance_xml,
                                                Format.XML)

        print "one"
        thing = True
        self.assertTrue(thing)

    def test_choice_2(self):
        print "two"
        thing = True
        self.assertTrue(thing)
class TestScopesAndInstances(unittest.TestCase):
    """
        This test class tests xml and json serialization from serialized typescopes 
        and json and xml instances of objects in thoses typescopes.
    """
    def setUp(self):
        pass

    def tearDown(self):
        pass
    
    def assert_serialization_works(self,scope_location,json_instance_location,format):
        self.scope = SimplTypesScope(Format.JSON, scope_location)
        simpl_object = self.scope.deserialize_file(json_instance_location, format)
        serialized_original = open(json_instance_location).read()
        serialized_now = self.scope.serialize(simpl_object, format)
        self.assertTrue(serialized_original, serialized_now)

    def test_choice(self):
        for filename in os.listdir (scopes_and_instances_location):
            if scope_end in filename:
                scope_name = filename.split(scope_end)[0]
                print scope_name
                print scopes_and_instances_location
                scope_spot = scopes_and_instances_location+scope_name+scope_end
                print scope_spot
                instance = scopes_and_instances_location+scope_name+".json"
                print instance
                instance_xml = scopes_and_instances_location+scope_name+".xml"
                print instance_xml
                self.assert_serialization_works(scope_spot,instance, Format.JSON)
                self.assert_serialization_works(scope_spot,instance_xml, Format.XML)
                
        print "one"
        thing = True
        self.assertTrue(thing) 

    def test_choice_2(self):
        print "two"
        thing = True
        self.assertTrue(thing)
Ejemplo n.º 4
0
class Circle(unittest.TestCase):
    '''
    classdocs
    '''

    def setUp(self):
        self.scope = SimplTypesScope(Format.JSON, "graphCollection_scope")
        self.scope.enableGraphSerialization()
        fileReader = open("graphCollection.xml", "r")
        self.pointXMLResult = fileReader.read()
        fileReader.close()
                
    def test_xml_run(self):
        simpl_object = self.scope.deserialize_file("graphCollection.xml", Format.XML)
        xmlelement = self.scope.serialize(simpl_object, Format.XML)
        print(prettify(xmlelement))
        
        expected_result = self.pointXMLResult
        print(expected_result)
        
        self.assertTrue(xmlelement, ElementTree.fromstring(expected_result))
        
    def test_json_run(self):
        simpl_object = self.scope.deserialize_file("graphCollection.json", Format.JSON)
        json_text = deserialize_from_file("graphCollection.json")
        print(json_text)
        json_element = self.scope.serialize(simpl_object, Format.JSON)
        
        print (json.dumps(json_element))
        self.assertTrue(json_text, json.dumps(json_element))
 def assert_serialization_works(self,scope_location,json_instance_location,format):
     self.scope = SimplTypesScope(Format.JSON, scope_location)
     simpl_object = self.scope.deserialize_file(json_instance_location, format)
     serialized_original = open(json_instance_location).read()
     serialized_now = self.scope.serialize(simpl_object, format)
     self.assertTrue(serialized_original, serialized_now)
Ejemplo n.º 6
0
 def setUp(self):
     self.scope = SimplTypesScope(Format.JSON, "graphCollection_scope")
     self.scope.enableGraphSerialization()
     fileReader = open("graphCollection.xml", "r")
     self.pointXMLResult = fileReader.read()
     fileReader.close()
from serializer.simpl_types_scope import SimplTypesScope
from utils.format import Format

print "Testing"

scope_location = "../test/test_scopes_and_instances/personDirectory_scope.json"

scope = SimplTypesScope(Format.JSON, scope_location)
person = scope.SimplType("Student")

person.name = "Bob"
person.stuNum = 3434#All of the different names are a little confusing, we should think about making an anatomy chart
person.arbitrary = "Bob"#will not serialize
print scope.serialize(person, Format.JSON)