Created
July 2, 2020 09:52
-
-
Save glemaitre/84a21cfdd70f516b6ce1d0fd4eeed02f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import pytest | |
def func(expected_columns): | |
df = pd.DataFrame({ | |
"A": [1, 2, 3], | |
"B": [1, 2, 3], | |
"C": [1, 2, 3] | |
}) | |
diff_columns = set(df.columns.tolist()).symmetric_difference( | |
expected_columns | |
) | |
if len(diff_columns): | |
raise ValueError( | |
f"Discrepency regarding the columns. The following columns are " | |
f"either missing or not expected: {diff_columns}." | |
) | |
return df | |
def test_func_error(): | |
expected_columns = set([ | |
"A", "B", "C", "D", | |
]) | |
err_msg = "Discrepency regarding the columns." | |
with pytest.raises(ValueError, match=err_msg): | |
func(expected_columns) | |
def test_func(): | |
expected_columns = set([ | |
"A", "B", "C" | |
]) | |
df = func(expected_columns) | |
assert set(df.columns.tolist()) == expected_columns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment