-
Notifications
You must be signed in to change notification settings - Fork 3
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
[ORCA-284] External Test Testing & [ORCA-287] OmeXmlSchemaTest Bug fix #50
Conversation
✅ Linked to Bug ORCA-287 · OmeXmlSchemaTest always returns an exit code of 0 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #50 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 24 24
Lines 1184 1184
Branches 192 192
=========================================
Hits 1184 1184
☔ View full report in Codecov by Sentry. |
@@ -1,90 +1,121 @@ | |||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(No changed needed, but I wanted to share some resources with you).
This article gives a great overview of Behavior Driven Development (BDD) topics that can be applied to testing: https://pythontest.com/strategy/given-when-then-2/
BDD is also heavily used by automation engineers when writing automated end-to-end testing in a number of frameworks, so it's likely you'll run into this eventually.
I find thinking in a GIVEN-WHEN-THEN structure for my tests gives me clearer focus that I am testing a singular thing, I know what my assumptions are, and I know the actions I am taking.
I started to use this structure in the Synapse Python Client:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great food for thought and I will look to incorporate these concepts in future work!
test_status = test.get_status() | ||
assert test_status == TestStatus.PASS | ||
def test_that_the_libtiff_info_test_command_is_produced(test_targets): | ||
target = test_targets["tiff"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I could see these static strings through the test being an enum of the possible valid values you could have: https://docs.python.org/3/library/enum.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I already created a ticket for reworking the test file names because I find them to be confusing. I can explore this option as part of that task.
def test_that_the_bioformats_info_test_command_is_produced(test_targets): | ||
target = test_targets["tiff"] | ||
@docker_enabled_test | ||
def test_that_the_bioformats_info_test_exit_code_is_0_when_it_should_be(test_files): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Food for thought (feel free to take it or leave it):
You did a great job splitting the tests up into the various python scripts - One area that could be improved is to have 1 more level of organization within the script by grouping like tests together. For example:
class TestBioformats:
def test_....
def test_....
class TestTiffDateTimeTest:
def test_...
Further reading: https://docs.pytest.org/en/7.1.x/getting-started.html#group-multiple-tests-in-a-class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did consider this and have used test classes in the past. The reason I did not do it in this ticket is that the internal test unit tests don't have this structure and I wanted to keep the testing organization consistent while staying within the external test scope.
I propose a separate ticket that handles this refactoring of internal and external test unit tests into classes. I think this is a great organizational addition that will make contributing new tests and their unit tests to this repo simpler.
Edit: I created this ticket to track this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few comments I left, otherwise LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 LGTM!
ORCA-284 Problem:
Currently, there is no way to run external tests without using
nf-dcqc
, and therefore there is no way to easily test them to ensure that they are evaluating files as intended.ORCA-284 Solution:
Implement Docker-enabled tests that can run the exact commands that
nf-dcqc
currently does via a local or GitHub Actions Docker environment.Of note in this implementation:
docker
python package was added as atesting
dependencyBioFormatsInfoTest
was updated to specify theOMETiff
file format in its CLI command. The test was producing inconsistent results in local testing without this specified. This change has been tested innf-dcqc
and yielded the same consistent results as before.OmeTiffSuite
so this should not cause problems unlessit is added to other/new suites.
test_tests.py
has been converted intotest_external_tests.py
(I should have just created the new files and deleted the old, the diff is a little weird), and internal test unit tests have been split off intotest_internal_tests.py
.DockerExecutor
was introduced totest_external_tests.py
. This class takes the docker image string and command from theProcess
object generated for external tests, in addition to the path to a testing file, and creates aDockerExecutor
which can run external test commands by invoking itsexecute
method.format_command_for_sh
method escapes special characters in thecommand and prefaces it with
sh -c
to ensure that commands are executed in a similarfashion across Docker containers
working_dir
was set to"/"
inclient.containers.run
to ensure that files are able to beaccessed once mounted, regardless of
WORKDIR
configurations in specific images.ubuntu
runner immediately, butmacos
proved trickier. I did some research and long story short GitHub did add support to easily run Docker in themacos
runner in this PR, but it has been reported recently that this has stopped working due to changes in dependencies. As an interim solution, I implemented a simple wrapper that causes Docker-enabled tests to be skipped when they are run in a non-Linux environment, rather than adding more complex changes to our CI workflow.ORCA-287 Problem:
OmeXmlSchemaTest
always returns an exit code of 0, even when a file fails.ORCA-287 Solution:
The results of the
bftools/xmlvalid
command are actually found in itsstdout
, so instead of evaluating directly on the firstexitcode
, we pipe the output into agrep
command and look for the substring that indicates success:"No validation errors found."
. This way, thepass_code
for the test can remain"0"
, but when the file fails the test it can produce the expected"1"
. This change has been tested innf-dcqc
and with local Docker execution.