Skip to content

Commit

Permalink
Use TemporaryDirectory instead of NamedTemporaryFile in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed May 12, 2024
1 parent 4c1b22d commit 94cf579
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/test___main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ def _test_cli_with_md5(url_or_id, md5, options=None):


def _test_cli_with_content(url_or_id, content):
with tempfile.NamedTemporaryFile() as f:
cmd = ["gdown", "--no-cookies", url_or_id, "-O", f.name]
# We can't use NamedTemporaryFile because Windows doesn't allow the subprocess
# to write the file created by the parent process.
with tempfile.TemporaryDirectory() as d:
file_path = os.path.join(d, "file")
cmd = ["gdown", "--no-cookies", url_or_id, "-O", file_path]
subprocess.call(cmd)
with open(f.name) as f:
with open(file_path) as f:
assert f.read() == content


Expand Down

0 comments on commit 94cf579

Please sign in to comment.