forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_inconsistent_namespace_check.py
38 lines (28 loc) · 1.39 KB
/
test_inconsistent_namespace_check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pytest
from ..check_for_inconsistent_pandas_namespace import (
check_for_inconsistent_pandas_namespace,
)
BAD_FILE_0 = "cat_0 = Categorical()\ncat_1 = pd.Categorical()"
BAD_FILE_1 = "cat_0 = pd.Categorical()\ncat_1 = Categorical()"
GOOD_FILE_0 = "cat_0 = Categorical()\ncat_1 = Categorical()"
GOOD_FILE_1 = "cat_0 = pd.Categorical()\ncat_1 = pd.Categorical()"
PATH = "t.py"
@pytest.mark.parametrize("content", [BAD_FILE_0, BAD_FILE_1])
def test_inconsistent_usage(content):
msg = r"Found both `pd\.Categorical` and `Categorical` in t\.py"
with pytest.raises(RuntimeError, match=msg):
check_for_inconsistent_pandas_namespace(content, PATH, replace=False)
@pytest.mark.parametrize("content", [GOOD_FILE_0, GOOD_FILE_1])
def test_consistent_usage(content):
# should not raise
check_for_inconsistent_pandas_namespace(content, PATH, replace=False)
@pytest.mark.parametrize("content", [BAD_FILE_0, BAD_FILE_1])
def test_inconsistent_usage_with_replace(content):
result = check_for_inconsistent_pandas_namespace(content, PATH, replace=True)
expected = "cat_0 = Categorical()\ncat_1 = Categorical()"
assert result == expected
@pytest.mark.parametrize("content", [GOOD_FILE_0, GOOD_FILE_1])
def test_consistent_usage_with_replace(content):
result = check_for_inconsistent_pandas_namespace(content, PATH, replace=True)
expected = content
assert result == expected