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

Added tests for format module #7

Merged
merged 2 commits into from
Apr 23, 2024
Merged

Added tests for format module #7

merged 2 commits into from
Apr 23, 2024

Conversation

mattheww95
Copy link
Collaborator

I have added initial tests for the format module verifying outputs, it appeared that the outputs that were passed as examples to the pipeline differed from those generated. It seemed some column headers were mangled and there may have been differences in fields generated. I have updated the test data to reflect the more recent version of locidex

I have added initial tests for the format module verifying outputs, it appeared that the outputs that were passed as examples to the pipeline differed from those generated. It seemed some column headers were mangled and there may have been differences in fields generated. I have updated the test data to reflect the more recent version of locidex
I have added initial tests for the format module verifying outputs, it appeared that the outputs that were passed as examples to the pipeline differed from those generated. It seemed some column headers were mangled and there may have been differences in fields generated. I have updated the test data to reflect the more recent version of locidex
@mattheww95 mattheww95 requested a review from kbessonov1984 April 4, 2024 21:04
"input": "/Users/jrobertson/PycharmProjects/locidex/locidex/example/format_db_mlst_in",
"outdir": "/Users/jrobertson/PycharmProjects/locidex/locidex/example/format_db_mlst_out",
"input": "locidex/example/format_db_mlst_in",
"outdir": "/tmp/pytest-of-mwells/pytest-115/build0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was wondering if you can use a global variables for paths instead of absolute paths for better portability such as TEST_ROOT = os.path.dirname(__file__). Take a look at https://github.com/phac-nml/mob-suite/blob/master/mob_suite/tests/test_mobtyper_vs_biomarker_report.py

from dataclasses import dataclass

EXPECTED_DATA_OUT = "locidex/example/format_db_mlst_out"
TEST_DATA = "locidex/example/format_db_mlst_in"
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can also even make it more general via __file__ such as PACKAGE_ROOT = os.path.join(os.path.dirname(mob_suite.__file__),/example/...

def test_format(cmd_args):
format.run(cmd_args)

def test_outputs(output_directory):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure what is the purpose of this function? I suspect it is to make sure the listed files are in the same order. Also on Mac or other OS there might be hidden files such as .DS_Store that could break this assertion

"force"
]
result_json = "results.json"
expected = os.path.join(EXPECTED_DATA_OUT, result_json)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the actual vs expected absolute paths need an assertion statement here so the error is more cleaner if they happen do differ

expected = os.path.join(EXPECTED_DATA_OUT, result_json)
actual = os.path.join(output_directory, result_json)
with open(actual, 'r', encoding='utf8') as act, open(expected, 'r', encoding='utf8') as expc:
act_js = json.load(act)[primary_key]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would better first test if the key is found in the JSON loaded object and display more cleaner error message instead of key not found error. Also it would not be clear if tis not found in actual vs expected paths.

if key_to_check in json.load(act).keys():
    print(f"Key '{key_to_check}' exists.")
else:
    print(f"Key '{key_to_check}' does not exist.")

@mattheww95 mattheww95 merged commit 4e38102 into tests Apr 23, 2024
@mattheww95 mattheww95 deleted the test/format branch April 25, 2024 16:09
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.

2 participants