GUI more robust and tests work
This commit is contained in:
parent
9436ccbbe2
commit
8cf48e6702
25
GUI/gui.py
25
GUI/gui.py
@ -11,28 +11,37 @@ class ConfigImporter():
|
|||||||
self.parser = ConfigParser.ConfigParser()
|
self.parser = ConfigParser.ConfigParser()
|
||||||
self.parser.read(self.filename)
|
self.parser.read(self.filename)
|
||||||
|
|
||||||
|
|
||||||
def load_common_attributes(self):
|
def load_common_attributes(self):
|
||||||
"""Loads common attributes from the initialized file."""
|
"""Loads common attributes from the initialized file."""
|
||||||
|
try:
|
||||||
return self.parser.get('GUI_Options', 'CommonParameters')
|
return self.parser.get('GUI_Options', 'CommonParameters')
|
||||||
|
except:
|
||||||
|
return 'One, Two, Three'
|
||||||
|
|
||||||
def load_output_types(self):
|
def load_output_types(self):
|
||||||
"""Loads output types from the initialized file."""
|
"""Loads output types from the initialized file."""
|
||||||
|
try:
|
||||||
return self.parser.get('GUI_Options', 'OutputTypes')
|
return self.parser.get('GUI_Options', 'OutputTypes')
|
||||||
|
except:
|
||||||
|
return 'csv'
|
||||||
|
|
||||||
def load_always_attributes(self):
|
def load_always_attributes(self):
|
||||||
"""Loads attributes that are always searched for from the initialized file."""
|
"""Loads attributes that are always searched for from the initialized file."""
|
||||||
|
try:
|
||||||
return self.parser.get('GUI_Options', 'AlwaysParameters')
|
return self.parser.get('GUI_Options', 'AlwaysParameters')
|
||||||
|
except:
|
||||||
|
return 'Name, Weight'
|
||||||
|
|
||||||
class GUI():
|
class GUI():
|
||||||
def __init__(self, search):
|
def __init__(self, search, config_file='GUI/gui.cfg'):
|
||||||
"""Boots the window, configuration."""
|
"""Boots the window, configuration."""
|
||||||
self.configurator = ConfigImporter('GUI/gui.cfg')
|
self.configurator = ConfigImporter(config_file)
|
||||||
self.finish_with_search = False
|
self.finish_with_search = False
|
||||||
self.values = {}
|
self.values = {}
|
||||||
self.required_variables = ['substance']
|
self.required_variables = ['substance']
|
||||||
self.search = search
|
self.search = search
|
||||||
|
self.window, self.variables = self.generate_window(self.load_common_attributes(), self.load_output_types())
|
||||||
|
|
||||||
def load_common_attributes(self):
|
def load_common_attributes(self):
|
||||||
"""Calls the configuration parser for common attributes."""
|
"""Calls the configuration parser for common attributes."""
|
||||||
@ -147,12 +156,12 @@ class GUI():
|
|||||||
print "No known class, {}, {}".format(name, var)
|
print "No known class, {}, {}".format(name, var)
|
||||||
|
|
||||||
self.values = values
|
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.finish_with_search = True
|
||||||
self.window.destroy()
|
self.window.destroy()
|
||||||
else:
|
else:
|
||||||
self.finish_with_search = False
|
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):
|
def execute_search(self):
|
||||||
"""Calls the Fourmi crawler with the values from the GUI"""
|
"""Calls the Fourmi crawler with the values from the GUI"""
|
||||||
@ -184,9 +193,7 @@ class GUI():
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Starts the window and the search."""
|
"""Starts the window and the search."""
|
||||||
self.window, self.variables = self.generate_window(self.load_common_attributes(), self.load_output_types())
|
|
||||||
self.window.mainloop()
|
self.window.mainloop()
|
||||||
|
print self.finish_with_search
|
||||||
if self.finish_with_search:
|
if self.finish_with_search:
|
||||||
self.execute_search()
|
self.execute_search()
|
||||||
else:
|
|
||||||
tkMessageBox.showinfo("Notice", "No search was executed!")
|
|
@ -6,22 +6,21 @@ class TestGUI(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def test_empty_attributes(self):
|
def test_empty_attributes(self):
|
||||||
test_gui = gui.GUI(None)
|
self.test_gui = gui.GUI(None, '../GUI/gui.cfg')
|
||||||
test_gui.configurator = gui.ConfigImporter('../GUI/gui.cfg')
|
self.test_gui.window.after(9, self.test_gui.prepare_search)
|
||||||
test_gui.window.after(10, test_gui.window.destroy)
|
self.test_gui.window.after(11, self.test_gui.window.destroy)
|
||||||
test_gui.run()
|
self.test_gui.run()
|
||||||
test_gui.prepare_search()
|
|
||||||
|
|
||||||
def test_no_configurations(self):
|
def test_no_configurations(self):
|
||||||
test_gui = gui.GUI(None)
|
self.test_gui = gui.GUI(None)
|
||||||
test_gui.configurator = gui.ConfigImporter(None)
|
self.test_gui.configurator = gui.ConfigImporter('')
|
||||||
test_gui.finish_with_search = True
|
self.test_gui.finish_with_search = True
|
||||||
|
self.test_gui.window.after(9, self.test_gui.prepare_search)
|
||||||
test_gui.variables= {'substance':''}
|
self.test_gui.window.after(11, self.test_gui.window.destroy)
|
||||||
test_gui.window.after(10, test_gui.prepare_search)
|
self.test_gui.run()
|
||||||
test_gui.window.after(10, test_gui.window.destroy)
|
|
||||||
test_gui.run()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user