From dcf2dd1db71a0123208a2ae55904ae78974795a4 Mon Sep 17 00:00:00 2001 From: Michal Lesiak Date: Mon, 22 May 2023 11:56:17 +0200 Subject: [PATCH] Fix writing to a file on windows --- src/dune/docker.py | 8 ++++++-- tests/common.py | 8 +++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/dune/docker.py b/src/dune/docker.py index afc18bae..30e44c36 100644 --- a/src/dune/docker.py +++ b/src/dune/docker.py @@ -99,10 +99,14 @@ def rm_file(self, file_name): self.execute_cmd(['rm', '-rf', file_name]) def write_file(self, file_name, body): - with tempfile.NamedTemporaryFile(mode='w+',) as tmp: + tmp_name = "" + with tempfile.NamedTemporaryFile(mode='w+', delete=False) as tmp: tmp.write(body) tmp.flush() - self.cp_from_host(tmp.name, file_name) + tmp_name = tmp.name + + self.cp_from_host(tmp_name, file_name) + os.unlink(tmp_name) def find_pid(self, process_name): stdout, stderr, exit_code = self.execute_cmd(['ps', 'ax']) diff --git a/tests/common.py b/tests/common.py index b7666f5c..ae265333 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1,12 +1,14 @@ - - import os +import platform # Find path for tests: TEST_PATH = os.path.dirname(os.path.abspath(__file__)) # Set path for executable: -DUNE_EXE = os.path.split(TEST_PATH)[0] + "/dune" +if platform.system() == 'Windows': + DUNE_EXE = os.path.split(TEST_PATH)[0] + "\dune.bat" +else: + DUNE_EXE = os.path.split(TEST_PATH)[0] + "/dune" print("Executable path: ", DUNE_EXE) # Default addresses