Example #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
Example #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)
Example #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)
Example #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)
Example #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()
Example #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)
Example #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)
Example #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()
Example #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()
Example #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)
Example #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))
Example #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()
Example #13
0
 def test__datamodel__setter__1(self):
     root = parser_.RootParser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         root.datamodel = datamodel_.DataModel()
Example #14
0
 def test__junctions__1(self):
     root = parser_.RootParser()
     self.assertEqual(root.junctions, ())
Example #15
0
 def test__endpoint__setter__1(self):
     root = parser_.RootParser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         root.endpoint = 'foo'
Example #16
0
 def test__endpoint__1(self):
     root = parser_.RootParser()
     with self.assertRaises(AttributeError):
         root.endpoint
Example #17
0
 def test__table__1(self):
     root = parser_.RootParser()
     with self.assertRaises(AttributeError):
         root.table
Example #18
0
 def test__datamodel_disabled__setter__1(self):
     root = parser_.RootParser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         root.datamodel_disabled = True
Example #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)
Example #20
0
 def test__datamodel__1(self):
     root = parser_.RootParser()
     self.assertIs(root.datamodel, root._datamodel)
Example #21
0
 def test__root__1(self):
     root = parser_.RootParser()
     self.assertIs(root.root, root)
Example #22
0
 def test__errors_setter__1(self):
     root = parser_.RootParser()
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         root.errors = []
Example #23
0
 def test__errors__1(self):
     root = parser_.RootParser()
     self.assertIs(root.errors, root._errors)
Example #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
Example #25
0
 def test__datamodel_disabled__1(self):
     root = parser_.RootParser()
     self.assertIs(root.datamodel_disabled, root._datamodel_disabled)