示例#1
0
    def setUp(self):
        self.c1 = mngr.SubComponent(componentid="cid01", name='namec01')
        self.c2 = mngr.SubComponent(componentid="cid02", name='namec02')

        self.p1 = mngr.Package(packageid='pid01',
                               name='namep01',
                               depends=mngr.Dependencies(),
                               components=[self.c1])
        self.p2 = mngr.Package(packageid='pid02',
                               name='namep02',
                               depends=mngr.Dependencies(),
                               components=[self.c2])

        self.c3 = mngr.SubComponent(componentid='cid03', name='namec03')
        self.c4 = mngr.SubComponent(componentid='cid04',
                                    name='namec04',
                                    subcomponents=[self.c3])
        self.c5 = mngr.SubComponent(componentid='cid05',
                                    name='namec05',
                                    subcomponents=[self.c4])

        self.p3 = mngr.Package(packageid='pid03',
                               name='namep03',
                               depends=mngr.Dependencies(),
                               components=[self.c5])
示例#2
0
 def test_recursion_limit(self):
     clist = [mngr.SubComponent(componentid='cid00', name='name00')]
     for i in range(900):
         clist.append(
             mngr.SubComponent(componentid='cid0{}'.format(i),
                               name='name0{}'.format(i),
                               subcomponents=[clist[-1]]))
     print(*clist[-1].get_childrens())
示例#3
0
 def test_get_childrens(self):
     c1 = mngr.SubComponent(componentid='cid01', name='name01')
     c2 = mngr.SubComponent(componentid='cid02',
                            name='name02',
                            subcomponents=[c1])
     c3 = mngr.SubComponent(componentid='cid03',
                            name='name03',
                            subcomponents=[c2])
     self.assertEqual(set(c1.get_childrens()), set())
     self.assertEqual(set(c2.get_childrens()), {c1})
     self.assertEqual(set(c3.get_childrens()), {c1, c2})
示例#4
0
 def test_full_id(self):
     c1 = mngr.SubComponent(componentid='cid01', name='name01')
     c2 = mngr.SubComponent(componentid='cid02',
                            name='name02',
                            subcomponents=[c1])
     c3 = mngr.SubComponent(componentid='cid03',
                            name='name03',
                            subcomponents=[c2])
     self.assertEqual(c3.get_full_id(), 'cid03')
     self.assertEqual(c2.get_full_id(), 'cid03.cid02')
     self.assertEqual(c1.get_full_id(), 'cid03.cid02.cid01')
示例#5
0
 def test_get_parents(self):
     c1 = mngr.SubComponent(componentid='cid01', name='name01')
     c2 = mngr.SubComponent(componentid='cid02',
                            name='name02',
                            subcomponents=[c1])
     c3 = mngr.SubComponent(componentid='cid03',
                            name='name03',
                            subcomponents=[c2])
     self.assertEqual(c1.get_ancestors(), [c3, c2])
     self.assertEqual(c2.get_ancestors(), [c3])
     self.assertEqual(c3.get_ancestors(), [])
示例#6
0
 def test_non_unique_parent(self):
     c1 = mngr.SubComponent(componentid='cid01',
                            name='name01',
                            subcomponents=[])
     c2 = mngr.SubComponent(componentid='cid02',
                            name='name02',
                            subcomponents=[c1])
     with self.assertRaises(mngr.NonUniqueParentException):
         c3 = mngr.SubComponent(componentid='cid03',
                                name='name03',
                                subcomponents=[c1])
示例#7
0
 def test_non_unique_id(self):
     m = mngr.Manager()
     m.add_pkg(self.p1)
     c = mngr.SubComponent(componentid="cid", name="namec")
     p = mngr.Package(packageid='pid01',
                      name='namep',
                      depends=mngr.Dependencies(),
                      components=[c])
     with self.assertRaises(mngr.NonUniqueIDException):
         m.add_pkg(p)
示例#8
0
    def test_import_export(self):
        c1 = mngr.SubComponent(componentid='cid01', name='namec01')
        p1 = mngr.Package(packageid='pid01',
                          name='namep01',
                          depends=mngr.Dependencies(),
                          components=[c1])

        c2 = mngr.SubComponent(componentid='cid02', name='namec02')
        c3 = mngr.SubComponent(componentid='cid03', name='namec03')
        c4 = mngr.SubComponent(componentid='cid04',
                               name='namec04',
                               subcomponents=[c2, c3])
        c5 = mngr.SubComponent(componentid='cid05', name='namec05')
        c6 = mngr.SubComponent(componentid='cid06',
                               name='namec06',
                               subcomponents=[c5])

        p2 = mngr.Package(packageid="pid02",
                          name="namep02",
                          depends=mngr.Dependencies(),
                          components=[c4, c6])

        pkgdict = {p1.id: p1, p2.id: p2}
        mngr.Package.save_to_json({p1.id: p1, p2.id: p2}, 'test.json')
        pkgdictexp = mngr.Package.load_from_json('test.json')
        self.assertEqual(
            {pkg.id: pkg.to_dict()
             for pkg in pkgdict.values()},
            {pkg.id: pkg.to_dict()
             for pkg in pkgdictexp.values()})
示例#9
0
 def test_to_dict_simple(self):
     c1 = mngr.SubComponent(componentid='cid01',
                            name='name01',
                            subcomponents=[],
                            depends=None)
     expected = {
         'id': 'cid01',
         'name': 'name01',
         'subcomponents': [],
         'dependencies': {
             'requirements': [],
             'conflicts': [],
             'before': [],
             'after': []
         }
     }
     self.assertEqual(c1.to_dict(), expected)
示例#10
0
    def test_to_dict_complex(self):
        c2 = mngr.SubComponent(componentid='cid02', name='name02')
        c3 = mngr.SubComponent(componentid='cid03', name='name03')
        c4 = mngr.SubComponent(componentid='cid04',
                               name='name04',
                               subcomponents=[c2, c3])
        c5 = mngr.SubComponent(componentid='cid05', name='name05')
        c6 = mngr.SubComponent(componentid='cid06',
                               name='name06',
                               subcomponents=[c5])
        c7 = mngr.SubComponent(componentid='cid07',
                               name='name07',
                               subcomponents=[c4, c6])

        expected = {
            'id':
            "cid07",
            'name':
            "name07",
            'subcomponents': [{
                'id':
                'cid04',
                'name':
                'name04',
                'subcomponents': [{
                    'id': 'cid02',
                    'name': 'name02',
                    'subcomponents': [],
                    'dependencies': {
                        'requirements': [],
                        'conflicts': [],
                        'before': [],
                        'after': []
                    }
                }, {
                    'id': 'cid03',
                    'name': 'name03',
                    'subcomponents': [],
                    'dependencies': {
                        'requirements': [],
                        'conflicts': [],
                        'before': [],
                        'after': []
                    }
                }],
                'dependencies': {
                    'requirements': [],
                    'conflicts': [],
                    'before': [],
                    'after': []
                }
            }, {
                'id':
                'cid06',
                'name':
                'name06',
                'subcomponents': [{
                    'id': 'cid05',
                    'name': 'name05',
                    'subcomponents': [],
                    'dependencies': {
                        'requirements': [],
                        'conflicts': [],
                        'before': [],
                        'after': []
                    }
                }],
                'dependencies': {
                    'requirements': [],
                    'conflicts': [],
                    'before': [],
                    'after': []
                }
            }],
            'dependencies': {
                'requirements': [],
                'conflicts': [],
                'before': [],
                'after': []
            }
        }
        self.assertEqual(c7.to_dict(), expected)