Skip to content

Commit e9490f1

Browse files
committed
fix tabulate CLI test on Windows
1 parent 7676709 commit e9490f1

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

test/test_cli.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from __future__ import print_function
77
from __future__ import unicode_literals
8+
import os
89

910

1011
import subprocess
@@ -33,19 +34,31 @@ def get_stdout_and_stderr(cmd):
3334
return out
3435

3536

37+
class TemporaryTextFile(object):
38+
def __init__(self):
39+
self.tmpfile = None
40+
def __enter__(self):
41+
self.tmpfile = tempfile.NamedTemporaryFile("w+", prefix="tabulate-test-tmp-", delete=False)
42+
return self.tmpfile
43+
def __exit__(self, exc_type, exc_val, exc_tb):
44+
if self.tmpfile:
45+
self.tmpfile.close()
46+
os.unlink(self.tmpfile.name)
47+
48+
3649
def test_script_from_file_to_stdout():
3750
"""CLI: read from file, print to stdout"""
38-
with tempfile.NamedTemporaryFile("w+") as tmpfile:
51+
with TemporaryTextFile() as tmpfile:
3952
write_sample_input(tmpfile)
4053
cmd = ["python", "tabulate.py", tmpfile.name]
4154
out = get_stdout_and_stderr(cmd)
4255
expected = "\n".join([
43-
'----- ------ -------------',
44-
'Sun 696000 1.9891e+09',
45-
'Earth 6371 5973.6',
46-
'Moon 1737 73.5',
47-
'Mars 3390 641.85',
48-
'----- ------ -------------'])
56+
'----- ------ -------------',
57+
'Sun 696000 1.9891e+09',
58+
'Earth 6371 5973.6',
59+
'Moon 1737 73.5',
60+
'Mars 3390 641.85',
61+
'----- ------ -------------'])
4962
print("got: ",repr(out))
5063
print("expected:",repr(expected))
51-
assert_equal(out.rstrip(), expected.rstrip())
64+
assert_equal(out.rstrip().splitlines(), expected.rstrip().splitlines())

0 commit comments

Comments
 (0)