From 03e7ea25fbfdfdf9c159f120327d85f196f9e932 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Sun, 5 Jan 2020 19:50:32 +0100 Subject: [PATCH] Fix tool watcher unit tests; sleep needs to happen after watching the file --- test/unit/tools/test_watcher.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/unit/tools/test_watcher.py b/test/unit/tools/test_watcher.py index 352a4a8a32c..e6eb7389ab1 100644 --- a/test/unit/tools/test_watcher.py +++ b/test/unit/tools/test_watcher.py @@ -16,15 +16,17 @@ def test_watcher(): with __test_directory() as t: tool_path = path.join(t, "test.xml") toolbox = Toolbox() - open(tool_path, "w").write("a") + with open(tool_path, "w") as f: + f.write("a") tool_watcher = watcher.get_tool_watcher(toolbox, bunch.Bunch( watch_tools=True )) tool_watcher.start() - time.sleep(1) tool_watcher.watch_file(tool_path, "cool_tool") + time.sleep(2) assert not toolbox.was_reloaded("cool_tool") - open(tool_path, "w").write("b") + with open(tool_path, "w") as f: + f.write("b") wait_for_reload(lambda: toolbox.was_reloaded("cool_tool")) tool_watcher.shutdown() assert tool_watcher.observer is None @@ -41,10 +43,12 @@ def test_tool_conf_watcher(): with __test_directory() as t: tool_conf_path = path.join(t, "test_conf.xml") - open(tool_conf_path, "w").write("a") + with open(tool_conf_path, "w", 1) as t: + t.write("a") conf_watcher.watch_file(tool_conf_path) - time.sleep(1) - open(tool_conf_path, "w").write("b") + time.sleep(2) + with open(tool_conf_path, 'wb', 0) as t: + t.write(b"b") wait_for_reload(lambda: callback.called) conf_watcher.shutdown() assert conf_watcher.thread is None