Skip to content

Commit

Permalink
tests: fix NamedTemporaryFile usage for windows as suggested in https…
Browse files Browse the repository at this point in the history
  • Loading branch information
ikreymer committed Apr 29, 2017
1 parent a954601 commit 8d46c18
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions test/test_cli.py
Expand Up @@ -10,6 +10,7 @@
import pytest
import sys
import tempfile
import os


def test_index():
Expand Down Expand Up @@ -44,7 +45,7 @@ def test_index():


def test_recompress():
with tempfile.NamedTemporaryFile() as temp:
with named_temp() as temp:
test_file = get_test_file('example-bad-non-chunked.warc.gz')

with patch_stdout() as buff:
Expand All @@ -69,10 +70,10 @@ def test_recompress():


def test_recompress_bad_file():
with tempfile.NamedTemporaryFile() as temp:
with named_temp() as temp:
temp.write(b'abcdefg-not-a-warc\n')
temp.seek(0)
with tempfile.NamedTemporaryFile() as temp2:
with named_temp() as temp2:
with pytest.raises(ArchiveLoadFailed):
main(args=['recompress', temp.name, temp2.name])

Expand All @@ -92,3 +93,17 @@ def patch_stdout():
sys.stdout = orig


# due to NamedTemporaryFile issue on Windows
# see: https://bugs.python.org/issue14243#msg157925
@contextmanager
def named_temp():
f = tempfile.NamedTemporaryFile(delete=False)
try:
yield f

finally:
try:
os.unlink(f.name)
except OSError:
pass

0 comments on commit 8d46c18

Please sign in to comment.