Esempio n. 1
0
    def test__getattr__1(self):
        class FooParser(parser_.Parser):
            def __init__(self):
                self._bar_parser = BarParser()
                super().__init__((self._bar_parser, ))

            @property
            def bar_parser(self):
                return self._bar_parser

        class BarParser(parser_.Parser):
            pass

        foo = FooParser()
        bar = foo._bar_parser
        root = parser_.RootParser((foo, ))
        self.assertIs(foo.bar_parser, bar)
        self.assertIs(root.bar_parser, bar)
        msg = '%s object has no attribute %s' % (repr(
            root.__class__.__name__), 'xyz')
        with self.assertRaisesRegex(AttributeError, msg):
            root.xyz
        msg = '%s object has no attribute %s' % (repr(
            root.__class__.__name__), 'xyz_parser')
        with self.assertRaisesRegex(AttributeError, msg):
            root.xyz_parser
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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()
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
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()
Esempio n. 9
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()
Esempio n. 10
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)
Esempio n. 11
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))
Esempio n. 12
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()
Esempio n. 13
0
 def test__datamodel__setter__1(self):
     root = parser_.RootParser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         root.datamodel = datamodel_.DataModel()
Esempio n. 14
0
 def test__junctions__1(self):
     root = parser_.RootParser()
     self.assertEqual(root.junctions, ())
Esempio n. 15
0
 def test__endpoint__setter__1(self):
     root = parser_.RootParser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         root.endpoint = 'foo'
Esempio n. 16
0
 def test__endpoint__1(self):
     root = parser_.RootParser()
     with self.assertRaises(AttributeError):
         root.endpoint
Esempio n. 17
0
 def test__table__1(self):
     root = parser_.RootParser()
     with self.assertRaises(AttributeError):
         root.table
Esempio n. 18
0
 def test__datamodel_disabled__setter__1(self):
     root = parser_.RootParser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         root.datamodel_disabled = True
Esempio n. 19
0
 def test__init__1(self):
     root = parser_.RootParser()
     self.assertEqual(root._children, ())
     self.assertEqual(root._errors, [])
     self.assertFalse(root._datamodel_disabled)
     self.assertIsInstance(root._datamodel, datamodel_.DataModel)
Esempio n. 20
0
 def test__datamodel__1(self):
     root = parser_.RootParser()
     self.assertIs(root.datamodel, root._datamodel)
Esempio n. 21
0
 def test__root__1(self):
     root = parser_.RootParser()
     self.assertIs(root.root, root)
Esempio n. 22
0
 def test__errors_setter__1(self):
     root = parser_.RootParser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         root.errors = []
Esempio n. 23
0
 def test__errors__1(self):
     root = parser_.RootParser()
     self.assertIs(root.errors, root._errors)
Esempio n. 24
0
 def test__root__setter__1(self):
     root1 = parser_.RootParser()
     root2 = parser_.RootParser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         root1.root = root2
Esempio n. 25
0
 def test__datamodel_disabled__1(self):
     root = parser_.RootParser()
     self.assertIs(root.datamodel_disabled, root._datamodel_disabled)