From 9dac068b7c163b26be1686981e2125bf8eb1955d Mon Sep 17 00:00:00 2001 From: Tomoya Tanjo Date: Sat, 21 May 2022 19:30:21 +0900 Subject: [PATCH] Print `doc` field in one line (#136) --- cwltest/__init__.py | 27 +++++++++++++++------ cwltest/tests/test-data/multi-lined-doc.yml | 15 ++++++++++++ cwltest/tests/test_multi_lined_doc.py | 20 +++++++++++++++ 3 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 cwltest/tests/test-data/multi-lined-doc.yml create mode 100644 cwltest/tests/test_multi_lined_doc.py diff --git a/cwltest/__init__.py b/cwltest/__init__.py index 9e0ec7a..b400af4 100755 --- a/cwltest/__init__.py +++ b/cwltest/__init__.py @@ -127,14 +127,20 @@ def run_test( test_number, total_tests, test.get("short_name"), - test.get("doc"), + test.get("doc", "").replace("\n", " ").strip(), suffix, ) ) else: sys.stderr.write( "%sTest [%i/%i] %s%s\n" - % (prefix, test_number, total_tests, test.get("doc"), suffix) + % ( + prefix, + test_number, + total_tests, + test.get("doc", "").replace("\n", " ").strip(), + suffix, + ) ) if verbose: sys.stderr.write(f"Running: {' '.join(test_command)}\n") @@ -174,7 +180,7 @@ def run_test( test_number, " ".join([quote(tc) for tc in test_command]), ) - _logger.error(test.get("doc")) + _logger.error(test.get("doc", "").replace("\n", " ").strip()) if err.returncode == UNSUPPORTED_FEATURE: _logger.error("Does not support required feature") else: @@ -203,7 +209,7 @@ def run_test( test_number, " ".join([quote(tc) for tc in test_command]), ) - _logger.error(test.get("doc")) + _logger.error(test.get("doc", "").replace("\n", " ").strip()) # Kill and re-communicate to get the logs and reap the child, as # instructed in the subprocess docs. if process: @@ -229,7 +235,7 @@ def run_test( test_number, " ".join([quote(tc) for tc in test_command]), ) - _logger.warning(test.get("doc")) + _logger.warning(test.get("doc", "").replace("\n", " ").strip()) _logger.warning("Returned zero but it should be non-zero") return TestResult(1, outstr, outerr, duration, args.classname) @@ -241,7 +247,7 @@ def run_test( test_number, " ".join([quote(tc) for tc in test_command]), ) - _logger.warning(test.get("doc")) + _logger.warning(test.get("doc", "").replace("\n", " ").strip()) _logger.warning("Compare failure %s", ex) fail_message = str(ex) @@ -456,10 +462,15 @@ def main(): # type: () -> int for i, t in enumerate(tests): if t.get("short_name"): print( - "[%i] %s: %s" % (i + 1, t["short_name"], t.get("doc", "").strip()) + "[%i] %s: %s" + % ( + i + 1, + t["short_name"], + t.get("doc", "").replace("\n", " ").strip(), + ) ) else: - print("[%i] %s" % (i + 1, t.get("doc", "").strip())) + print("[%i] %s" % (i + 1, t.get("doc", "").replace("\n", " ").strip())) return 0 diff --git a/cwltest/tests/test-data/multi-lined-doc.yml b/cwltest/tests/test-data/multi-lined-doc.yml new file mode 100644 index 0000000..af21928 --- /dev/null +++ b/cwltest/tests/test-data/multi-lined-doc.yml @@ -0,0 +1,15 @@ +- job: v1.0/cat-job.json + output: {} + tool: return-0.cwl + doc: | + Test with + label + label: opt-error + tags: [ js, init_work_dir ] +- job: v1.0/cat-job.json + output: {} + tool: return-0.cwl + doc: | + Test without + label + tags: [ js, init_work_dir ] diff --git a/cwltest/tests/test_multi_lined_doc.py b/cwltest/tests/test_multi_lined_doc.py new file mode 100644 index 0000000..1fa1501 --- /dev/null +++ b/cwltest/tests/test_multi_lined_doc.py @@ -0,0 +1,20 @@ +import os +from os import linesep as n +from pathlib import Path + +from .util import run_with_mock_cwl_runner, get_data +import defusedxml.ElementTree as ET + + +def test_run(): + args = ["--test", get_data("tests/test-data/multi-lined-doc.yml")] + error_code, stdout, stderr = run_with_mock_cwl_runner(args) + assert f"Test [1/2] opt-error: Test with label{n}" in stderr + assert f"Test [2/2] Test without label{n}" in stderr + + +def test_list(): + args = ["--test", get_data("tests/test-data/multi-lined-doc.yml"), "-l"] + error_code, stdout, stderr = run_with_mock_cwl_runner(args) + assert f"[1] opt-error: Test with label{n}" in stdout + assert f"[2] Test without label{n}" in stdout