|
1 | 1 | import pytest |
| 2 | +import pandas |
2 | 3 |
|
| 4 | +import conftest |
3 | 5 | from conftest import fail_on_pvlib_version |
4 | 6 |
|
5 | 7 | from pvlib._deprecation import pvlibDeprecationWarning, deprecated |
@@ -43,3 +45,38 @@ def test_use_fixture_with_decorator(some_data): |
43 | 45 | assert some_data == "some data" |
44 | 46 | with pytest.warns(pvlibDeprecationWarning): # test for deprecation warning |
45 | 47 | deprec_func(some_data) |
| 48 | + |
| 49 | + |
| 50 | +@pytest.mark.parametrize('function_name', ['assert_index_equal', |
| 51 | + 'assert_series_equal', |
| 52 | + 'assert_frame_equal']) |
| 53 | +@pytest.mark.parametrize('pd_version', ['1.0.0', '1.1.0']) |
| 54 | +@pytest.mark.parametrize('check_less_precise', [True, False]) |
| 55 | +def test__check_pandas_assert_kwargs(mocker, monkeypatch, |
| 56 | + function_name, pd_version, |
| 57 | + check_less_precise): |
| 58 | + # test that conftest._check_pandas_assert_kwargs returns appropriate |
| 59 | + # kwargs for the assert_x_equal functions |
| 60 | + |
| 61 | + # patch the pandas assert; not interested in actually calling them: |
| 62 | + def patched_assert(*args, **kwargs): |
| 63 | + pass |
| 64 | + |
| 65 | + monkeypatch.setattr(pandas.testing, function_name, patched_assert) |
| 66 | + # then attach a spy to it so we can see what args it is called with: |
| 67 | + mocked_function = mocker.spy(pandas.testing, function_name) |
| 68 | + # patch pd.__version__ to exercise the two branches in |
| 69 | + # conftest._check_pandas_assert_kwargs |
| 70 | + monkeypatch.setattr(pandas, '__version__', pd_version) |
| 71 | + |
| 72 | + # finally, run the function and check what args got passed to pandas: |
| 73 | + assert_function = getattr(conftest, function_name) |
| 74 | + args = [None, None] |
| 75 | + assert_function(*args, check_less_precise=check_less_precise) |
| 76 | + if pd_version == '1.1.0': |
| 77 | + tol = 1e-3 if check_less_precise else 1e-5 |
| 78 | + expected_kwargs = {'atol': tol, 'rtol': tol} |
| 79 | + else: |
| 80 | + expected_kwargs = {'check_less_precise': check_less_precise} |
| 81 | + |
| 82 | + mocked_function.assert_called_with(*args, **expected_kwargs) |
0 commit comments