remove extra comments, stub in mock test.

This commit is contained in:
chris t 2020-07-28 21:03:41 -07:00
parent b9b286b379
commit 4c0b082f2b
2 changed files with 15 additions and 5 deletions

View File

@ -198,21 +198,23 @@ def init_base(new_base):
del new_ns['__dict__'] del new_ns['__dict__']
new_ns = type(name, (new_base,), new_ns) new_ns = type(name, (new_base,), new_ns)
globals()[name] = new_ns globals()[name] = new_ns
return {name: new_ns}
ret = {}
for c in ['Tag', 'TagAssociation', 'Taggable']: for c in ['Tag', 'TagAssociation', 'Taggable']:
init_cls(c, new_base) ret.update(init_cls(c, new_base))
globals()['Base'] = new_base globals()['Base'] = new_base
# these are here because "Tag" needs to exist before adding the # these are here because "Tag" needs to exist before adding the
# listener. # listener.
sa.event.listen(Tag, 'before_insert', delete_before_insert) sa.event.listen(Tag, 'before_insert', delete_before_insert)
sa.event.listen(sa.orm.session.Session, 'before_flush', sa.event.listen(sa.orm.session.Session, 'before_flush',
enforce_unique_text) enforce_unique_text)
# need to return new types so that the caller can incorporate them # need to return new types so that the caller can incorporate them
# into its view of the module. # into its view of the module.
return {'Tag': globals()['Tag'], return ret
'TagAssociation': globals()['TagAssociation'],
'Taggable': globals()['Taggable']}
def delete_before_insert(mapper, conn, target): def delete_before_insert(mapper, conn, target):

View File

@ -2,6 +2,7 @@
from __future__ import print_function from __future__ import print_function
import mock
import pandas as pd import pandas as pd
import pprint import pprint
import sqlalchemy as sa import sqlalchemy as sa
@ -88,7 +89,6 @@ class ks_basic(unittest.TestCase):
ts = self.session.query(kk.Tag).all() ts = self.session.query(kk.Tag).all()
self.assertEqual(1, len(ts)) self.assertEqual(1, len(ts))
def test_collection(self): def test_collection(self):
"""Test access to the collection of objects associated with a """Test access to the collection of objects associated with a
tag.""" tag."""
@ -370,3 +370,11 @@ class ks_basic(unittest.TestCase):
# TODO test class inheritance. should work in simple cases. . # TODO test class inheritance. should work in simple cases. .
# . somewhat difficult, possibly infeasible in complex cases. # . somewhat difficult, possibly infeasible in complex cases.
class kk_mocktest(unittest.TestCase):
"""Make sure mocking works as expected."""
@mock.patch('libkosokoso.Tag', autospec=True)
def test_tag_mock(self, tag_mock):
t1 = kk.Tag()
self.assertIsInstance(t1, mock.NonCallableMagicMock)