From 964c660865c3c49d2355425e65fa2bd8e77377aa Mon Sep 17 00:00:00 2001 From: Simon Poirier Date: Thu, 29 Oct 2009 01:49:16 +0000 Subject: addon test+documentation+cleanup+module reloading (bug#462149) --- (limited to 'tests/addontests.py') diff --git a/tests/addontests.py b/tests/addontests.py index 24fc803..8ea49e9 100644 --- a/tests/addontests.py +++ b/tests/addontests.py @@ -19,6 +19,7 @@ import unittest from sugar.tutorius import addon, properties +import os, sys class AddonTest(unittest.TestCase): def test_create_constructor_fail(self): @@ -41,13 +42,13 @@ class AddonTest(unittest.TestCase): assert obj is not None def test_reload_addons(self): - addon._cache = None + addon.__cache__.clear() assert len(addon.list_addons()) > 0, "Addons should be reloaded upon cache clear" def test_get_addon_meta(self): - addon._cache = None + addon.__cache__.clear() meta = addon.get_addon_meta("BubbleMessage") - expected = set(['mandatory_props', 'class', 'display_name', 'name', 'type', 'icon']) + expected = set(['mandatory_props', 'class', 'display_name', 'name', 'ts', 'type', 'icon']) assert not set(meta.keys()).difference(expected), "%s == %s"%(meta.keys(), expected) def test_reverse_lookup(self): @@ -70,4 +71,21 @@ class AddonTest(unittest.TestCase): assert not attribs,\ "assignation of attribute(s) %s detected in '%s.__init__'"%(attribs, type(obj).__name__) + def test_addon_reimport(self): + obj = addon.create("BubbleMessage", message="Hi!", position=[12,31]) + mod_name = type(obj).__module__ + # alter module + type(obj).testvar = True + + # recreate without touching the module file + obj = addon.create("BubbleMessage", message="Hi!", position=[12,31]) + assert hasattr(type(obj), 'testvar') and type(obj).testvar == True + + # touch the module + os.system('touch %s'%sys.modules.get(mod_name).__file__) + obj = addon.create("BubbleMessage", message="Hi!", position=[12,31]) + mod = type(obj).__module__ + assert not hasattr(mod, 'testvar') + + -- cgit v0.9.1