Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Output): use default HTML log name if '-hl' CLI parameter was last #713

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions tests/test_html_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def test_cli_log_custom_name(tmpdir):

def test_cli_log_default_name(tmpdir):
artifact_dir = check_cli(tmpdir, ["-hl"])
assert not os.path.exists(os.path.join(artifact_dir, "default"))
assert os.path.exists(os.path.join(artifact_dir, "universum_log.html"))


# https://github.com/Samsung/Universum/issues/711
def test_cli_log_default_name_last_parameter(tmpdir):
artifact_dir = check_cli(tmpdir, ["-hl"], is_html_last_param=True)
assert not os.path.exists(os.path.join(artifact_dir, "default"))
assert os.path.exists(os.path.join(artifact_dir, "universum_log.html"))


Expand Down Expand Up @@ -299,7 +307,7 @@ def check_timestamps(body_element, universum_log_element):
assert delta.seconds <= 60


def check_cli(tmpdir, html_log_params):
def check_cli(tmpdir, html_log_params, is_html_last_param=False):
artifact_dir = tmpdir.join("artifacts")
config_file = tmpdir.join("configs.py")
config_file.write_text(config, "utf-8")
Expand All @@ -308,8 +316,14 @@ def check_cli(tmpdir, html_log_params):
"-fsd", str(tmpdir),
"-cfg", str(config_file),
"-ad", str(artifact_dir)]
html_log_params.extend(cli_params)
result = __main__.main(html_log_params)
if is_html_last_param:
cli_params.extend(html_log_params)
params = cli_params
else:
html_log_params.extend(cli_params)
params = html_log_params

result = __main__.main(params)

assert result == 0
return artifact_dir
Expand Down
8 changes: 5 additions & 3 deletions universum/modules/output/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ def define_arguments(argument_parser):
help="Type of output to produce (tc - TeamCity, jenkins - Jenkins, term - terminal, "
"github - Github Actions). TeamCity, Jenkins and Github Actions environments are "
"detected automatically when launched on build agent.")
# `universum` -> html_log == default
# `universum -hl` -> html_log == const
# `universum` -> html_log == `default`
# `universum -hl ${other_params}` -> html_log == `const`
# `universum ${other_params} -hl` -> html_log == "default"
# `universum -hl custom` -> html_log == custom
parser.add_argument("--html-log", "-hl", nargs="?", const=HtmlOutput.default_name, default=None,
help=f"Generate a self-contained user-friendly HTML log. "
Expand Down Expand Up @@ -104,7 +105,8 @@ def log_execution_finish(self, title: str, version: str) -> None:

def _create_html_driver(self):
is_enabled = self.settings.html_log is not None
html_driver = self.html_driver_factory(log_name=self.settings.html_log) if is_enabled else None
log_name = HtmlOutput.default_name if self.settings.html_log == "default" else self.settings.html_log
html_driver = self.html_driver_factory(log_name=log_name) if is_enabled else None
handler = HtmlDriverHandler(html_driver)
return handler

Expand Down