From 668b6a97f2355c95db0122f18088a1142a283e4e Mon Sep 17 00:00:00 2001 From: Ken Lauer Date: Mon, 31 Jul 2023 13:54:18 -0700 Subject: [PATCH] MNT: back-compat for 'pytmc template' delimiter-less filename --- pytmc/bin/template.py | 10 +++++----- pytmc/tests/test_commandline.py | 9 +++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pytmc/bin/template.py b/pytmc/bin/template.py index ea00348..4bf6236 100644 --- a/pytmc/bin/template.py +++ b/pytmc/bin/template.py @@ -729,15 +729,15 @@ def split_input_output(arg: str) -> tuple[str, str]: input_filename : str The input filename. output_filename : str - The output filename. + The output filename. Empty filename implies stdout. """ delim = ":" + num_delim = arg.count(delim) if num_delim == 0: - raise ValueError( - f"Invalid input: {arg!r} should be in the format " - f"'input_filename:output_filename'" - ) + # Without a delimiter, assume the file is the template filename + # and the user wants to write to standard output + return arg, "" if num_delim == 1: # Our job is easy in this scenario diff --git a/pytmc/tests/test_commandline.py b/pytmc/tests/test_commandline.py index 4db2bdd..9bbaa62 100644 --- a/pytmc/tests/test_commandline.py +++ b/pytmc/tests/test_commandline.py @@ -122,7 +122,12 @@ def test_template_smoke(project_filename, template): "argument, input_filename, output_filename", [ pytest.param( - "a", "", "", marks=pytest.mark.xfail(strict=True, reason="no delimiter") + "a", "a", "", + id="template-file-to-stdout" + ), + pytest.param( + "-", "-", "", + id="stdin-to-stdout", ), pytest.param( "a:b", "a", "b", @@ -157,7 +162,7 @@ def test_filename_split( ): def exists(fn: str) -> bool: - if fn == "-": + if fn in {"-", ""}: return False print("Exists?", fn, fn in {input_filename, output_filename}) return fn in {input_filename, output_filename}