def testReadFieldsFromFile(self): hin = open(os.path.join(os.path.dirname(__file__), 'fielddata'), 'r') name, field = connect.read(hin) self.assertEqual("A", name) self.assertEqual(42, field.value) name, field = connect.read(hin) self.assertEqual("B", name) self.assertEqual("Another one.", field.value) name, field = connect.read(hin) self.assertEqual("C", name) for a, b in zip(["Another one.", "Two"], field.value): self.assertEqual(a, b)
def testReadMFVec2(self): hin = StringIO.StringIO("C\x00MFVec2\x001.1\x001.2\x002.1\x002.2\n") name, field = connect.read(hin) self.assertEqual("C", name) for a, b in zip([ avango.osg.Vec2(1.1, 1.2), avango.osg.Vec2(2.1, 2.2)], field.value): self.assertAlmostEqual(a.x, b.x, self.osg_float_places) self.assertAlmostEqual(a.y, b.y, self.osg_float_places)
def testReadMFVec2(self): hin = StringIO.StringIO("C\x00MFVec2\x001.1\x001.2\x002.1\x002.2\n") name, field = connect.read(hin) self.assertEqual("C", name) for a, b in zip([avango.osg.Vec2(1.1, 1.2), avango.osg.Vec2(2.1, 2.2)], field.value): self.assertAlmostEqual(a.x, b.x, self.osg_float_places) self.assertAlmostEqual(a.y, b.y, self.osg_float_places)
def testReadSFVec4(self): hin = StringIO.StringIO("C\x00SFVec4\x001.1\x001.2\x001.3\x001.4\n") name, field = connect.read(hin) self.assertEqual("C", name) a = avango.osg.Vec4(1.1, 1.2, 1.3, 1.4) b = field.value self.assertAlmostEqual(a.x, b.x, self.osg_float_places) self.assertAlmostEqual(a.y, b.y, self.osg_float_places) self.assertAlmostEqual(a.z, b.z, self.osg_float_places) self.assertAlmostEqual(a.w, b.w, self.osg_float_places)
def testReadSFMatrix(self): hin = StringIO.StringIO("""C\x00SFMatrix\x00 \ 1.0\x000.0\x000.0\x000.0\x00 \ 0.0\x001.0\x000.0\x000.0\x00 \ 0.0\x000.0\x001.0\x000.0\x00 \ 0.0\x008.0\x0015.0\x001.0\n""") name, field = connect.read(hin) self.assertEqual("C", name) a = avango.osg.make_trans_mat(0, 8, 15) b = field.value self.assertAlmostEqual(a.get_translate().x, b.get_translate().x, self.osg_float_places) self.assertAlmostEqual(a.get_translate().y, b.get_translate().y, self.osg_float_places) self.assertAlmostEqual(a.get_translate().z, b.get_translate().z, self.osg_float_places)
def testReadMFMatrix(self): hin = StringIO.StringIO("""C\x00MFMatrix\x00 \ 1.0\x000.0\x000.0\x000.0\x00 \ 0.0\x001.0\x000.0\x000.0\x00 \ 0.0\x000.0\x001.0\x000.0\x00 \ 1.0\x002.0\x003.0\x001.0\x00 \ 1.0\x000.0\x000.0\x000.0\x00 \ 0.0\x001.0\x000.0\x000.0\x00 \ 0.0\x000.0\x001.0\x000.0\x00 \ 4.0\x005.0\x006.0\x001.0\n""") name, field = connect.read(hin) self.assertEqual("C", name) for a, b in zip([ avango.osg.make_trans_mat(1, 2, 3), avango.osg.make_trans_mat(4, 5, 6) ], field.value): self.assertAlmostEqual(a.get_translate().x, b.get_translate().x, self.osg_float_places) self.assertAlmostEqual(a.get_translate().y, b.get_translate().y, self.osg_float_places) self.assertAlmostEqual(a.get_translate().z, b.get_translate().z, self.osg_float_places)
def testReadMFInt(self): hin = StringIO.StringIO("C\x00MFInt\x000\x008\x0015\n") name, field = connect.read(hin) self.assertEqual("C", name) for a, b in zip([0, 8, 15], field.value): self.assertEqual(a, b)
def testReadSFFloat(self): hin = StringIO.StringIO("A\x00SFFloat\x001.2\n") name, field = connect.read(hin) self.assertEqual("A", name) self.assertAlmostEqual(1.2, field.value, self.osg_float_places)
def testReadSFString(self): hin = StringIO.StringIO("B\x00SFString\x00Another one.\n") name, field = connect.read(hin) self.assertEqual("B", name) self.assertEqual("Another one.", field.value)
def read_empty(): hin = StringIO.StringIO("") name, field = connect.read(hin)
def testReadMFString(self): hin = StringIO.StringIO("C\x00MFString\x00Another one.\x00Two\n") name, field = connect.read(hin) self.assertEqual("C", name) for a, b in zip(["Another one.", "Two"], field.value): self.assertEqual(a, b)
def testReadSFInt(self): hin = StringIO.StringIO("A\x00SFInt\x0042\n") name, field = connect.read(hin) self.assertEqual("A", name) self.assertEqual(42, field.value)
def testReadSFBool(self): hin = StringIO.StringIO("A\x00SFBool\x001\n") name, field = connect.read(hin) self.assertEqual("A", name) self.assertEqual(True, field.value)