Skip to content

Commit

Permalink
fix test_cli - change script path, do not import .version if __init__…
Browse files Browse the repository at this point in the history
….py is run as a script
  • Loading branch information
astanin committed Oct 6, 2022
1 parent 4e2eeb1 commit 05e88d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion tabulate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def _is_file(f):


__all__ = ["tabulate", "tabulate_formats", "simple_separated_format"]
from .version import version as __version__ # noqa: F401
if __name__ != "__main__":
from .version import version as __version__ # noqa: F401


# minimum extra space in headers
Expand Down
21 changes: 14 additions & 7 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):

def test_script_from_stdin_to_stdout():
"""Command line utility: read from stdin, print to stdout"""
cmd = [sys.executable, "tabulate.py"]
cmd = [sys.executable, "tabulate/__init__.py"]
out = run_and_capture_stdout(cmd, input=sample_input())
expected = SAMPLE_SIMPLE_FORMAT
print("got: ", repr(out))
Expand All @@ -126,7 +126,7 @@ def test_script_from_file_to_stdout():
with TemporaryTextFile() as tmpfile:
tmpfile.write(sample_input())
tmpfile.seek(0)
cmd = [sys.executable, "tabulate.py", tmpfile.name]
cmd = [sys.executable, "tabulate/__init__.py", tmpfile.name]
out = run_and_capture_stdout(cmd)
expected = SAMPLE_SIMPLE_FORMAT
print("got: ", repr(out))
Expand All @@ -142,7 +142,7 @@ def test_script_from_file_to_file():
input_file.seek(0)
cmd = [
sys.executable,
"tabulate.py",
"tabulate/__init__.py",
"-o",
output_file.name,
input_file.name,
Expand All @@ -165,7 +165,7 @@ def test_script_from_file_to_file():
def test_script_header_option():
"""Command line utility: -1, --header option"""
for option in ["-1", "--header"]:
cmd = [sys.executable, "tabulate.py", option]
cmd = [sys.executable, "tabulate/__init__.py", option]
raw_table = sample_input(with_headers=True)
out = run_and_capture_stdout(cmd, input=raw_table)
expected = SAMPLE_SIMPLE_FORMAT_WITH_HEADERS
Expand All @@ -178,7 +178,7 @@ def test_script_header_option():
def test_script_sep_option():
"""Command line utility: -s, --sep option"""
for option in ["-s", "--sep"]:
cmd = [sys.executable, "tabulate.py", option, ","]
cmd = [sys.executable, "tabulate/__init__.py", option, ","]
raw_table = sample_input(sep=",")
out = run_and_capture_stdout(cmd, input=raw_table)
expected = SAMPLE_SIMPLE_FORMAT
Expand All @@ -190,7 +190,14 @@ def test_script_sep_option():
def test_script_floatfmt_option():
"""Command line utility: -F, --float option"""
for option in ["-F", "--float"]:
cmd = [sys.executable, "tabulate.py", option, ".1e", "--format", "grid"]
cmd = [
sys.executable,
"tabulate/__init__.py",
option,
".1e",
"--format",
"grid",
]
raw_table = sample_input()
out = run_and_capture_stdout(cmd, input=raw_table)
expected = SAMPLE_GRID_FORMAT_WITH_DOT1E_FLOATS
Expand All @@ -202,7 +209,7 @@ def test_script_floatfmt_option():
def test_script_format_option():
"""Command line utility: -f, --format option"""
for option in ["-f", "--format"]:
cmd = [sys.executable, "tabulate.py", "-1", option, "grid"]
cmd = [sys.executable, "tabulate/__init__.py", "-1", option, "grid"]
raw_table = sample_input(with_headers=True)
out = run_and_capture_stdout(cmd, input=raw_table)
expected = SAMPLE_GRID_FORMAT_WITH_HEADERS
Expand Down

0 comments on commit 05e88d2

Please sign in to comment.