Example #1
0
    def test_json_roundtrip(self):
        store = SchemaStore()
        store.add_record(namespaced_schemas.TestRecord)
        with warnings.catch_warnings(record=True) as warninglist:
            store.add_record(TestRecord)
        self.assertEquals(len(warninglist), 1)

        namespace_instance = namespaced_schemas.TestRecord(a='test')
        namespace_roundtrip = pyschema.loads(pyschema.dumps(namespace_instance), record_store=store)
        self.assertTrue(isinstance(namespace_roundtrip, namespaced_schemas.TestRecord))

        instance = TestRecord(a='test')
        roundtrip = pyschema.loads(pyschema.dumps(instance), record_store=store)
        self.assertTrue(isinstance(roundtrip, TestRecord))
Example #2
0
 def run(self):
     with self.output().open('w') as f:
         f.write(pyschema.dumps(
             InputRecord(
                 foo="yay",
                 bar=2
             )
         ))
         f.write("\n")
         f.write(pyschema.dumps(
             InputRecord(
                 foo="yay",
                 bar=3
             )
         ))
         f.write("\n")
Example #3
0
    def test_json_roundtrip(self):
        store = SchemaStore()
        store.add_record(namespaced_schemas.TestRecord)
        with warnings.catch_warnings(record=True) as warninglist:
            store.add_record(TestRecord)
        self.assertEquals(len(warninglist), 1)

        namespace_instance = namespaced_schemas.TestRecord(a='test')
        namespace_roundtrip = pyschema.loads(
            pyschema.dumps(namespace_instance), record_store=store)
        self.assertTrue(
            isinstance(namespace_roundtrip, namespaced_schemas.TestRecord))

        instance = TestRecord(a='test')
        roundtrip = pyschema.loads(pyschema.dumps(instance),
                                   record_store=store)
        self.assertTrue(isinstance(roundtrip, TestRecord))
Example #4
0
    def test_full_circle(self):
        class Foo(Record):
            bin = Bytes()

        class MyRecord(Record):
            a_string = Text()
            a_float = Float()
            record = List(SubRecord(Foo))

        rec = MyRecord(a_string=u"hej")
        rec.record = [Foo(bin="bar")]

        s = dumps(rec)
        reloaded_obj = loads(s)

        self.assertEquals(reloaded_obj.a_string, u"hej")
        self.assertTrue(reloaded_obj.a_float is None)
        self.assertTrue(reloaded_obj.record[0].bin, "bar")
Example #5
0
    def test_full_circle(self):
        class Foo(Record):
            bin = Bytes()

        class MyRecord(Record):
            a_string = Text()
            a_float = Float()
            record = List(SubRecord(Foo))

        rec = MyRecord(a_string=u"hej")
        rec.record = [Foo(bin="bar")]

        s = dumps(rec)
        reloaded_obj = loads(s)

        self.assertEquals(reloaded_obj.a_string, u"hej")
        self.assertTrue(reloaded_obj.a_float is None)
        self.assertTrue(reloaded_obj.record[0].bin, "bar")
Example #6
0
 def run(self):
     with self.output().open('w') as f:
         f.write(pyschema.dumps(InputRecord(foo="yay", bar=2)))
         f.write("\n")
         f.write(pyschema.dumps(InputRecord(foo="yay", bar=3)))
         f.write("\n")
Example #7
0
 def _roundtrip(self, schema, input_bytes, expected=None):
     record = schema()
     record._ = input_bytes
     serialized = pyschema.dumps(record, attach_schema_name=False)
     reborn = pyschema.loads(serialized, schema=schema)
     return serialized, reborn._
Example #8
0
 def _roundtrip(self, schema, input_bytes, expected=None):
     record = schema()
     record._ = input_bytes
     serialized = pyschema.dumps(record, attach_schema_name=False)
     reborn = pyschema.loads(serialized, schema=schema)
     return serialized, reborn._