diff --git a/tests/document/class_methods.py b/tests/document/class_methods.py index 2632d38f..88937ec8 100644 --- a/tests/document/class_methods.py +++ b/tests/document/class_methods.py @@ -66,7 +66,7 @@ class ClassMethodsTest(unittest.TestCase): """ collection_name = 'person' self.Person(name='Test').save() - self.assertIn(collection_name, self.db.collection_names()) + self.assertIn(collection_name, self.db.collection_names()) self.Person.drop_collection() self.assertNotIn(collection_name, self.db.collection_names()) @@ -102,16 +102,16 @@ class ClassMethodsTest(unittest.TestCase): BlogPost.drop_collection() BlogPost.ensure_indexes() - self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [] }) + self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': []}) BlogPost.ensure_index(['author', 'description']) - self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [[('author', 1), ('description', 1)]] }) + self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': [[('author', 1), ('description', 1)]]}) BlogPost._get_collection().drop_index('author_1_description_1') - self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [] }) + self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': []}) BlogPost._get_collection().drop_index('author_1_title_1') - self.assertEqual(BlogPost.compare_indexes(), { 'missing': [[('author', 1), ('title', 1)]], 'extra': [] }) + self.assertEqual(BlogPost.compare_indexes(), {'missing': [[('author', 1), ('title', 1)]], 'extra': []}) def test_compare_indexes_inheritance(self): """ Ensure that the indexes are properly created and that @@ -140,16 +140,16 @@ class ClassMethodsTest(unittest.TestCase): BlogPost.ensure_indexes() BlogPostWithTags.ensure_indexes() - self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [] }) + self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': []}) BlogPostWithTags.ensure_index(['author', 'tag_list']) - self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [[('_cls', 1), ('author', 1), ('tag_list', 1)]] }) + self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': [[('_cls', 1), ('author', 1), ('tag_list', 1)]]}) BlogPostWithTags._get_collection().drop_index('_cls_1_author_1_tag_list_1') - self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [] }) + self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': []}) BlogPostWithTags._get_collection().drop_index('_cls_1_author_1_tags_1') - self.assertEqual(BlogPost.compare_indexes(), { 'missing': [[('_cls', 1), ('author', 1), ('tags', 1)]], 'extra': [] }) + self.assertEqual(BlogPost.compare_indexes(), {'missing': [[('_cls', 1), ('author', 1), ('tags', 1)]], 'extra': []}) def test_compare_indexes_multiple_subclasses(self): """ Ensure that compare_indexes behaves correctly if called from a @@ -184,9 +184,9 @@ class ClassMethodsTest(unittest.TestCase): BlogPostWithTags.ensure_indexes() BlogPostWithCustomField.ensure_indexes() - self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [] }) - self.assertEqual(BlogPostWithTags.compare_indexes(), { 'missing': [], 'extra': [] }) - self.assertEqual(BlogPostWithCustomField.compare_indexes(), { 'missing': [], 'extra': [] }) + self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': []}) + self.assertEqual(BlogPostWithTags.compare_indexes(), {'missing': [], 'extra': []}) + self.assertEqual(BlogPostWithCustomField.compare_indexes(), {'missing': [], 'extra': []}) @requires_mongodb_gte_26 def test_compare_indexes_for_text_indexes(self): diff --git a/tests/document/delta.py b/tests/document/delta.py index 30296956..942e3a0a 100644 --- a/tests/document/delta.py +++ b/tests/document/delta.py @@ -863,5 +863,6 @@ class DeltaTest(unittest.TestCase): self.assertEqual('oops', delta[0]["users.007.rolist"][0]["type"]) self.assertEqual(uinfo.id, delta[0]["users.007.info"]) + if __name__ == '__main__': unittest.main() diff --git a/tests/document/json_serialisation.py b/tests/document/json_serialisation.py index 110f1e14..7c785ab2 100644 --- a/tests/document/json_serialisation.py +++ b/tests/document/json_serialisation.py @@ -32,12 +32,12 @@ class TestJson(unittest.TestCase): string = StringField(db_field='s') embedded = EmbeddedDocumentField(Embedded, db_field='e') - doc = Doc( string="Hello", embedded=Embedded(string="Inner Hello")) - doc_json = doc.to_json(sort_keys=True, use_db_field=False,separators=(',', ':')) + doc = Doc(string="Hello", embedded=Embedded(string="Inner Hello")) + doc_json = doc.to_json(sort_keys=True, use_db_field=False, separators=(',', ':')) expected_json = """{"embedded":{"string":"Inner Hello"},"string":"Hello"}""" - self.assertEqual( doc_json, expected_json) + self.assertEqual(doc_json, expected_json) def test_json_simple(self): diff --git a/tests/fields/file_tests.py b/tests/fields/file_tests.py index 213e889c..76e20bb9 100644 --- a/tests/fields/file_tests.py +++ b/tests/fields/file_tests.py @@ -578,5 +578,6 @@ class FileTest(MongoDBTestCase): self.assertEqual(marmot.photos[0].foo, 'bar') self.assertEqual(marmot.photos[0].get().length, 8313) + if __name__ == '__main__': unittest.main() diff --git a/tests/fixtures.py b/tests/fixtures.py index d8eb8487..b8303b99 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -48,6 +48,7 @@ class PickleSignalsTest(Document): def post_delete(self, sender, document, **kwargs): pickled = pickle.dumps(document) + signals.post_save.connect(PickleSignalsTest.post_save, sender=PickleSignalsTest) signals.post_delete.connect(PickleSignalsTest.post_delete, sender=PickleSignalsTest) diff --git a/tests/queryset/field_list.py b/tests/queryset/field_list.py index b111238a..250e2601 100644 --- a/tests/queryset/field_list.py +++ b/tests/queryset/field_list.py @@ -208,7 +208,7 @@ class OnlyExcludeAllTest(unittest.TestCase): BlogPost.drop_collection() - post = BlogPost(content='Had a good coffee today...', various={'test_dynamic':{'some': True}}) + post = BlogPost(content='Had a good coffee today...', various={'test_dynamic': {'some': True}}) post.author = User(name='Test User') post.comments = [Comment(title='I aggree', text='Great post!'), Comment(title='Coffee', text='I hate coffee')] post.save() @@ -413,7 +413,6 @@ class OnlyExcludeAllTest(unittest.TestCase): numbers = Numbers.objects.fields(embedded__n={"$slice": [-5, 10]}).get() self.assertEqual(numbers.embedded.n, [-5, -4, -3, -2, -1]) - def test_exclude_from_subclasses_docs(self): class Base(Document): @@ -436,5 +435,6 @@ class OnlyExcludeAllTest(unittest.TestCase): self.assertRaises(LookUpError, Base.objects.exclude, "made_up") + if __name__ == '__main__': unittest.main() diff --git a/tests/queryset/geo.py b/tests/queryset/geo.py index fd8c9b0f..240a94ab 100644 --- a/tests/queryset/geo.py +++ b/tests/queryset/geo.py @@ -534,11 +534,11 @@ class GeoQueriesTest(MongoDBTestCase): Location.drop_collection() - Location(loc=[1,2]).save() + Location(loc=[1, 2]).save() loc = Location.objects.as_pymongo()[0] self.assertEqual(loc["loc"], {"type": "Point", "coordinates": [1, 2]}) - Location.objects.update(set__loc=[2,1]) + Location.objects.update(set__loc=[2, 1]) loc = Location.objects.as_pymongo()[0] self.assertEqual(loc["loc"], {"type": "Point", "coordinates": [2, 1]}) diff --git a/tests/queryset/pickable.py b/tests/queryset/pickable.py index d96e7dc6..bf7bb31c 100644 --- a/tests/queryset/pickable.py +++ b/tests/queryset/pickable.py @@ -6,10 +6,12 @@ from mongoengine.connection import connect __author__ = 'stas' + class Person(Document): name = StringField() age = IntField() + class TestQuerysetPickable(unittest.TestCase): """ Test for adding pickling support for QuerySet instances @@ -18,7 +20,7 @@ class TestQuerysetPickable(unittest.TestCase): def setUp(self): super(TestQuerysetPickable, self).setUp() - connection = connect(db="test") #type: pymongo.mongo_client.MongoClient + connection = connect(db="test") # type: pymongo.mongo_client.MongoClient connection.drop_database("test") @@ -27,7 +29,6 @@ class TestQuerysetPickable(unittest.TestCase): age=21 ) - def test_picke_simple_qs(self): qs = Person.objects.all() @@ -46,10 +47,10 @@ class TestQuerysetPickable(unittest.TestCase): self.assertEqual(qs.count(), loadedQs.count()) - #can update loadedQs + # can update loadedQs loadedQs.update(age=23) - #check + # check self.assertEqual(Person.objects.first().age, 23) def test_pickle_support_filtration(self): @@ -70,7 +71,7 @@ class TestQuerysetPickable(unittest.TestCase): self.assertEqual(loaded.count(), 2) self.assertEqual(loaded.filter(name="Bob").first().age, 23) - + diff --git a/tests/queryset/visitor.py b/tests/queryset/visitor.py index 8261faae..22d274a8 100644 --- a/tests/queryset/visitor.py +++ b/tests/queryset/visitor.py @@ -275,7 +275,6 @@ class QTest(unittest.TestCase): with self.assertRaises(InvalidQueryError): self.Person.objects.filter('user1') - def test_q_regex(self): """Ensure that Q objects can be queried using regexes. """ diff --git a/tests/test_connection.py b/tests/test_connection.py index 88d63cdb..7c4fc4cf 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -99,11 +99,11 @@ class ConnectionTest(unittest.TestCase): conn = get_connection() self.assertIsInstance(conn, mongomock.MongoClient) - connect(host=['mongodb://localhost'], is_mock=True, alias='testdb2') + connect(host=['mongodb://localhost'], is_mock=True, alias='testdb2') conn = get_connection('testdb2') self.assertIsInstance(conn, mongomock.MongoClient) - connect(host=['localhost'], is_mock=True, alias='testdb3') + connect(host=['localhost'], is_mock=True, alias='testdb3') conn = get_connection('testdb3') self.assertIsInstance(conn, mongomock.MongoClient) @@ -111,11 +111,11 @@ class ConnectionTest(unittest.TestCase): conn = get_connection('testdb4') self.assertIsInstance(conn, mongomock.MongoClient) - connect(host=['mongodb://localhost:27017', 'mongodb://localhost:27018'], is_mock=True, alias='testdb5') + connect(host=['mongodb://localhost:27017', 'mongodb://localhost:27018'], is_mock=True, alias='testdb5') conn = get_connection('testdb5') self.assertIsInstance(conn, mongomock.MongoClient) - connect(host=['localhost:27017', 'localhost:27018'], is_mock=True, alias='testdb6') + connect(host=['localhost:27017', 'localhost:27018'], is_mock=True, alias='testdb6') conn = get_connection('testdb6') self.assertIsInstance(conn, mongomock.MongoClient) diff --git a/tests/test_context_managers.py b/tests/test_context_managers.py index 8fb7bc78..8207cd89 100644 --- a/tests/test_context_managers.py +++ b/tests/test_context_managers.py @@ -302,5 +302,6 @@ class ContextManagersTest(unittest.TestCase): _ = db.system.indexes.find_one() # queries on db.system.indexes are ignored as well self.assertEqual(q, 1) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_replicaset_connection.py b/tests/test_replicaset_connection.py index a53f5903..4aa647d6 100644 --- a/tests/test_replicaset_connection.py +++ b/tests/test_replicaset_connection.py @@ -47,5 +47,6 @@ class ConnectionTest(unittest.TestCase): self.assertEqual(conn.read_preference, READ_PREF) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_signals.py b/tests/test_signals.py index df687d0e..f3b6e33c 100644 --- a/tests/test_signals.py +++ b/tests/test_signals.py @@ -39,7 +39,6 @@ class SignalTests(unittest.TestCase): def post_init(cls, sender, document, **kwargs): signal_output.append('post_init signal, %s, document._created = %s' % (document, document._created)) - @classmethod def pre_save(cls, sender, document, **kwargs): signal_output.append('pre_save signal, %s' % document) @@ -247,7 +246,7 @@ class SignalTests(unittest.TestCase): def load_existing_author(): a = self.Author(name='Bill Shakespeare') a.save() - self.get_signal_output(lambda: None) # eliminate signal output + self.get_signal_output(lambda: None) # eliminate signal output a1 = self.Author.objects(name='Bill Shakespeare')[0] self.assertEqual(self.get_signal_output(create_author), [ @@ -431,5 +430,6 @@ class SignalTests(unittest.TestCase): {} ]) + if __name__ == '__main__': unittest.main()