From 4c0b082f2b38d812c88b12b79cb3e1f2719077b7 Mon Sep 17 00:00:00 2001 From: chris t Date: Tue, 28 Jul 2020 21:03:41 -0700 Subject: [PATCH] remove extra comments, stub in mock test. --- kosokoso.py | 10 ++++++---- tests/test_basic.py | 10 +++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/kosokoso.py b/kosokoso.py index 9c62da6..e875728 100644 --- a/kosokoso.py +++ b/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): diff --git a/tests/test_basic.py b/tests/test_basic.py index 3541a33..d6c64f7 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -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)