Ejemplo n.º 1
0
 def test__parent__1(self):
     chp1 = parser_.Parser()
     chp2 = parser_.Parser()
     parser = parser_.Parser((chp1, chp2))
     root = parser_.RootParser((parser,))
     self.assertIs(parser.parent, root)
     self.assertIs(chp1.parent, parser)
     self.assertIs(chp2.parent, parser)
Ejemplo n.º 2
0
 def test__datamodel__1(self):
     chp1 = parser_.Parser()
     chp2 = parser_.Parser()
     parser = parser_.Parser((chp1, chp2))
     root = parser_.RootParser((parser,))
     self.assertIs(parser.datamodel, root.datamodel)
     self.assertIs(chp1.datamodel, root.datamodel)
     self.assertIs(chp2.datamodel, root.datamodel)
Ejemplo n.º 3
0
 def test__errors__1(self):
     chp1 = parser_.Parser()
     chp2 = parser_.Parser()
     parser = parser_.Parser((chp1, chp2))
     root = parser_.RootParser((parser,))
     self.assertIs(parser.errors, root.errors)
     self.assertIs(chp1.errors, root.errors)
     self.assertIs(chp2.errors, root.errors)
     self.assertIs(root.errors, root.errors)
Ejemplo n.º 4
0
 def test__root__1(self):
     chp1 = parser_.Parser()
     chp2 = parser_.Parser()
     parser = parser_.Parser((chp1, chp2))
     root = parser_.RootParser((parser,))
     self.assertIs(parser.root, root)
     self.assertIs(chp1.root, root)
     self.assertIs(chp2.root, root)
     self.assertIs(root.root, root)
Ejemplo n.º 5
0
 def test__init__2(self):
     chp1 = parser_.Parser()
     chp2 = parser_.Parser()
     root = parser_.RootParser((chp1, chp2))
     self.assertIs(root._children[0], chp1)
     self.assertIs(root._children[1], chp2)
     self.assertEqual(root._errors, [])
     self.assertFalse(root._datamodel_disabled)
     self.assertIs(chp1.parent, root)
     self.assertIs(chp2.parent, root)
Ejemplo n.º 6
0
 def test__init__2(self):
     chp1 = parser_.Parser()
     chp2 = parser_.Parser()
     parser = parser_.Parser((chp1, chp2))
     root = parser_.RootParser((parser,))
     self.assertIs(parser._children[0], chp1)
     self.assertIs(parser._children[1], chp2)
     self.assertIs(parser._parent, root)
     self.assertIs(chp1.parent, parser)
     self.assertIs(chp2.parent, parser)
     self.assertFalse(root._datamodel_disabled)
Ejemplo n.º 7
0
    def test__parse__1(self):
        parser = parser_.Parser()
        with patch.object(parser_.Parser, 'parse_before_children', return_value = False) as before, \
             patch.object(parser_.Parser, 'parse_with_children', return_value = True) as middle, \
             patch.object(parser_.Parser, 'parse_after_children', return_value = True) as after, \
             patch.object(parser_.Parser, 'table', 'mytable'), \
             patch.object(parser_.Parser, 'junctions', 'myjunctions'), \
             patch.object(parser_.Parser, 'append_record') as append, \
             patch.object(parser_.Parser, 'update_record') as update:
            parser_.Parser().parse('iter', a = 'A', b = 'B')

        before.assert_called_once_with('iter', {'a' : 'A', 'b' : 'B'})
        middle.assert_not_called()
        after.assert_not_called()
        append.assert_not_called()
        update.assert_not_called()
Ejemplo n.º 8
0
 def test__junctions__1(self):
     class MyParser(parser_.Parser):
         @property
         def endpoint(self):
             return 'xyz'
     parser = parser_.Parser()
     parent = MyParser((parser,))
     self.assertEqual(parser.junctions, ('xyz',))
Ejemplo n.º 9
0
 def test__endpoint__1(self):
     class MyParser(parser_.Parser):
         @property
         def endpoint(self):
             return 'xyz'
     parser = parser_.Parser()
     parent = MyParser((parser,))
     self.assertIs(parser.endpoint, parent.endpoint)
Ejemplo n.º 10
0
 def test__append_record__1(self):
     parser = parser_.Parser()
     root = parser_.RootParser((parser, ), disable_data=True)
     with patch.object(Dogs, 'append') as tab_append:
         parser.append_record({
             'name': 'Name',
             'age': 'Age'
         }, 'dogs', ('owners', ))
     tab_append.assert_not_called()
