Erik Grinaker avatar Erik Grinaker committed e0a14b9

completed ui module unit tests

Comments (0)

Files changed (3)

 	* fixed a crasher bug when undoing an entry drag/drop under
 	certain circumstances
 
+	* wrote remaining ui module unit tests
+
 2005-01-29  Erik Grinaker <erikg@codepoet.no>
 
 	* check for fd.o shared MIME utils at build-time, and avoid
 		try:
 			gtk.UIManager.add_ui_from_file(self, file)
 
-		except GError:
+		except gobject.GError:
 			raise IOError
 
 
 			if action is not None:
 				return action
 
-		else:
-			return None
-
 
 	def get_action_group(self, name):
 		"Returns the named action group"
 			if actiongroup.get_name() == name:
 				return actiongroup
 
-		else:
-			return None
-
 
 
 ##### APPLICATION COMPONENTS #####
 class EntryView(VBox):
 	"A component for displaying an entry"
 
-	def __init__(self, cfg):
+	def __init__(self, cfg = None):
 		VBox.__init__(self)
 		self.config = cfg
 		self.set_spacing(15)
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #
 
-import gobject, gtk, unittest
+import gnome, gobject, gtk, unittest
 
 from revelation import config, data, entry, ui
 
 
 
 
+class App(unittest.TestCase):
+	"App"
+
+	def test_subclass(self):
+		"App is subclass of gnome.ui.App"
+
+		self.assertEquals(isinstance(ui.App("test"), gnome.ui.App), True)
+
+
+
+class App_add_toolbar(unittest.TestCase):
+	"App.add_toolbar()"
+
+	def test_toolbar(self):
+		"App.add_toolbar() doesn't crash :)"
+
+		a = ui.App("test")
+		t = ui.Toolbar()
+		a.add_toolbar(t, "toolbar", 0, False)
+
+
+
+class App_get_title(unittest.TestCase):
+	"App.get_title()"
+
+	def test_stripname(self):
+		"App.get_title() returns title without appname"
+
+		a = ui.App("test")
+		a.set_title("testtitle")
+		self.assertEquals(a.get_title(), "testtitle")
+
+
+
+class App_run(unittest.TestCase):
+	"App.run()"
+
+	def test_mainloop(self):
+		"App.run() starts a gtk mainloop"
+
+		global foo
+		foo = False
+
+		def cb():
+			global foo
+			foo = True
+			gtk.main_quit()
+
+		a = ui.App("test")
+
+		gobject.timeout_add(100, cb)
+		a.run()
+
+		self.assertEquals(foo, True)
+		a.destroy()
+
+
+
+class App_set_title(unittest.TestCase):
+	"App.set_title()"
+
+	def test_appname(self):
+		"App.set_title() appends revelation appname to title"
+
+		a = ui.App("test")
+		a.set_title("title")
+
+		self.assertEquals(gtk.Window.get_title(a), "title - " + config.APPNAME)
+
+
+
 class Button(unittest.TestCase):
 	"Button"
 
 
 
 
+class EntryView(unittest.TestCase):
+	"EntryView"
+
+	def test_subclass(self):
+		"EntryView is subclass of gtk.VBox"
+
+		self.assertEquals(isinstance(ui.EntryView(), gtk.VBox), True)
+
+
+
+class EntryView_clear(unittest.TestCase):
+	"EntryView.clear()"
+
+	def test_children(self):
+		"EntryView.clear() empties widget contents"
+
+		v = ui.EntryView()
+
+		e = entry.GenericEntry()
+		e.name = "test"
+		e[entry.UsernameField] = "username"
+
+		v.display_entry(e)
+		v.clear()
+		self.assertEquals(len(v.get_children()), 0)
+
+
+	def test_entry(self):
+		"EntryView.clear() clears the entry attribute"
+
+		v = ui.EntryView()
+		v.display_entry(entry.GenericEntry())
+		v.clear()
+
+		self.assertEquals(v.entry, None)
+
+
+
+class EntryView_display_entry(unittest.TestCase):
+	"EntryView"
+
+	def test_display(self):
+		"EntryView.display_entry() displays entry"
+
+		v = ui.EntryView()
+
+		e = entry.GenericEntry()
+		e.name = "test"
+		e.description = "desc"
+		e[entry.UsernameField] = "username"
+
+		v.display_entry(e)
+		self.assertNotEqual(len(v.get_children()), 0)
+
+
+	def test_entry(self):
+		"EntryView.display_entry() sets entry attribute"
+
+		v = ui.EntryView()
+		e = entry.GenericEntry()
+		v.display_entry(e)
+
+		self.assertEquals(v.entry is e, True)
+
+
+
+class EntryView_display_info(unittest.TestCase):
+	"EntryView.display_info()"
+
+	def test_clear(self):	
+		"EntryView.display_info() removes the entry"
+
+		v = ui.EntryView()
+		v.display_entry(entry.GenericEntry())
+		v.display_info()
+
+		self.assertEquals(v.entry, None)
+
+
+	def test_display(self):
+		"EntryView.display_info() displays info"
+
+		v = ui.EntryView()
+		v.display_info()
+
+		self.assertNotEqual(len(v.get_children()), 0)
+
+
+
 class FileEntry(unittest.TestCase):
 	"FileEntry"
 
 
 
 
+class Searchbar(unittest.TestCase):
+	"Searchbar"
+
+	def test_subclass(self):
+		"Searchbar is subclass of gtk.Toolbar"
+
+		self.assertEquals(isinstance(ui.Searchbar(), gtk.Toolbar), True)
+
+
+
 class SpinEntry(unittest.TestCase):
 	"SpinEntry"
 
 
 
 
