670 improve testing - #749
Conversation
Basic refactoring to use mock bulk download
I dont understand why it does not work with caplog - now it should work.
This tests the user input regarding their credentials, not our software.
For faster testing
These failed due to pandas 3.0 handles None types differently
Simon-Will
left a comment
There was a problem hiding this comment.
Thanks a lot. It's looking quite good, I think! I only have some minor comments on most changes and one bigger thought:
I'm thinking a bit about how to trim the XML files and which files to choose for testing on. The current tests always work with wind, biomass, water and nuclear since these are small files and can be imported in a reasonable time for a test. I want to make two independent points:
- With trimmed files, we can also in a short time import multiple files because they only contain 100 records each. This way, we would also test the multi-file imports, which is currently a blind spot in the tests.
- The trimming works by using the first 100 records in a file. I think these are also the oldest records in the MaStR database, so they are quite a biased sample. It could happen that newer records contain some data that cannot be imported, but this would never be tested. This could be alleviated by choosing a random sample in the trimming process or by using solar so that we automatically have newer records by always having the first 100 records in each file.
** To be honest, this point is a bit moot since we already don't test the majority of the file types. If there were some data in some of them that couldn't be imported, the tests wouldn't catch it anyway.
What do you think about these?
I am not 100% sure what you mean here. Is your suggestion to also include large tables like solar, storages, ...? If yes I think I agree. The script will take a lot longer to run, but we only need to run it once in a while. And it has the advantage that more (all) technologies are part of the tests. Edit: Now I understand what you mean with multi-file: This is about technologies that have multiple xml files, like EinheitenSolar_1, _2, ... I will think of a way, maybe have maximum of three files per technology. |
It is useful to have the downloaded xml files in a tmp folder when building the mockup dataset for testing
|
@Simon-Will can you re-review? I resolved your requested changes and did the following:
|
|
@FlorianK13, hi, I was on vacation last week, but now took a look. I'm a bit confused since I cannot see new commits, the |
|
yeah sorry, forgot to push. Now the branch is ready for your review @Simon-Will |
Simon-Will
left a comment
There was a problem hiding this comment.
I like the new creation of the mockup files. Very nice! Looks good to me!
General
This is a first step for making our tests better. It creates a mockup for the bulk download and it skips the API tests if no credentials are provided (which hopefully makes the CI run successfully, also for PRs from outside)
SUmmary of changes
Add
tests/data/Gesamtdatenexport_mockup.zip: a small (~120 KB) mockup of the MaStR bulk download, generated byscripts/create_bulk_download_mockup.py. Contains 100 rows per XML table for wind, biomass, hydroRefactor
tests/conftest.py: replace the scan for existing local ZIP files with two fixtures (mockup_xml_zip_in_output_dir,mockup_docs_zip_in_output_dir) that copy the bundled files into a temporary directory. Theoutput_dirfixture now setsMASTR_PROJECT_HOME_DIRviamonkeypatch.setenvso theMastr()instance automatically picks up the temp directory without needing an explicitoutput_dirargument.Refactor
tests/test_mastr.py— remove all@pytest.mark.skipifguards that depended on real data and split the single large download integration test smaller onesSwitch
test_mastr_generate_data_model_fallback_to_included_docsfromcaplogtopatch.objecton the logger as somehow the caplog thing always failedRefactor
tests/soap_api/test_download.py— add arequires_real_credentialsmarker (using a runtime credential check) so that tests requiring real MaStR credentials are explicitly skipped when credentials are unavailable -> THIS HOPEFULLY FIXES THE GH CREDENTIAL ISSUE WHERE CI FAILED FOR OUTSIDE PRsDelete
tests/test_credentials.py— the credential test required real secrets and provided no value in CI.Since pandas>3.0 it handles dtypes differently - i needed to adapt some tests so that mismatching dtypes do not cause failure anymore
PR-Assignee
Reviewer