Skip to content

Commit

Permalink
Store toolbox in test_case._toolbox
Browse files Browse the repository at this point in the history
Apparently accessing double-underscore variables in threads leads
to name-mangling issues, so effectively updating test_case.__toolbox
wouldn't be reflected outside of the watcher thread.
We previously used self.app.toolbox which circumenvented
this issue.
It is possible that `check_tool_errors` / `check_no_tool_errors`
were accessing the old toolbox, unless the watching thread happened
to fire between function definition and assert, and that's probably
why increasing the number of trials had no effect.
  • Loading branch information
mvdbeek authored and nsoranzo committed Mar 4, 2019
1 parent 294c7b6 commit 999c2c0
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions test/unit/tools/test_toolbox.py
Expand Up @@ -51,11 +51,9 @@ def assert_integerated_tool_panel(self, exists=True):

@property
def toolbox(self):
if self.__toolbox is None:
self.__toolbox = SimplifiedToolBox(self)
# wire app with this new toolbox
self.app.toolbox = self.__toolbox
return self.__toolbox
if self._toolbox is None:
self.app.toolbox = self._toolbox = SimplifiedToolBox(self)
return self._toolbox

def setUp(self):
self.reindexed = False
Expand All @@ -67,7 +65,7 @@ def setUp(self):
itp_config = os.path.join(self.test_directory, "integrated_tool_panel.xml")
self.app.config.integrated_tool_panel_config = itp_config
self.app.watchers = ConfigWatchers(self.app)
self.__toolbox = None
self._toolbox = None
self.config_files = []

def _repo_install(self, changeset, config_filename=None):
Expand Down Expand Up @@ -197,7 +195,7 @@ def test_tool_reload_when_macro_is_altered(self):
macro_out.write(SIMPLE_MACRO.substitute(tool_version="3.0"))

def check_tool_macro():
tool = self.app.toolbox.get_tool("tool_with_macro")
tool = self.toolbox.get_tool("tool_with_macro")
assert tool.version == "3.0"

self._try_until_no_errors(check_tool_macro)
Expand All @@ -216,7 +214,7 @@ def test_tool_reload_for_broken_tool(self):
out.write('certainly not a valid tool')

def check_tool_errors():
tool = self.app.toolbox.get_tool("test_tool")
tool = self.toolbox.get_tool("test_tool")
assert tool is not None
assert tool.version == "1.0"
assert tool.tool_errors == 'Current on-disk tool is not valid'
Expand All @@ -227,7 +225,7 @@ def check_tool_errors():
self._init_tool(filename="simple_tool.xml", version="2.0")

def check_no_tool_errors():
tool = self.app.toolbox.get_tool("test_tool")
tool = self.toolbox.get_tool("test_tool")
assert tool is not None
assert tool.version == "2.0"
assert tool.tool_errors is None
Expand Down Expand Up @@ -562,4 +560,4 @@ def handle_panel_update(self, section_dict):

def reload_callback(test_case):
test_case.app.tool_cache.cleanup()
test_case.__toolbox = test_case.app.toolbox = SimplifiedToolBox(test_case)
test_case._toolbox = test_case.app.toolbox = SimplifiedToolBox(test_case)

0 comments on commit 999c2c0

Please sign in to comment.