예제 #1
0
 def test_fromCartesian(self):
     """MageList fromCartesian() should return new list with ACG coordinates
     """
     point = MagePoint([.1,.2,.3])
     m = MageList([point]*5,Color='green')
     res = m.toCartesian().fromCartesian()
     self.assertEqual(str(m),str(res))
예제 #2
0
 def test_toCartesian(self):
     """MageList toCartesian should return new list"""
     m = MageList([self.null],Color='green')
     res = m.toCartesian()
     self.assertEqual(len(m), len(res))
     self.assertEqual(m.Color,res.Color)
     self.assertEqual(res[0].Coordinates,[1,1,1])
     m.Color='red'
     self.assertEqual(res.Color,'green')
     m = MageList([self.properties])
     self.assertRaises(ValueError,m.toCartesian)
예제 #3
0
 def test_toArray_coords_only(self):
     """MageList toArray should return the correct array"""
     m = MageList(self.empty_list)
     self.assertEqual(m.toArray(include_radius=False),array(()))
     m = MageList(self.first_list,Radius=.3)
     self.assertEqual(m.toArray(include_radius=False),
             array([[0,0,0],[2.0,4.0,6.0]]))
     m = MageList(self.radii)
     self.assertEqual(m.toArray(include_radius=False), 
             array([[2,2,2],[3,3,3]]))
     m = MageList(self.radii,Radius=.4)
     self.assertEqual(m.toArray(include_radius=False),
             array([[2,2,2],[3,3,3]]))
     m = MageList(self.single_list) #radius = None
     self.assertEqual(m.toArray(include_radius=False),array([[1,1,1]]))
예제 #4
0
 def test_toArray_radii(self):
     """MageList toArray should return the correct array"""
     m = MageList(self.empty_list)
     self.assertEqual(m.toArray(),array(()))
     m = MageList(self.first_list,Radius=.3)
     self.assertEqual(m.toArray(),array([[0,0,0,0.3],[2.0,4.0,6.0,0.3]]))
     m = MageList(self.radii)
     self.assertEqual(m.toArray(), array([[2,2,2,.1],[3,3,3,.5]]))
     m = MageList(self.radii,Radius=.4)
     self.assertEqual(m.toArray(), array([[2,2,2,.1],[3,3,3,.5]]))
     m = MageList(self.single_list) #radius = None
     self.assertRaises(ValueError,m.toArray)
예제 #5
0
def MageListFromString(line):
    """Returns a new MageList, created from a string representation"""
    result = MageList()
    trans = {'off':('Off',True),\
            'color':'Color',\
            'radius':'Radius',\
            'nobutton':('NoButton',True),\
            'angle':'Angle',\
            'width':'Width',\
            'face':'Face',\
            'font':'Font',\
            'size':'Size'}

    line = re.sub('=\s*','=',line)
    label = extract_delimited(line, '{', '}')
    if label is not None:
        pieces = line.replace('{'+label+'}', '').split()
    else:
        pieces = line.split()
   
    style = pieces[0].strip('@')[:-4] #take off the 'list' part
    if style in MageList.KnownStyles:
        result.Style = style
    else:
        raise ValueError,"Unknown style: %s"%(style)
    result.Label = label 
    
    #process all optional pieces
    for piece in pieces[1:]:
        try:
            key,value = [item.strip() for item in piece.split('=')]
            key = trans[key]
        except ValueError: #unpack list of wrong size
            key,value = trans[piece][0],trans[piece][1]
        #KeyError will be raised in case of an unkown key
        setattr(result,key,value)
    return result
예제 #6
0
 def test_iterPoints(self):
     """MageList iterPoints should yield all points in self"""
     m = MageList(self.single_list)
     for point in m.iterPoints():
         assert isinstance(point,MagePoint)
     self.assertEqual(len(list(m.iterPoints())),1)
     m = MageList(self.multi_list)
     for point in m.iterPoints():
         assert isinstance(point,MagePoint)
     self.assertEqual(len(list(m.iterPoints())),10)