8000 Use pandas wrapper functions for the test suite by kandersolar · Pull Request #1021 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Use pandas wrapper functions for the test suite #1021

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

Merged
merged 7 commits into from
Aug 7, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add test
  • Loading branch information
kandersolar committed Aug 7, 2020
commit 390ff61cb50968ad45aa8baef4d8fda3df818a5b
37 changes: 37 additions & 0 deletions pvlib/tests/test_conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
import pandas

import conftest
from conftest import fail_on_pvlib_version

from pvlib._deprecation import pvlibDeprecationWarning, deprecated
Expand Down Expand Up @@ -43,3 +45,38 @@ def test_use_fixture_with_decorator(some_data):
assert some_data == "some data"
with pytest.warns(pvlibDeprecationWarning): # test for deprecation warning
deprec_func(some_data)


@pytest.mark.parametrize('function_name', ['assert_index_equal',
'assert_series_equal',
'assert_frame_equal'])
@pytest.mark.parametrize('pd_version', ['1.0.0', '1.1.0'])
@pytest.mark.parametrize('check_less_precise', [True, False])
def test__check_pandas_assert_kwargs(mocker, monkeypatch,
function_name, pd_version,
check_less_precise):
# test that conftest._check_pandas_assert_kwargs returns appropriate
# kwargs for the assert_x_equal functions

# patch the pandas assert; not interested in actually calling them:
def patched_assert(*args, **kwargs):
pass

monkeypatch.setattr(pandas.testing, function_name, patched_assert)
# then attach a spy to it so we can see what args it is called with:
mocked_function = mocker.spy(pandas.testing, function_name)
# patch pd.__version__ to exercise the two branches in
# conftest._check_pandas_assert_kwargs
monkeypatch.setattr(pandas, '__version__', pd_version)

# finally, run the function and check what args got passed to pandas:
assert_function = getattr(conftest, function_name)
args = [None, None]
assert_function(*args, check_less_precise=check_less_precise)
if pd_version == '1.1.0':
tol = 1e-3 if check_less_precise else 1e-5
expected_kwargs = {'atol': tol, 'rtol': tol}
else:
expected_kwargs = {'check_less_precise': check_less_precise}

mocked_function.assert_called_with(*args, **expected_kwargs)
0