Skip to content

Commit 654f8dc

Browse files
fixup! Add test for working and broken symlinks
1 parent 70d5f71 commit 654f8dc

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

Diff for: test/test_compile.py

+21-13
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,27 @@ def test_compile_with_symlink(run_command, data_dir):
178178

179179
# create a symlink to some external file and move the main .ino
180180
# contents into that to check that the symlink is actually compiled
181-
with tempfile.NamedTemporaryFile() as external:
182-
os.symlink(external.name, symlink_file)
183-
184-
with open(main_file, mode="rb+") as main:
185-
external.write(main.read())
186-
external.flush()
187-
main.truncate(0)
188-
main.flush()
189-
190-
# Build sketch for arduino:avr:uno
191-
result = run_command(["compile", "-b", fqbn, sketch_path])
192-
assert result.stderr == ""
193-
assert result.ok
181+
with tempfile.NamedTemporaryFile(delete=False) as external:
182+
try:
183+
os.symlink(external.name, symlink_file)
184+
185+
with open(main_file, mode="rb+") as main:
186+
external.write(main.read())
187+
external.flush()
188+
main.truncate(0)
189+
main.flush()
190+
191+
# Close to allow re-opening the file on Windows
192+
# See https://bugs.python.org/issue14243
193+
external.close()
194+
195+
# Build sketch for arduino:avr:uno
196+
result = run_command(["compile", "-b", fqbn, sketch_path])
197+
assert result.stderr == ""
198+
assert result.ok
199+
finally:
200+
# Explicit cleanup needed because the file is closed above
201+
os.unlink(external.name)
194202

195203
def test_broken_symlink(sketch_name, link_name, target_name, expect_error):
196204
sketch_path = os.path.join(data_dir, sketch_name)

0 commit comments

Comments
 (0)