Split out warning tests as they are order dependent
This commit is contained in:
@@ -37,34 +37,6 @@ class DocumentTest(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
self.Person.drop_collection()
|
||||
|
||||
def test_future_warning(self):
|
||||
"""Add FutureWarning for future allow_inhertiance default change.
|
||||
"""
|
||||
|
||||
self.warning_list = []
|
||||
showwarning_default = warnings.showwarning
|
||||
|
||||
def append_to_warning_list(message,category, *args):
|
||||
self.warning_list.append({"message":message, "category":category})
|
||||
|
||||
# add warnings to self.warning_list instead of stderr
|
||||
warnings.showwarning = append_to_warning_list
|
||||
|
||||
class SimpleBase(Document):
|
||||
a = IntField()
|
||||
|
||||
class InheritedClass(SimpleBase):
|
||||
b = IntField()
|
||||
|
||||
# restore default handling of warnings
|
||||
warnings.showwarning = showwarning_default
|
||||
|
||||
InheritedClass()
|
||||
self.assertEqual(len(self.warning_list), 1)
|
||||
warning = self.warning_list[0]
|
||||
self.assertEqual(FutureWarning, warning["category"])
|
||||
self.assertTrue("InheritedClass" in str(warning["message"]))
|
||||
|
||||
def test_drop_collection(self):
|
||||
"""Ensure that the collection may be dropped from the database.
|
||||
"""
|
||||
@@ -144,28 +116,6 @@ class DocumentTest(unittest.TestCase):
|
||||
meta = {'collection': 'wibble'}
|
||||
self.assertEqual('wibble', InheritedAbstractNamingTest._get_collection_name())
|
||||
|
||||
# set up for redirecting warnings
|
||||
self.warning_list = []
|
||||
showwarning_default = warnings.showwarning
|
||||
|
||||
def append_to_warning_list(message, category, *args):
|
||||
self.warning_list.append({'message':message, 'category':category})
|
||||
|
||||
# add warnings to self.warning_list instead of stderr
|
||||
warnings.showwarning = append_to_warning_list
|
||||
warnings.simplefilter("always")
|
||||
|
||||
class NonAbstractBase(Document):
|
||||
pass
|
||||
|
||||
class InheritedDocumentFailTest(NonAbstractBase):
|
||||
meta = {'collection': 'fail'}
|
||||
|
||||
# restore default handling of warnings
|
||||
warnings.showwarning = showwarning_default
|
||||
|
||||
self.assertTrue(issubclass(self.warning_list[0]["category"], SyntaxWarning))
|
||||
self.assertEqual('non_abstract_base', InheritedDocumentFailTest._get_collection_name())
|
||||
|
||||
# Mixin tests
|
||||
class BaseMixin(object):
|
||||
@@ -1508,40 +1458,6 @@ class DocumentTest(unittest.TestCase):
|
||||
p1.reload()
|
||||
self.assertEqual(p1.name, p.parent.name)
|
||||
|
||||
def test_cascade_warning(self):
|
||||
|
||||
self.warning_list = []
|
||||
showwarning_default = warnings.showwarning
|
||||
|
||||
def append_to_warning_list(message, category, *args):
|
||||
self.warning_list.append({"message": message,
|
||||
"category": category})
|
||||
|
||||
# add warnings to self.warning_list instead of stderr
|
||||
warnings.showwarning = append_to_warning_list
|
||||
|
||||
class Person(Document):
|
||||
name = StringField()
|
||||
parent = ReferenceField('self')
|
||||
|
||||
Person.drop_collection()
|
||||
|
||||
p1 = Person(name="Wilson Snr")
|
||||
p1.parent = None
|
||||
p1.save()
|
||||
|
||||
p2 = Person(name="Wilson Jr")
|
||||
p2.parent = p1
|
||||
p2.save()
|
||||
|
||||
# restore default handling of warnings
|
||||
warnings.showwarning = showwarning_default
|
||||
self.assertEqual(len(self.warning_list), 1)
|
||||
warning = self.warning_list[0]
|
||||
self.assertEqual(FutureWarning, warning["category"])
|
||||
self.assertTrue("Cascading saves will default to off in 0.8"
|
||||
in str(warning["message"]))
|
||||
|
||||
def test_save_cascade_kwargs(self):
|
||||
|
||||
class Person(Document):
|
||||
|
||||
Reference in New Issue
Block a user