def create_collection(self): collection = CPolylineCollection() p1 = CPolyline( name = "POLY1" , init_points = [(0,10) , (1,11) , (2,12)]) p2 = CPolyline( name = "POLY2" , init_points = [(0,100) , (10,110) , (20,120)]) collection.addPolyline( p1 ) collection.addPolyline( p2 ) tail = p1[-1] self.assertEqual( tail , (2,12)) self.assertEqual(p1.getName() , "POLY1") tail = p2[-1] self.assertEqual( tail , (20,120)) self.assertEqual(p2.getName() , "POLY2") return collection
def test_add_polyline(self): pc = CPolylineCollection() pl = pc.createPolyline( name = "TestP" ) self.assertTrue( isinstance(pl , CPolyline)) self.assertEqual(len(pc) , 1) self.assertTrue( "TestP" in pc ) with self.assertRaises(IndexError): pl = pc[2] p0 = pc[0] self.assertTrue( p0 == pl ) with self.assertRaises(KeyError): pn = pc["missing"] pn = pc["TestP"] self.assertTrue( pn == pl ) px = CPolyline( name = "TestP") with self.assertRaises(KeyError): pc.addPolyline( px ) self.assertEqual(len(pc) , 1) p2 = CPolyline( name = "Poly2") pc.addPolyline( p2 ) self.assertEqual( len(pc) , 2 ) self.assertTrue( "Poly2" in pc ) l = [] for p in pc: l.append(p) self.assertEqual( len(pc) , 2 ) points = [(0,1) , (1,1)] pc.addPolyline( points , name = "XYZ") self.assertTrue( "XYZ" in pc )