Ejemplo n.º 11
0
 def test__append_record__2(self):
     dm = DataModel()
     parser = parser_.Parser()
     root = parser_.RootParser((parser,), dm)
     with patch.object(Dogs, 'append') as tab_append, \
          patch.object(model.Junction, 'append') as rel_append:
         parser.append_record({'name' : 'Name', 'age' : 'Age', 'foo' : 'Foo'}, 'dogs', ())
     dog = model.entityclass(Dog)
     tab_append.assert_called_once_with(dog(**{'name': 'Name', 'age' : 'Age'}))
     rel_append.assert_not_called()
Ejemplo n.º 12
0
 def test__update_record__1(self):
     parser = parser_.Parser()
     root = parser_.RootParser((parser,), disable_data=True)
     with patch.object(Dogs, 'getrecord') as tab_getrecord, \
          patch.object(model.Record, 'update') as rec_update, \
          patch.object(model.Record, 'save') as rec_save:
         parser.update_record({'name' : 'Name', 'age' : 'Age'}, 'dogs', 'unimportant1', 'unimportant2')
     tab_getrecord.assert_not_called()
     rec_update.assert_not_called()
     rec_save.assert_not_called()
Ejemplo n.º 13
0
 def test__update_record__2(self):
     dm = DataModel()
     parser = parser_.Parser()
     root = parser_.RootParser((parser,), dm)
     record = model.recordclass(Dog)(('Goofy', '14'), dm.tables['dogs'])
     with patch.object(Dogs, 'getrecord', return_value=record) as tab_getrecord, \
          patch.object(model.Record, 'update', side_effect=record.update) as rec_update, \
          patch.object(model.Record, 'save') as rec_save:
         parser.update_record({'name' : 'Name', 'age' : 'Age', 'foo' : 'Foo'}, 'dogs', 12, True)
     tab_getrecord.assert_called_once_with(12)
     rec_update.assert_called_once_with({'name':'Name', 'age':'Age'})
     rec_save.assert_called_once_with()
Ejemplo n.º 14
0
 def test__append_record__4(self):
     dm = DataModel()
     dog = model.entityclass(Dog)
     person = model.entityclass(Person)
     dm.tables['persons'].append(person(**{'name':'John', 'surname':'Smith'}))
     parser = parser_.Parser()
     root = parser_.RootParser((parser,), dm)
     with patch.object(Dogs, 'append', return_value=1) as tab_append, \
          patch.object(model.Junction, 'append') as rel_append:
         parser.append_record({'name' : 'Name', 'age' : 'Age', 'foo' : 'Foo'}, 'dogs', (dm.tables['dogs'].relations['owners'],))
     tab_append.assert_called_once_with(dog(**{'name': 'Name', 'age' : 'Age'}))
     rel_append.assert_called_once_with(model.Pair(1,0))
Ejemplo n.º 15
0
 def test__children__setter__1(self):
     parser = parser_.Parser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         parser.children = (parser_.Parser(),)
Ejemplo n.º 16
0
 def test__children__1(self):
     chp1 = parser_.Parser()
     chp2 = parser_.Parser()
     parser = parser_.Parser((chp1, chp2))
     self.assertIs(parser.children[0], chp1)
     self.assertIs(parser.children[1], chp2)
Ejemplo n.º 17
0
 def test__datamodel_disabled__setter__1(self):
     parser = parser_.Parser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         parser.datamodel_disabled = True
Ejemplo n.º 18
0
 def test__parent_setter__1(self):
     chp = parser_.Parser()
     parser = parser_.Parser()
     chp.parent = parser
     self.assertIs(chp.parent, parser)
Ejemplo n.º 19
0
 def test__errors__setter__1(self):
     parser = parser_.Parser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         parser.errors = True
Ejemplo n.º 20
0
 def test__table__1(self):
     parser = parser_.Parser()
     self.assertIsNone(parser.table)
Ejemplo n.º 21
0
 def test__init__1(self):
     parser = parser_.Parser()
     with self.assertRaises(AttributeError):
         parser._parent
     self.assertEqual(parser._children, ())
Ejemplo n.º 22
0
 def test__endpoint__setter__1(self):
     parser = parser_.Parser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         parser.endpoint = 'foo'
Ejemplo n.º 23
0
 def test__junctions__setter__1(self):
     parser = parser_.Parser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         parser.junctions = 'foo'
Ejemplo n.º 24
0
 def test__parse_after_children__1(self):
     self.assertTrue(parser_.Parser().parse_after_children('iter', 'kw'))
Ejemplo n.º 25
0
 def test__datamodel__setter__1(self):
     parser = parser_.Parser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         parser.datamodel = datamodel_.DataModel()