Beispiel #1
0
    def test_merge_list(self):
        root = Root()
        root.merge('''
          a:
            b:
             - 1
             - 2
          c: []
        ''')

        assert root.a.b == [1, 2]

        root.c.merge(root.a.b.copy())
        root.a.b.append(3)
        assert root.a.b == [1, 2, 3]
        assert root.c == [1, 2]
Beispiel #2
0
    def test_merge_list(self):
        root = Root()
        root.merge('''
          a:
            b:
             - 1
             - 2
          c: []
        ''')

        self.assertEqual([1, 2], root.a.b)

        root.c.merge(root.a.b.copy())
        root.a.b.append(3)
        self.assertEqual([1, 2, 3], root.a.b)
        self.assertEqual([1, 2], root.c)
Beispiel #3
0
    def test_merge_deep_object(self):
        root = Root()
        root.merge('''
          a:
            b:
              c: 3
        ''')

        self.assertEqual(3, root.a.b.c)
        root.merge('''
          d:
            e: 1
        ''')

        self.assertIsInstance(root.d, Mergable)

        root.d.merge(root.a)
        self.assertEqual(3, root.d.b.c)

        root.a.b = 2
        self.assertEqual(2, root.a.b)
        self.assertEqual(3, root.d.b.c)
Beispiel #4
0
    def test_merge_deep_object(self):
        root = Root()
        root.merge('''
          a:
            b:
              c: 3
        ''')

        assert root.a.b.c == 3
        root.merge('''
          d:
            e: 1
        ''')

        assert isinstance(root.d, Mergable)

        root.d.merge(root.a)
        assert root.d.b.c == 3

        root.a.b = 2
        assert root.a.b == 2
        assert root.d.b.c == 3
Beispiel #5
0
    def test_constructor(self):
        context = dict(
            c=3
        )

        builtin = '''
          a:
            a1: 1

          b:
          - 1
          - 2
          - %(c)s
        '''

        root = Root(builtin, context)
        assert root.a.a1 == 1
        assert root.b[0] == 1
        assert root.b[1] == 2
        assert root.b[2] == 3

        root.merge('''
          a:
            a2: 2
        ''')
        assert root.a.a2 == 2

        root.a.a3 = 3
        assert root.a.a1 == 1
        assert root.a.a2 == 2
        assert root.a.a3 == 3

        root.merge('''
          b:
            - 4
        ''')
        assert root.b[0] == 4
        assert len(root.b) == 1
Beispiel #6
0
    def test_constructor(self):
        context = dict(c=3)

        builtin = '''
          a:
            a1: 1

          b:
          - 1
          - 2
          - %(c)s
        '''

        root = Root(builtin, context)
        self.assertEqual(root.a.a1, 1)
        self.assertEqual(root.b[0], 1)
        self.assertEqual(root.b[1], 2)
        self.assertEqual(root.b[2], 3)

        root.merge('''
          a:
            a2: 2
        ''')
        self.assertEqual(root.a.a2, 2)

        root.a.a3 = 3
        self.assertEqual(root.a.a1, 1)
        self.assertEqual(root.a.a2, 2)
        self.assertEqual(root.a.a3, 3)

        root.merge('''
          b:
            - 4
        ''')
        self.assertEqual(root.b[0], 4)
        self.assertEqual(1, len(root.b))
Beispiel #7
0
 def test_merge_empty_object(self):
     root = Root()
     root.merge('')
     self.assertEqual(0, len(root.keys()))
Beispiel #8
0
 def test_merge_errors(self):
     root = Root()
     with self.assertRaises(TypeError):
         root.merge(None)
Beispiel #9
0
 def test_merge_empty_object(self):
     root = Root()
     root.merge('')
     assert len(root.keys()) == 0
Beispiel #10
0
 def test_merge_errors(self):
     root = Root()
     with pytest.raises(TypeError):
         root.merge(None)