From 556091c3953698c004b0873db7e126f4bae2f0bb Mon Sep 17 00:00:00 2001 From: Griatch Date: Mon, 13 Apr 2020 11:34:12 +0200 Subject: [PATCH] Add simple ContentHandler unit test --- evennia/objects/tests.py | 14 ++++++++++++++ evennia/utils/test_resources.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/evennia/objects/tests.py b/evennia/objects/tests.py index 0cacfcea89..7eb942ff1f 100644 --- a/evennia/objects/tests.py +++ b/evennia/objects/tests.py @@ -1,6 +1,7 @@ from evennia.utils.test_resources import EvenniaTest from evennia import DefaultObject, DefaultCharacter, DefaultRoom, DefaultExit from evennia.objects.models import ObjectDB +from evennia.utils import create class DefaultObjectTest(EvenniaTest): @@ -145,3 +146,16 @@ class TestObjectManager(EvenniaTest): self.assertEqual(obj2.attributes.get(key="phrase"), "xyzzy") self.assertEqual(self.obj1.attributes.get(key="phrase", category="adventure"), "plugh") self.assertEqual(obj2.attributes.get(key="phrase", category="adventure"), "plugh") + +class TestContentHandler(EvenniaTest): + "Test the ContentHandler (obj.contents)" + + def test_cache_clearing(self): + self.assertTrue(self.obj1 in self.room1.contents) + self.assertTrue(self.obj2 in self.room1.contents) + + obj3 = create.create_object(key="obj3", location=self.room1) + self.assertTrue(obj3 in self.room1.contents) + + obj3.delete() + self.assertFalse(obj3 in self.room1.contents) diff --git a/evennia/utils/test_resources.py b/evennia/utils/test_resources.py index 053541391f..d5ca8e1f32 100644 --- a/evennia/utils/test_resources.py +++ b/evennia/utils/test_resources.py @@ -38,7 +38,7 @@ def unload_module(module): an object, the module in which that object sits will be unloaded. A string should directly give the module pathname to unload. - Example: + Example: # (in a test method) unload_module(foo) with mock.patch("foo.GLOBALTHING", "mockval"):