Exemplo n.º 1
0
 def test_fromCartesian(self):
     """MageGroup fromCartesian should return a new MageGroup"""
     point = MagePoint([.1,.2,.3])
     l = MageList([point]*5,Color='red')
     m = MageGroup([l],Radius=0.02,Subgroup=True)
     mg = MageGroup([m])
     res = mg.toCartesian().fromCartesian()
     self.assertEqual(str(mg),str(res))
Exemplo n.º 2
0
def MageGroupFromString(line):
    """Returns a new MageGroup, created from a string representation"""
    result = MageGroup([],RecessiveOn=False) 
    trans = {'off':('Off',True),\
            'recessiveon':('RecessiveOn',True),\
            'color':'Color',\
            'radius':'Radius',\
            'nobutton':('NoButton',True),\
            'dominant':('Dominant',True),\
            'lens':('Lens',True),
            'master':'Master',\
            'instance':'Instance',\
            'clone':'Clone'}
    
    #extract all delimited fields: label & KeyWordOptions (master, etc)
    delimited_fields = []
    while 1:
        part = extract_delimited(line,'{','}')
        if part is not None:
            delimited_fields.append(part)
            line = line.replace('{'+part+'}','')
        else:
            break
    #the first one is always the label
    label = delimited_fields[0] 
    #the later ones (starting with 1) are keyword options
    field_idx = 1
    #gather all left-over pieces
    pieces = line.split()
    
    if 'sub' in pieces[0]: #@(sub)group
        result.Subgroup = True
    result.Label = label

    #process all optional pieces
    for piece in pieces[1:]:
        try:
            #here we're finding the key. The value will be '', because it
            #is stored in delimited_fields (accesible by field_idx)
            key,value = piece.split('=')
            setattr(result,trans[key],delimited_fields[field_idx])
            field_idx += 1
        except ValueError:
            setattr(result,trans[piece][0],trans[piece][1])
    return result
Exemplo n.º 3
0
 def setUp(self):
     """Define some standard lists and groups."""
     self.p1 = MagePoint([0, 1, 0], Color='green', Label='x')
     self.p0 = MagePoint([0,0,0])
     self.min_list = MageList([self.p0]*2,'y')
     self.max_list = MageList([self.p1]*5,'z',Color='blue',Off=True, \
         Style='ball')
     self.min_group = MageGroup([self.min_list], Label="min_group")
     self.max_group = MageGroup([self.min_list, self.max_list], Color='red',
                      Label="max_group", Style='dot')
     self.nested = MageGroup([self.min_group, self.max_group], Label='nest',
         Color='orange', Radius=0.3, Style='vector')
     self.empty = MageGroup(Label='empty',Color='orange', NoButton=True,
             Style='vector',RecessiveOn=False)
Exemplo n.º 4
0
class MageGroupTests(TestCase):
    """Test cases for the MageGroup class."""
    def setUp(self):
        """Define some standard lists and groups."""
        self.p1 = MagePoint([0, 1, 0], Color='green', Label='x')
        self.p0 = MagePoint([0,0,0])
        self.min_list = MageList([self.p0]*2,'y')
        self.max_list = MageList([self.p1]*5,'z',Color='blue',Off=True, \
            Style='ball')
        self.min_group = MageGroup([self.min_list], Label="min_group")
        self.max_group = MageGroup([self.min_list, self.max_list], Color='red',
                         Label="max_group", Style='dot')
        self.nested = MageGroup([self.min_group, self.max_group], Label='nest',
            Color='orange', Radius=0.3, Style='vector')
        self.empty = MageGroup(Label='empty',Color='orange', NoButton=True,
                Style='vector',RecessiveOn=False)

    def test_init(self):
        """Nested MageGroups should set subgroup and cascades correctly."""
        exp_lines = [
        '@group {nest} recessiveon',
        '@subgroup {min_group} recessiveon',
        '@vectorlist {y} color=orange radius=0.3',
        str(self.p0),
        str(self.p0),
        '@subgroup {max_group} recessiveon',
        '@dotlist {y} color=red radius=0.3',
        str(self.p0),
        str(self.p0),
        '@balllist {z} off color=blue radius=0.3',
        str(self.p1),
        str(self.p1),
        str(self.p1),
        str(self.p1),
        str(self.p1),
        ]
        s = str(self.nested).split('\n')
        self.assertEqual(str(self.nested), '\n'.join(exp_lines))
        #check that resetting the cascaded values works OK
        nested = self.nested
        str(nested)
        self.assertEqual(nested,self.nested)
        self.assertEqual(nested[0][0].Color,None)
    
    def test_str(self):
        """MageGroup str should print correctly"""
        m = self.empty
        self.assertEqual(str(self.empty),'@group {empty} nobutton')
        m = MageGroup(Label='label',Clone='clone_name',Off=True)
        self.assertEqual(str(m),
                '@group {label} off recessiveon clone={clone_name}')
        m = MageGroup()
        self.assertEqual(str(m),'@group recessiveon')
        
    def test_iterGroups(self):
        """MageGroup iterGroups should behave as expected"""
        groups = list(self.nested.iterGroups())
        self.assertEqual(groups[0],self.min_group)
        self.assertEqual(groups[1],self.max_group)
        self.assertEqual(len(groups),2)

    def test_iterLists(self):
        """MageGroup iterLists should behave as expected"""
        lists = list(self.nested.iterLists())
        self.assertEqual(len(lists),3)
        self.assertEqual(lists[0],self.min_list)
        self.assertEqual(lists[1],self.min_list)
        self.assertEqual(lists[2],self.max_list)

    def test_iterGroupsAndLists(self):
        """MageGroup iterGroupsAndLists should behave as expected"""
        all = list(self.nested.iterGroupsAndLists())
        self.assertEqual(len(all),5)
        self.assertEqual(all[0],self.min_group)
        self.assertEqual(all[4],self.max_list)

    def test_iterPoints(self):
        """MageGroup iterPoints should behave as expected"""
        points = list(self.nested.iterPoints())
        self.assertEqual(len(points),9)
        self.assertEqual(points[1],self.p0)
        self.assertEqual(points[6],self.p1)

    def test_toCartesian(self):
        """MageGroup toCartesian should return a new MageGroup"""
        m = self.nested
        res = m.toCartesian()
        self.assertEqual(len(m),len(res))
        self.assertEqual(m.RecessiveOn,res.RecessiveOn)
        self.assertEqual(m[1][1].Color, res[1][1].Color)
        self.assertEqual(res[1][1][1].Coordinates,[1,0,0])
    
    def test_fromCartesian(self):
        """MageGroup fromCartesian should return a new MageGroup"""
        point = MagePoint([.1,.2,.3])
        l = MageList([point]*5,Color='red')
        m = MageGroup([l],Radius=0.02,Subgroup=True)
        mg = MageGroup([m])
        res = mg.toCartesian().fromCartesian()
        self.assertEqual(str(mg),str(res))