Skip to content

Commit

Permalink
fixes setUpClass references; adds skip to run_script
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom O'Hara committed Feb 5, 2024
1 parent c21a7f0 commit aa2da2f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions mezcla/unittest_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def setUpClass(cls, filename=None, module=None):
"""Per-class initialization: make sure script_module set properly
Note: Optional FILENAME is path for testing script and MODULE the imported object for tested script
"""
debug.trace(6, f"TestWrapper.setupClass({cls}, fn={filename}, mod={module})")
debug.trace(6, f"TestWrapper.setUpClass({cls}, fn={filename}, mod={module})")
super().setUpClass()
cls.class_setup = True
debug.trace_object(7, cls, "TestWrapper class")
Expand Down Expand Up @@ -273,7 +273,7 @@ def get_module_file_path(test_filename):
@classmethod
def set_module_info(cls, test_filename, module_object=None):
"""Sets both script_module and script_path
Note: normally invoked in setupClass method
Note: normally invoked in setUpClass method
Usage: cls.set_module_info(__file__, THE_MODULE)
"""
debug.trace(7, f'set_module_info({test_filename}, {module_object})')
Expand All @@ -289,8 +289,8 @@ def setUp(self):
# Note: By default, each test gets its own temp file.
debug.trace(6, "TestWrapper.setUp()")
if not self.class_setup:
debug.trace(5, "Warning: invoking setupClass in setup")
TestWrapper.setupClass(self.__class__)
debug.trace(5, "Warning: invoking setUpClass in setup")
TestWrapper.setUpClass(self.__class__)
if not gh.ALLOW_SUBCOMMAND_TRACING:
gh.disable_subcommand_tracing()
# The temp file is an extension of temp-base file by default.
Expand All @@ -308,15 +308,16 @@ def setUp(self):
return

def run_script(self, options=None, data_file=None, log_file=None, trace_level=4,
out_file=None, env_options=None, uses_stdin=None, post_options=None, background=None):
out_file=None, env_options=None, uses_stdin=None, post_options=None, background=None, skip_stdin=None):
"""Runs the script over the DATA_FILE (optional), passing (positional)
OPTIONS and optional setting ENV_OPTIONS. If OUT_FILE and LOG_FILE are
not specified, they are derived from self.temp_file. The optional POST_OPTIONS
go after the data file.
Notes:
- OPTIONS uses quotes around shell special characters used (e.g., '<', '>', '|')
- issues warning if script invocation leads to error
- if USES_STDIN, requires explicit empty string for DATA_FILE to avoid use of - (n.b., as a precaution against hangups)"""
- if USES_STDIN, requires explicit empty string for DATA_FILE to avoid use of - (n.b., as a precaution against hangups)
- if """
debug.trace_fmtd(trace_level + 1,
"TestWrapper.run_script(opts={opts!r}, data={df}, log={lf}, lvl={lvl}, out={of}, env={env}, stdin={stdin}, post={post}, back={back})",
opts=options, df=data_file, lf=log_file, lvl=trace_level, of=out_file,
Expand All @@ -327,12 +328,14 @@ def run_script(self, options=None, data_file=None, log_file=None, trace_level=4,
env_options = ""
if post_options is None:
post_options = ""
if skip_stdin is None:
skip_stdin = False

# Derive the full paths for data file and log, and then invoke script.
# TODO: derive from temp base and data file name?;
# TODO1: derive default for uses_stdin based on use of filename argment (e.g., from usage)
uses_stdin_false = ((uses_stdin is not None) and not bool(uses_stdin))
data_path = ("" if uses_stdin_false else "-")
data_path = ("" if (skip_stdin or uses_stdin_false) else "-")
if data_file is not None:
data_path = (gh.resolve_path(data_file) if len(data_file) else data_file)
if not log_file:
Expand Down

0 comments on commit aa2da2f

Please sign in to comment.