Skip to content

feat: handle logging for multiple yamls#263

Merged
Pog3k merged 9 commits into
eclipse-kiso-testing:masterfrom
TedRio:separate-files-for-logging-when-multiple-YAMLs
Mar 27, 2023
Merged

feat: handle logging for multiple yamls#263
Pog3k merged 9 commits into
eclipse-kiso-testing:masterfrom
TedRio:separate-files-for-logging-when-multiple-YAMLs

Conversation

@TedRio
Copy link
Copy Markdown
Contributor

@TedRio TedRio commented Mar 23, 2023

No description provided.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 23, 2023

Codecov Report

Merging #263 (c0c3dd1) into master (651512e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head c0c3dd1 differs from pull request most recent head 564424f. Consider uploading reports for the commit 564424f to get more accurate results

@@           Coverage Diff           @@
##           master     #263   +/-   ##
=======================================
  Coverage   96.91%   96.91%           
=======================================
  Files          77       77           
  Lines        6191     6194    +3     
=======================================
+ Hits         6000     6003    +3     
  Misses        191      191           
Impacted Files Coverage Δ
src/pykiso/cli.py 100.00% <100.00%> (ø)
src/pykiso/logging_initializer.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment thread src/pykiso/cli.py Outdated

:return: file name without extension
"""
full_name = os.path.basename(path)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With pathlib this would become:
return Path(path).resolve().name

Copy link
Copy Markdown
Contributor Author

@TedRio TedRio Mar 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually Path(config_file).stem does exactly what I want and this function is useless 🤦‍♂️

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function will be then removed ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread src/pykiso/cli.py Outdated
@click.option(
"-l",
"--log-path",
"--log-paths",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't introduce a breaking change on the name just because we are now supporting multiple ones, only the option's help should be extended IMO

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes pls no breaking change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread src/pykiso/cli.py Outdated
)
log_index += 1
else:
raise ValueError(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using click.UsageError or any click CLI-specific exception instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread src/pykiso/cli.py Outdated
if log_paths:
yaml_name = get_file_name_without_extension(config_file)
# Put all logs in one file
if len(log_paths) == 1:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe run these check before looping and use something like:

for idx, config_file in enumerate(test_configuration_file):
    logger = initialize_logging(
        log_paths[idx], log_level, verbose, report_type, yaml_name
    )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the enumerate, for the check before the looping not sure it would make the code cleaner

Comment thread src/pykiso/logging_initializer.py Outdated
if log_path.is_dir():
fname = time.strftime("%Y-%m-%d_%H-%M-test.log")
if log_path.suffix == "":
if not log_path.is_dir():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe more

if log_path.is_dir():
    log_path.mkdir(exist_ok=True, parent=True)

?

Copy link
Copy Markdown
Contributor Author

@TedRio TedRio Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well unless I miss something if I do this is_dir will return False if the folder does not exist and it will not be created

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely right!
You could still flatten this a bit by doing:

if log_path.suffix == "":
    log_path.mkdir(parents=True, exist_ok=True)

which would already take care of the additional is_dir condition

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@TedRio TedRio requested a review from sebclrsn March 27, 2023 11:28
@Pog3k Pog3k merged commit 440923d into eclipse-kiso-testing:master Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants