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

Add tests for sample data repo #13

Closed
wants to merge 2 commits into from
Closed

Add tests for sample data repo #13

wants to merge 2 commits into from

Conversation

stefsmeets
Copy link
Contributor

This PR adds some basic tests for the sample data repository functionality.

Closes #10

@stefsmeets stefsmeets requested a review from nielsdrost December 2, 2020 09:00
@stefsmeets stefsmeets marked this pull request as ready for review January 8, 2021 08:42
@stefsmeets stefsmeets requested a review from bouweandela January 8, 2021 10:30
Copy link
Member

@bouweandela bouweandela left a comment

Choose a reason for hiding this comment

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

When I try to run the tests, it fails with:

FAILED tests/test_sample_data_loader.py::test_load_timeseries_cubes_invalid - Failed: DID NOT RAISE <class 'ValueError'>

It would be good to add a GitHub action to show that this PR actually works. Do you have the permissions to do that? If not, I can do it.

@stefsmeets
Copy link
Contributor Author

When I try to run the tests, it fails with:

FAILED tests/test_sample_data_loader.py::test_load_timeseries_cubes_invalid - Failed: DID NOT RAISE <class 'ValueError'>

Works fine here, can you post the tracelog?

It would be good to add a GitHub action to show that this PR actually works. Do you have the permissions to do that? If not, I can do it.

Agreed, but let's do that in a separate PR once this is merged. I made a new issue here: #13

@bouweandela
Copy link
Member

That's why it's useful to run the tests on an independent machine..

Here goes:

$ pytest
=========================================================== test session starts ============================================================
platform linux -- Python 3.8.6, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: /home/bandela/src/esmvalgroup/esmvaltool_sample_data
plugins: xdist-2.1.0, env-0.6.2, mock-3.3.1, forked-1.3.0, flake8-1.0.6, metadata-1.11.0, html-3.0.0, cov-2.10.1
collected 3 items                                                                                                                          

tests/test_sample_data_loader.py ..F                                                                                                 [100%]

================================================================= FAILURES =================================================================
____________________________________________________ test_load_timeseries_cubes_invalid ____________________________________________________

    def test_load_timeseries_cubes_invalid():
        """Test for fail on wrong input parameter."""
        with pytest.raises(ValueError):
>           load_timeseries_cubes("FAIL")
E           Failed: DID NOT RAISE <class 'ValueError'>

tests/test_sample_data_loader.py:21: Failed
============================================================= warnings summary =============================================================
../../../conda/envs/esmvaltool/lib/python3.8/site-packages/pyke/knowledge_engine.py:28
  /home/bandela/conda/envs/esmvaltool/lib/python3.8/site-packages/pyke/knowledge_engine.py:28: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp

tests/test_sample_data_loader.py: 336 warnings
  /home/bandela/conda/envs/esmvaltool/lib/python3.8/site-packages/iris/fileformats/cf.py:358: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
    nc_var_att = getattr(nc_var, cls.cf_identity, None)

tests/test_sample_data_loader.py: 2421 warnings
  /home/bandela/conda/envs/esmvaltool/lib/python3.8/site-packages/iris/fileformats/cf.py:1139: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
    value = dataset.getncattr(attr)

tests/test_sample_data_loader.py: 1332 warnings
  /home/bandela/conda/envs/esmvaltool/lib/python3.8/site-packages/iris/fileformats/cf.py:191: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
    value = getattr(self.cf_data, name)

tests/test_sample_data_loader.py: 86 warnings
  /home/bandela/conda/envs/esmvaltool/lib/python3.8/site-packages/iris/fileformats/cf.py:221: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
    return tuple((attr, self.getncattr(attr)) for attr in

-- Docs: https://docs.pytest.org/en/stable/warnings.html
========================================================= short test summary info ==========================================================
FAILED tests/test_sample_data_loader.py::test_load_timeseries_cubes_invalid - Failed: DID NOT RAISE <class 'ValueError'>
================================================ 1 failed, 2 passed, 4176 warnings in 5.85s ================================================

@stefsmeets
Copy link
Contributor Author

stefsmeets commented Jan 19, 2021

That's why it's useful to run the tests on an independent machine..

Useful, yes, but it wouldn't solve the issue you are having. Can you check what the output is:

import esmvaltool_sample_data
esmvaltool_sample_data.load_timeseries_cubes('FAIL')

@bouweandela
Copy link
Member

It would make reviewing this pull request a lot easier though. The output is ModuleNotFoundError: No module named 'esmaltool_sample_data', but if I change the code to what I think you mean the output is an empty list, [].

@stefsmeets
Copy link
Contributor Author

stefsmeets commented Jan 25, 2021

It would make reviewing this pull request a lot easier though. The output is ModuleNotFoundError: No module named 'esmaltool_sample_data', but if I change the code to what I think you mean the output is an empty list, [].

The typo was my bad, but that output is impossible, because it checks the argument and raises a ValueError:

if mip_table not in ('amon', 'day'):

Are you sure you are on the latest version of this branch?

@bouweandela
Copy link
Member

Maybe I wasn't, I pulled the latest version of the branch and now I get:

$ pytest
=========================================================== test session starts ============================================================
platform linux -- Python 3.8.6, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: /home/bandela/src/esmvalgroup/esmvaltool_sample_data
plugins: xdist-2.1.0, env-0.6.2, mock-3.3.1, forked-1.3.0, flake8-1.0.6, metadata-1.11.0, html-3.0.0, cov-2.10.1
collected 3 items                                                                                                                          

tests/test_sample_data_loader.py ..F                                                                                                 [100%]

================================================================= FAILURES =================================================================
____________________________________________________ test_load_timeseries_cubes_invalid ____________________________________________________

    def test_load_timeseries_cubes_invalid():
        """Test for fail on wrong input parameter."""
        with pytest.raises(ValueError):
>           load_timeseries_cubes("FAIL")
E           Failed: DID NOT RAISE <class 'ValueError'>

tests/test_sample_data_loader.py:21: Failed
============================================================= warnings summary =============================================================
../../../conda/envs/esmvaltool/lib/python3.8/site-packages/pyke/knowledge_engine.py:28
  /home/bandela/conda/envs/esmvaltool/lib/python3.8/site-packages/pyke/knowledge_engine.py:28: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp

tests/test_sample_data_loader.py: 336 warnings
  /home/bandela/conda/envs/esmvaltool/lib/python3.8/site-packages/iris/fileformats/cf.py:358: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
    nc_var_att = getattr(nc_var, cls.cf_identity, None)

tests/test_sample_data_loader.py: 2421 warnings
  /home/bandela/conda/envs/esmvaltool/lib/python3.8/site-packages/iris/fileformats/cf.py:1139: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
    value = dataset.getncattr(attr)

tests/test_sample_data_loader.py: 1332 warnings
  /home/bandela/conda/envs/esmvaltool/lib/python3.8/site-packages/iris/fileformats/cf.py:191: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
    value = getattr(self.cf_data, name)

tests/test_sample_data_loader.py: 86 warnings
  /home/bandela/conda/envs/esmvaltool/lib/python3.8/site-packages/iris/fileformats/cf.py:221: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
    return tuple((attr, self.getncattr(attr)) for attr in

-- Docs: https://docs.pytest.org/en/stable/warnings.html
========================================================= short test summary info ==========================================================
FAILED tests/test_sample_data_loader.py::test_load_timeseries_cubes_invalid - Failed: DID NOT RAISE <class 'ValueError'>
================================================ 1 failed, 2 passed, 4176 warnings in 4.99s ================================================

and

$ python
Python 3.8.6 | packaged by conda-forge | (default, Oct  7 2020, 19:08:05) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import esmvaltool_sample_data
>>> esmvaltool_sample_data.load_timeseries_cubes('FAIL')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/bandela/src/esmvalgroup/esmvaltool_sample_data/esmvaltool_sample_data/__init__.py", line 78, in load_timeseries_cubes
    raise ValueError(f'Invalid `mip_table`: {repr(mip_table)}')
ValueError: Invalid `mip_table`: 'FAIL'
>>> 

@stefsmeets stefsmeets closed this Jun 29, 2021
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.

Add unit tests for loader functions
2 participants