11# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected] > 22#
33# SPDX-License-Identifier: MPL-2.0
4- from typing import Tuple
4+ from typing import Any , Tuple
55from unittest .mock import MagicMock , patch
66
77import pandas as pd
1010from power_grid_model_io .functions .filters import exclude_all_columns_empty_or_zero , exclude_empty , exclude_value
1111
1212
13+ @pytest .mark .parametrize (
14+ ("row_value" , "expected_call" ),
15+ [
16+ (1 , 1 ),
17+ (pd .Series (1 ), 1 ),
18+ ],
19+ )
1320@patch ("power_grid_model_io.functions.filters.has_value" )
14- def test_exclude_empty (mock_has_value : MagicMock ):
21+ def test_exclude_empty (mock_has_value : MagicMock , row_value : Any , expected_call : Any ):
1522 col = "foo"
16- row = pd .Series ({"foo" : 1 , "bar" : "xyz" })
17- actual = exclude_empty (row , col )
18- mock_has_value .assert_called_once_with (row [col ])
19- assert actual == mock_has_value .return_value
23+ row = pd .Series ([row_value , "xyz" ], index = ["foo" , "bar" ])
24+ actual = exclude_empty (row = row , col = col )
25+
26+ mock_has_value .assert_called_once_with (expected_call )
27+ assert actual is mock_has_value .return_value
2028
2129
2230def test_exclude_empty__invalid_col ():
@@ -31,9 +39,11 @@ def test_exclude_empty__invalid_col():
3139 (4.0 , "x" , True ),
3240 (3.0 , 3.0 , False ),
3341 (3.2 , 3.1 , True ),
42+ (pd .Series ([3 ]), 3 , False ),
43+ (pd .Series ([3 ]), 2 , True ),
3444 ],
3545)
36- def test_exclude_value (row_value : float , check_value : float , expected : bool ):
46+ def test_exclude_value (row_value : float | pd . Series , check_value : float , expected : bool ):
3747 row = pd .Series ({"foo" : row_value })
3848 actual = exclude_value (row = row , col = "foo" , value = check_value )
3949 assert actual == expected
0 commit comments