Ejemplo n.º 1
0
    def test_clone_nested(self):
        s1 = Section()
        s1.x = 1
        s2 = Section()
        s2.y = 2
        a2 = api(s2)
        self.a.set('s1', s1)
        self.a.set('s2', a2)

        s_ = self.a.clone()

        compare(api(s_.s1).history(), api(s1).history())
        compare(api(s_.s2).history(), api(s2).history())

        self.assertFalse(s_.s1 is s1)
        self.assertFalse(s_.s2 is s2)
Ejemplo n.º 2
0
    def test_process_tree(self):
        call_order = []
        def action(section, api):
            call_order.append(api.get('index').value)
        a = [self.a]
        self.a.set('index', 0)
        self.a.action(action)
        for i in range(1, 8):
            si = Section()
            ai = api(si)
            ai.set('index', i)
            a.append(ai)
            ai.action(action)
            
        self.a.set('a1', a[1])
        a[1].set('a2', a[2])
        a[1].set('a3', a[3])
        self.a.set('a4', a[4])
        a[4].set('a5', a[5])
        a[5].set('a6', a[6])
        a[4].set('a7', a[7])

        self.a.process()
        
        # test leaf-first node traversal
        compare([2, 3, 1, 6, 5, 7, 4, 0], call_order)

        # test all sections are processed
        for ai in a:
            compare(True, ai.processed)
Ejemplo n.º 3
0
 def test_clone_simple(self):
     # stuff that should be cloned
     self.a._source = 'foo'
     self.a.set('x', 1)
     self.a.set('y', 1)
     self.a.set('y', 2)
     self.a.remove('z')
     def foo(): pass
     self.a.action(foo)
     s_ = self.a.clone()
     self.assertTrue(isinstance(s_, Section))
     self.assertFalse(s_ is self.section)
     
     a_ = api(s_)
     self.assertFalse(a_.processed)
     
     compare(self.a.name, a_.name)
     compare(self.a.source(), a_.source())
     compare(self.a.by_name, a_.by_name)
     self.assertFalse(self.a.by_name is a_.by_name)
     compare(self.a.by_order, a_.by_order)
     self.assertFalse(self.a.by_order is a_.by_order)
     compare(self.a.history(), a_.history())
     self.assertFalse(self.a._history is a_._history)
     compare(self.a._actions, a_._actions)
     self.assertFalse(self.a._actions is a_._actions)
Ejemplo n.º 4
0
def parse(text, source=None):
    section = Section()
    node = api(section)
    for i,line in enumerate(text.split('\n')):
        line_no = i+1
        line = line.strip()
        if not line:
            continue
        key,value = line.split(' ',1)
        node.set(key,value.strip(),'line %i of %s' % (line_no,source))
    return node
Ejemplo n.º 5
0
 def test_append_section_name(self):
     s = Section()
     self.a.append(s)
     compare(None, api(s).name)
Ejemplo n.º 6
0
 def test_append_api(self):
     expected = Section()
     a = api(expected)
     self.a.append(a)
     actual = tuple(self.a.items())[0].value
     self.assertTrue(expected is actual)
Ejemplo n.º 7
0
 def test_set_section_name(self):
     s = Section()
     self.a.set('foo', s)
     compare('foo', api(s).name)
Ejemplo n.º 8
0
 def test_set_api(self):
     s = Section()
     a = api(s)
     self.a.set('foo', a)
     self.assertTrue(self.a.get('foo').value is s)
Ejemplo n.º 9
0
 def test_section_source_default(self):
     s = Section()
     compare(api(s).source(), 'default_source')
Ejemplo n.º 10
0
 def test_section_source(self):
     s = Section(source='my source')
     compare(api(s).source(), 'my source')
Ejemplo n.º 11
0
 def test_tree(self):
     child = Section()
     self.s.child = child
     self.assertTrue(self.s.child is child)
     compare(api(child).name, 'child')
Ejemplo n.º 12
0
 def setUp(self):
     super(Base, self).setUp()
     self.s = Section()
     self.a = api(self.s)
Ejemplo n.º 13
0
 def test_not_named(self):
     s = Section()
     compare(api(s).name, None)
Ejemplo n.º 14
0
 def test_named(self):
     s = Section(name='a name')
     compare(api(s).name, 'a name')