remove extra comments, stub in mock test.
This commit is contained in:
parent
b9b286b379
commit
4c0b082f2b
10
kosokoso.py
10
kosokoso.py
|
|
@ -198,21 +198,23 @@ def init_base(new_base):
|
|||
del new_ns['__dict__']
|
||||
new_ns = type(name, (new_base,), new_ns)
|
||||
globals()[name] = new_ns
|
||||
return {name: new_ns}
|
||||
|
||||
ret = {}
|
||||
for c in ['Tag', 'TagAssociation', 'Taggable']:
|
||||
init_cls(c, new_base)
|
||||
ret.update(init_cls(c, new_base))
|
||||
|
||||
globals()['Base'] = new_base
|
||||
|
||||
# these are here because "Tag" needs to exist before adding the
|
||||
# listener.
|
||||
sa.event.listen(Tag, 'before_insert', delete_before_insert)
|
||||
sa.event.listen(sa.orm.session.Session, 'before_flush',
|
||||
enforce_unique_text)
|
||||
|
||||
# need to return new types so that the caller can incorporate them
|
||||
# into its view of the module.
|
||||
return {'Tag': globals()['Tag'],
|
||||
'TagAssociation': globals()['TagAssociation'],
|
||||
'Taggable': globals()['Taggable']}
|
||||
return ret
|
||||
|
||||
|
||||
def delete_before_insert(mapper, conn, target):
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
from __future__ import print_function
|
||||
|
||||
import mock
|
||||
import pandas as pd
|
||||
import pprint
|
||||
import sqlalchemy as sa
|
||||
|
|
@ -88,7 +89,6 @@ class ks_basic(unittest.TestCase):
|
|||
ts = self.session.query(kk.Tag).all()
|
||||
self.assertEqual(1, len(ts))
|
||||
|
||||
|
||||
def test_collection(self):
|
||||
"""Test access to the collection of objects associated with a
|
||||
tag."""
|
||||
|
|
@ -370,3 +370,11 @@ class ks_basic(unittest.TestCase):
|
|||
# TODO test class inheritance. should work in simple 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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue