From 8cf48e6702461789c9923eb7b47aefac0871a5a3 Mon Sep 17 00:00:00 2001 From: Harmen Prins Date: Thu, 12 Jun 2014 14:49:28 +0200 Subject: [PATCH] GUI more robust and tests work --- GUI/gui.py | 33 ++++++++++++++++++++------------- tests/test_gui.py | 25 ++++++++++++------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/GUI/gui.py b/GUI/gui.py index 8f40560..f0ba076 100644 --- a/GUI/gui.py +++ b/GUI/gui.py @@ -11,28 +11,37 @@ class ConfigImporter(): self.parser = ConfigParser.ConfigParser() self.parser.read(self.filename) + def load_common_attributes(self): """Loads common attributes from the initialized file.""" - return self.parser.get('GUI_Options', 'CommonParameters') + try: + return self.parser.get('GUI_Options', 'CommonParameters') + except: + return 'One, Two, Three' def load_output_types(self): """Loads output types from the initialized file.""" - return self.parser.get('GUI_Options', 'OutputTypes') + try: + return self.parser.get('GUI_Options', 'OutputTypes') + except: + return 'csv' def load_always_attributes(self): """Loads attributes that are always searched for from the initialized file.""" - return self.parser.get('GUI_Options', 'AlwaysParameters') - + try: + return self.parser.get('GUI_Options', 'AlwaysParameters') + except: + return 'Name, Weight' class GUI(): - def __init__(self, search): + def __init__(self, search, config_file='GUI/gui.cfg'): """Boots the window, configuration.""" - self.configurator = ConfigImporter('GUI/gui.cfg') + self.configurator = ConfigImporter(config_file) self.finish_with_search = False self.values = {} self.required_variables = ['substance'] self.search = search - + self.window, self.variables = self.generate_window(self.load_common_attributes(), self.load_output_types()) def load_common_attributes(self): """Calls the configuration parser for common attributes.""" @@ -147,12 +156,12 @@ class GUI(): print "No known class, {}, {}".format(name, var) self.values = values - if all([i in values.keys() for i in self.required_variables]): + if all([values.get(i)!='' for i in self.required_variables]): self.finish_with_search = True self.window.destroy() else: self.finish_with_search = False - tkMessageBox.showinfo('Not all required information was entered!') + #tkMessageBox.showinfo('Not all required information was entered!') def execute_search(self): """Calls the Fourmi crawler with the values from the GUI""" @@ -184,9 +193,7 @@ class GUI(): def run(self): """Starts the window and the search.""" - self.window, self.variables = self.generate_window(self.load_common_attributes(), self.load_output_types()) self.window.mainloop() + print self.finish_with_search if self.finish_with_search: - self.execute_search() - else: - tkMessageBox.showinfo("Notice", "No search was executed!") \ No newline at end of file + self.execute_search() \ No newline at end of file diff --git a/tests/test_gui.py b/tests/test_gui.py index afa6da9..4a9ddd2 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -6,22 +6,21 @@ class TestGUI(unittest.TestCase): def setUp(self): pass + def test_empty_attributes(self): - test_gui = gui.GUI(None) - test_gui.configurator = gui.ConfigImporter('../GUI/gui.cfg') - test_gui.window.after(10, test_gui.window.destroy) - test_gui.run() - test_gui.prepare_search() + self.test_gui = gui.GUI(None, '../GUI/gui.cfg') + self.test_gui.window.after(9, self.test_gui.prepare_search) + self.test_gui.window.after(11, self.test_gui.window.destroy) + self.test_gui.run() + def test_no_configurations(self): - test_gui = gui.GUI(None) - test_gui.configurator = gui.ConfigImporter(None) - test_gui.finish_with_search = True - - test_gui.variables= {'substance':''} - test_gui.window.after(10, test_gui.prepare_search) - test_gui.window.after(10, test_gui.window.destroy) - test_gui.run() + self.test_gui = gui.GUI(None) + self.test_gui.configurator = gui.ConfigImporter('') + self.test_gui.finish_with_search = True + self.test_gui.window.after(9, self.test_gui.prepare_search) + self.test_gui.window.after(11, self.test_gui.window.destroy) + self.test_gui.run()