Beispiel #1
0
 def test_compile_protocol(self):
     #  Try compiling from filename
     out1 = tempfile.TemporaryFile()
     extprot.compile_protocol(pfile,out1)
     out1.seek(0)
     out1 = out1.read().strip()
     #  Try compiling from filelike object
     out2 = tempfile.TemporaryFile()
     extprot.compile_protocol(open(pfile),out2)
     out2.seek(0)
     out2 = out2.read().strip()
     #  Try compiling from string
     out3 = extprot.compile_protocol_string(open(pfile).read()).strip()
     #  Should all give the same result
     self.assertEquals(out1,out2)
     self.assertEquals(out1,out3)
     #  And should have certain things in them
     self.assertTrue("class person(types.Message):" in out1)
     self.assertTrue("class optional(types.Union):" in out1)
     self.assertTrue("class Set(types.Option):" in out1)
Beispiel #2
0
            assert book1 == book2

    return TestAddressBook

#  test the hard-crafted translation at the start of this file
Test_handcrafted = make_cases(**globals())
Test_handcrafted.__name__ = "Test_handcrafted"

#  test the dynamic in-memory compilation
file = path.join(path.dirname(__file__),"../../examples/address_book.proto")
dynamic = {}
extprot.import_protocol(file,dynamic)
Test_dynamic = make_cases(**dynamic)
Test_dynamic.__name__ = "Test_dynamic"

#  test the to-source-code compilation
file = path.join(path.dirname(__file__),"../../examples/address_book.proto")
compiled = {}

tdir = tempfile.mkdtemp()
try:
    modfile = path.join(tdir,"address_book.py")
    with open(modfile,"wt") as f:
        extprot.compile_protocol(file,f)
    execfile(modfile,compiled)
    Test_compiled = make_cases(**compiled)
    Test_compiled.__name__ = "Test_compiled"
finally:
    shutil.rmtree(tdir)

Beispiel #3
0
            assert doc5.dim[3][0] == 92.0
            assert not doc5.dim[3][2]
            doc5.dim[3][2].append(["ateststring"])
            assert len(doc5.dim[3][2]) == 1
            self.assertRaises(ValueError,doc5.dim[3][2].append,7)
            for d in (doc1,doc2,doc3,doc4,doc5):
                self.assertEquals(d,doc.from_string(d.to_string()))

    return Test


#  test the hard-crafted translation at the start of this file
Test_handcrafted = make_cases(**globals())

#  test the dynamic in-memory compilation
file = path.join(path.dirname(__file__),"../../examples/tst.proto")
dynamic = {}
extprot.import_protocol(file,dynamic)
Test_dynamic = make_cases(**dynamic)

#  test the to-source-code compilation
file = path.join(path.dirname(__file__),"../../examples/tst.proto")
compiled = {}
modfile = tempfile.NamedTemporaryFile()
extprot.compile_protocol(open(file),modfile)
modfile.flush()
execfile(modfile.name,compiled)
Test_compiled = make_cases(**compiled)
modfile.close()

Beispiel #4
0
            for d in (doc1, doc2, doc3, doc4, doc5):
                self.assertEquals(d, doc.from_string(d.to_string()))

    return Test


#  test the hard-crafted translation at the start of this file
Test_handcrafted = make_cases(**globals())
Test_handcrafted.__name__ = "Test_handcrafted"

#  test the dynamic in-memory compilation
file = path.join(path.dirname(__file__), "../../examples/tst.proto")
dynamic = {}
extprot.import_protocol(file, dynamic)
Test_dynamic = make_cases(**dynamic)
Test_dynamic.__name__ = "Test_dynamic"

#  test the to-source-code compilation
file = path.join(path.dirname(__file__), "../../examples/tst.proto")
compiled = {}
tdir = tempfile.mkdtemp()
try:
    modfile = path.join(tdir, "tst.py")
    with open(modfile, "wt") as f:
        extprot.compile_protocol(open(file), f)
    execfile(modfile, compiled)
    Test_compiled = make_cases(**compiled)
    Test_compiled.__name__ = "Test_compiled"
finally:
    shutil.rmtree(tdir)
Beispiel #5
0
        def test_address_book(self):
            p1 = person("Ryan",1,optional.Set("*****@*****.**"),[])
            p2 = person("Lauren",2,optional.Unset,[("123456",phone_type.Home)])
            p3 = person("Aidan",3)
            book1 = address_book([p1,p2,p3])
            book2 = address_book.from_string(book1.to_string())
            assert book1 == book2

    return TestAddressBook

#  test the hard-crafted translation at the start of this file
TestAddessBook_handcrafted = make_cases(**globals())

#  test the dynamic in-memory compilation
file = path.join(path.dirname(__file__),"../../examples/address_book.proto")
dynamic = {}
extprot.import_protocol(file,dynamic)
Test_dynamic = make_cases(**dynamic)

#  test the to-source-code compilation
file = path.join(path.dirname(__file__),"../../examples/address_book.proto")
compiled = {}
modfile = tempfile.NamedTemporaryFile()
extprot.compile_protocol(file,modfile)
modfile.flush()
execfile(modfile.name,compiled)
Test_compiled = make_cases(**compiled)
modfile.close()