From 53af01c95abe622c0490b43c12439a04aa449509 Mon Sep 17 00:00:00 2001 From: Simon Poirier Date: Wed, 28 Oct 2009 06:15:15 +0000 Subject: addon test extension to check interface contraints --- (limited to 'tests') diff --git a/tests/addontests.py b/tests/addontests.py index 5fb4f61..24fc803 100644 --- a/tests/addontests.py +++ b/tests/addontests.py @@ -18,7 +18,7 @@ import unittest -from sugar.tutorius import addon +from sugar.tutorius import addon, properties class AddonTest(unittest.TestCase): def test_create_constructor_fail(self): @@ -47,4 +47,27 @@ class AddonTest(unittest.TestCase): def test_get_addon_meta(self): addon._cache = None meta = addon.get_addon_meta("BubbleMessage") - assert meta.keys() == ['mandatory_props', 'class', 'display_name', 'name', 'icon',] + expected = set(['mandatory_props', 'class', 'display_name', 'name', 'type', 'icon']) + assert not set(meta.keys()).difference(expected), "%s == %s"%(meta.keys(), expected) + + def test_reverse_lookup(self): + obj = addon.create("BubbleMessage", message="Hi!", position=[12,31]) + assert "BubbleMessage" == addon.get_name_from_type(type(obj)) + + for name in addon.list_addons(): + klass = addon.get_addon_meta(name)['class'] + assert name == addon.get_name_from_type(klass),\ + "could not reverse lookup from type '%s'"%klass.__name__ + + def test_addon_constructor(self): + for name in addon.list_addons(): + obj = addon.create(name) + # __init__ can have locals, but should not initialize attributes on + # self as non-properties attributes won't survive serialization + # through DBUS. Assignation in do() for actions or install_handlers + # for event filters is the correct way. + attribs = set(obj.__dict__.keys()).difference(obj._props.keys()+['_props', '_callback']) + assert not attribs,\ + "assignation of attribute(s) %s detected in '%s.__init__'"%(attribs, type(obj).__name__) + + -- cgit v0.9.1