From 8025d0dc9ccf5abc3639c68972a5fe8672596caf Mon Sep 17 00:00:00 2001 From: LouisK92 <37270609+LouisK92@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:04:27 +0100 Subject: [PATCH] Adjust based on pre-commit --- tests/README.md | 21 +++++++++++++-------- tests/plotting/test_plotting.py | 16 +++++++++------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/tests/README.md b/tests/README.md index 81cb051..d571d30 100644 --- a/tests/README.md +++ b/tests/README.md @@ -11,22 +11,27 @@ pytest ``` ## Regenerating the test data -For testing there were some files generated at some point in the past. These files shouldn't be changed. However, -there are cases when they might need to be recreated. E.g. an `anndata` update could lead to warnings when loading h5ads + +For testing there were some files generated at some point in the past. These files shouldn't be changed. However, +there are cases when they might need to be recreated. E.g. an `anndata` update could lead to warnings when loading h5ads saved with older versions of `anndata` or similar things. In this case, the test data can be regenerated by running: 1. For test data etc.: -Run the functions of the file `tests/_generate_test_files.py`. (not implemented yet) + Run the functions of the file `tests/_generate_test_files.py`. (not implemented yet) 2. For tests that compare their outputs to previously generated outputs (mainly plots): -- Run the according tests -- Find out the temp directory of pytest: e.g. from `python`: + +- Run the according tests +- Find out the temp directory of pytest: e.g. from `python`: + ```python import tempfile tempfile.gettempdir() ``` + The newest outputs should be in a folder like `/pytest-of-/pytest-/test_/` -- Copy the new outputs to the according test subfolder `tests/...` and overwrite the old ones. -3. Some tests don't save their outputs to files but compare them directly to some reference values. In this case, there -should be a comment in the test code that explains how to regenerate the reference values. E.g. function `test_knns_shared_comp` in `spapros/tests/evaluation/test_metrics.py`. +- Copy the new outputs to the according test subfolder `tests/...` and overwrite the old ones. + +3. Some tests don't save their outputs to files but compare them directly to some reference values. In this case, there + should be a comment in the test code that explains how to regenerate the reference values. E.g. function `test_knns_shared_comp` in `spapros/tests/evaluation/test_metrics.py`. diff --git a/tests/plotting/test_plotting.py b/tests/plotting/test_plotting.py index eab129e..fc8ea8b 100644 --- a/tests/plotting/test_plotting.py +++ b/tests/plotting/test_plotting.py @@ -8,22 +8,24 @@ # Note: The figures depend somehow on the environment! # Tests might fail if compared figures derived from different envs eg development env and test env + def _transform_string(s): """Transforms a string by replacing ': ' with '-' and ', ' with '_', and then removing problematic characters for Windows filenames. - - In the tests we use the kwargs of the functions as strings to name output files. To get a valid name for windows + + In the tests we use the kwargs of the functions as strings to name output files. To get a valid name for windows we need to replace certain characters. """ # Initial replacements - transformed = s.replace(': ', '-').replace(', ', '_') - + transformed = s.replace(": ", "-").replace(", ", "_") + # Additional removals - for char in [':', ',', '{', '}', "'", '[', ']']: - transformed = transformed.replace(char, '') - + for char in [":", ",", "{", "}", "'", "[", "]"]: + transformed = transformed.replace(char, "") + return transformed + ############# # selection # #############