Skip to content

Commit

Permalink
✅ Removed tests for not existing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafalz13 committed Jul 11, 2024
1 parent 89d98aa commit 9dcf387
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 97 deletions.
2 changes: 1 addition & 1 deletion src/viadot/sources/sharepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def _parse_excel(
na_values: Optional[list[str]] = None,
**kwargs,
):
"""Parses an Excel file into a DataFrame. Cast all columns to string.
"""Parses an Excel file into a DataFrame. Casts all columns to string.
Args:
excel_file: An ExcelFile object containing the data to parse.
Expand Down
106 changes: 10 additions & 96 deletions tests/unit/test_sharepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,6 @@ def test_sharepoint_custom_na(sharepoint_mock):
assert "NA" in list(df["col_a"])


def test_sharepoint_convert_all_to_string_type(sharepoint_mock):
converted_df = sharepoint_mock._convert_all_to_string_type(df=SAMPLE_DF)

assert not converted_df.empty
assert pd.isnull(converted_df["nan_col"]).all()


def test_sharepoint_convert_empty_columns_to_string(sharepoint_mock):
converted_df = sharepoint_mock._empty_column_to_string(df=SAMPLE_DF)

assert not converted_df.empty
assert converted_df["float_col"].dtype == float
assert converted_df["nan_col"].dtype == "string"


def test__get_file_extension(sharepoint_mock):
url_excel = "https://tenant.sharepoint.com/sites/site/file.xlsx"
url_dir = "https://tenant.sharepoint.com/sites/site/"
Expand All @@ -86,93 +71,22 @@ def test__is_file(sharepoint_mock):
assert is_file is False


def test__empty_column_to_string_mixed_values(sharepoint_mock):
df = pd.DataFrame(
{"col1": [None, None, None], "col2": [1, None, 3], "col3": ["a", "b", "c"]}
)
result = sharepoint_mock._empty_column_to_string(df)

expected = pd.DataFrame(
{
"col1": [None, None, None],
"col2": [1, None, 3],
"col3": ["a", "b", "c"],
}
)
expected["col1"] = expected["col1"].astype("string")

pd.testing.assert_frame_equal(result, expected)


def test_convert_all_to_string_type_mixed_types(sharepoint_mock):
df = pd.DataFrame(
{
"int": [1, 2, 3],
"float": [1.1, 2.2, 3.3],
"bool": [True, False, True],
"string": ["a", "b", "c"],
}
)
result = sharepoint_mock._convert_all_to_string_type(df)
expected = pd.DataFrame(
{
"int": ["1", "2", "3"],
"float": ["1.1", "2.2", "3.3"],
"bool": ["True", "False", "True"],
"string": ["a", "b", "c"],
}
)

pd.testing.assert_frame_equal(result, expected)


def test_convert_all_to_string_type_only_nan(sharepoint_mock):
df = pd.DataFrame(
{
"int": [None, None, None],
"float": [None, None, None],
"bool": [None, None, None],
"string": [None, None, None],
}
)
result = sharepoint_mock._convert_all_to_string_type(df)
expected = pd.DataFrame(
{
"int": [None, None, None],
"float": [None, None, None],
"bool": [None, None, None],
"string": [None, None, None],
}
).astype("string")
pd.testing.assert_frame_equal(result, expected)


def test_convert_all_to_string_type_empty_dataframe(sharepoint_mock):
df = pd.DataFrame()
result = sharepoint_mock._convert_all_to_string_type(df)

expected = pd.DataFrame()

pd.testing.assert_frame_equal(result, expected)


def test_convert_all_to_string_type_already_strings(sharepoint_mock):
df = pd.DataFrame({"string1": ["1", "2", "3"], "string2": ["a", "b", "c"]})
result = sharepoint_mock._convert_all_to_string_type(df)

expected = pd.DataFrame({"string1": ["1", "2", "3"], "string2": ["a", "b", "c"]})

pd.testing.assert_frame_equal(result, expected)


def test__parse_excel_single_sheet(sharepoint_mock):
excel_file = sharepoint_mock._download_file_stream()
result = sharepoint_mock._parse_excel(excel_file, sheet_name="Sheet1")
result_df = sharepoint_mock._parse_excel(excel_file, sheet_name="Sheet1")
expected = pd.DataFrame(
{
"col_a": ["val1", "", "val2", "NA", "N/A", "#N/A"],
"col_b": ["val1", "val2", "val3", "val4", "val5", "val6"],
}
)

assert result["col_b"].equals(expected["col_b"])
assert result_df["col_b"].equals(expected["col_b"])


def test__parse_excel_string_dtypes(sharepoint_mock):
excel_file = sharepoint_mock._download_file_stream()
result_df = sharepoint_mock._parse_excel(excel_file, sheet_name="Sheet1")

for column in result_df.columns:
assert result_df[column].dtype == object

0 comments on commit 9dcf387

Please sign in to comment.