+class UIManager(unittest.TestCase):
+	"UIManager"
+
+	def test_subclass(self):
+		"UIManager is subclass of gtk.UIManager"
+
+		self.assertEquals(isinstance(ui.UIManager(), gtk.UIManager), True)
+
+
+
+class UIManager_add_actions_from_file(unittest.TestCase):
+	"UIManager.add_actions_from_file()"
+
+	def test_ioerror(self):
+		"UIManager.add_actions_from_file() raises IOError on file error"
+
+		self.assertRaises(IOError, ui.UIManager().add_actions_from_file, "/dummyfile123")
+
+
+
+class UIManager_add_actions_from_string(unittest.TestCase):
+	"UIManager.add_actions_from_string()"
+
+	def test_action(self):
+		"UIManager.add_actions_from_string() creates action correctly"
+
+		mgr = ui.UIManager()
+
+		mgr.add_actions_from_string("""
+<?xml version=\"1.0\" ?>
+<actions>
+	<actiongroup name=\"testgroup\">
+		<action>
+			<name>test</name>
+			<label>Just a test</label>
+			<stock>gtk-ok</stock>
+			<accel>&lt;Control&gt;O</accel>
+			<description>Test-description</description>
+		</action>
+	</actiongroup>
+</actions>
+""")
+
+		action = mgr.get_action("test")
+
+		self.assertEquals(action.get_property("name"), "test")
+		self.assertEquals(action.get_property("label"), "Just a test")
+		self.assertEquals(action.get_property("stock-id"), "gtk-ok")
+		self.assertEquals(action.get_property("tooltip"), "Test-description")
+		self.assertEquals(action.get_property("action-group").get_name(), "testgroup")
+
+
+	def test_actiongroup(self):
+		"UIManager.add_actions_from_string() creates action groups"
+
+		mgr = ui.UIManager()
+
+		mgr.add_actions_from_string("""
+<?xml version=\"1.0\" ?>
+<actions>
+	<actiongroup name=\"testgroup\">
+		<action>
+			<name>test</name>
+			<label>Just a test</label>
+			<stock>gtk-ok</stock>
+			<accel>&lt;Control&gt;O</accel>
+			<description>Test-description</description>
+		</action>
+	</actiongroup>
+</actions>
+""")
+
+		actiongroup = mgr.get_action_group("testgroup")
+		self.assertEquals(isinstance(actiongroup, gtk.ActionGroup), True)
+
+
+	def test_invalid(self):
+		"UIManager.add_actions_from_string() raises DataError on invalid data"
+
+		xml = """
+<?xml version="1.0" ?>
+<actions>
+	<dummy></dummy>
+</action>
+"""
+
+		self.assertRaises(ui.DataError, ui.UIManager().add_actions_from_string, xml)
+
+
+	def test_optional(self):
+		"UIManager.add_actions_from_string() uses optional action elements"
+
+		mgr = ui.UIManager()
+
+		mgr.add_actions_from_string("""
+<?xml version=\"1.0\" ?>
+<actions>
+	<actiongroup name=\"testgroup\">
+		<action>
+			<name>test</name>
+		</action>
+	</actiongroup>
+</actions>
+""")
+
+		action = mgr.get_action("test")
+
+		self.assertEquals(action.get_property("name"), "test")
+		self.assertEquals(action.get_property("label"), "")
+		self.assertEquals(action.get_property("stock-id"), "")
+		self.assertEquals(action.get_property("tooltip"), "")
+		self.assertEquals(action.get_property("action-group").get_name(), "testgroup")
+
+
+
+class UIManager_add_ui_from_file(unittest.TestCase):
+	"UIManager.add_ui_from_file()"
+
+	def test_ioerror(self):
+		"UIManager.add_ui_from_file() raises IOError on file error"
+
+		self.assertRaises(IOError, ui.UIManager().add_ui_from_file, "/dummyfile123")
+
+
+
+class UIManager_append_action_group(unittest.TestCase):
+	"UIManager.append_action_group()"
+
+	def test_append(self):
+		"UIManager.append_action_group() appends action group"
+
+		mgr = ui.UIManager()
+		mgr.add_actions_from_string("""
+<?xml version="1.0" ?>
+<actions>
+	<actiongroup name="testa" />
+	<actiongroup name="testb" />
+</actions>
+		""")
+
+		group = gtk.ActionGroup("testc")
+		mgr.append_action_group(group)
+
+		self.assertEquals(mgr.get_action_group("testc") is group, True)
+		self.assertEquals(mgr.get_action_groups()[2], group)
+
+
+
+class UIManager_get_action(unittest.TestCase):
+	"UIManager.get_action()"
+
+	def test_action(self):
+		"UIManager.get_action() looks up action"
+
+		mgr = ui.UIManager()
+		mgr.add_actions_from_string("""
+<?xml version="1.0" ?>
+<actions>
+	<actiongroup name="testgroup">
+		<action>
+			<name>testaction</name>
+		</action>
+	</actiongroup>
+</actions>
+		""")
+
+		action = mgr.get_action("testaction")
+		self.assertEquals(isinstance(action, gtk.Action), True)
+		self.assertEquals(action.get_property("name"), "testaction")
+
+
+	def test_none(self):
+		"UIManager.get_action() returns None if not found"
+
+		self.assertEquals(ui.UIManager().get_action("test"), None)
+
+
+
+class UIManager_get_action_group(unittest.TestCase):
+	"UIManager.get_action_group()"
+
+	def test_action(self):
+		"UIManager.get_action_group() looks up group"
+
+		mgr = ui.UIManager()
+		mgr.add_actions_from_string("""
+<?xml version="1.0" ?>
+<actions>
+	<actiongroup name="testgroup">
+		<action>
+			<name>testaction</name>
+		</action>
+	</actiongroup>
+</actions>
+		""")
+
+		group = mgr.get_action_group("testgroup")
+		self.assertEquals(isinstance(group, gtk.ActionGroup), True)
+		self.assertEquals(group.get_name(), "testgroup")
+
+
+	def test_none(self):
+		"UIManager.get_action_group() returns None if not found"
+
+		self.assertEquals(ui.UIManager().get_action_group("test"), None)
+
+
+
 class VBox(unittest.TestCase):
 	"VBox"
 
 
 
 if __name__ == "__main__":
+	gnome.init("revelation-test", "revelation-test")
 	unittest.main()
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.