Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDRP-781: Unit tests for remaining staging helpers #249

Draft
wants to merge 23 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fe3c5d5
RDRP-781: mocking for load json
JenCheshire Jun 20, 2024
353e98c
RDRP-781: secondary snapshot test
JenCheshire Jun 21, 2024
97c0172
RDRP-781: merge in develop and fix conflicts
JenCheshire Jun 24, 2024
909b2e3
RDRP-781: three tests working
JenCheshire Jun 24, 2024
7c0fdaa
RDRP-781: tidy tests
JenCheshire Jun 24, 2024
c533f06
RDRP-781: pre-commit changes
JenCheshire Jun 24, 2024
60df8d7
RDRP-781: tweak to docstring
JenCheshire Jun 24, 2024
0c1dd9d
RDRP-781: change config to default settings
JenCheshire Jun 24, 2024
292706f
RDRP-781: remove unnecessary #
JenCheshire Jun 24, 2024
990f95f
RDRP-781: removing unused imports
JenCheshire Jun 24, 2024
43f1758
RDRP-781: fix tests
JenCheshire Jun 24, 2024
8252eb8
RDRP-781: fix tests
JenCheshire Jun 24, 2024
023787b
RDRP-781: check changes to load validate mapper test
JenCheshire Jun 24, 2024
8c4c7a3
RDRP-781: fix issue with mocker
JenCheshire Jun 24, 2024
eef93da
RDRP-781: remove used import
JenCheshire Jun 26, 2024
d5929be
RDRP-781: update class name
JenCheshire Jun 26, 2024
26bd8d7
RDRP-781: merge in develop
JenCheshire Aug 2, 2024
e8d8edd
RDRP-781: fix tests
JenCheshire Aug 9, 2024
dce6ee3
RDRP-781: merge develop into 781
JenCheshire Aug 9, 2024
6f7a3d5
Merge remote-tracking branch 'origin/develop' into RDRP-781_remove_pa…
JenCheshire Sep 11, 2024
fb9227d
Merge remote-tracking branch 'origin/develop' into RDRP-781_remove_pa…
JenCheshire Sep 18, 2024
361f8ab
Merge remote-tracking branch 'origin/develop' into RDRP-781_remove_pa…
JenCheshire Oct 23, 2024
c79ce20
RDRP-781: mapper unit test
JenCheshire Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/staging/spp_snapshot_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ def response_rate(contributors: pd.DataFrame, responses: pd.DataFrame) -> float:
SppProcessingLogger.info(f"The response rate is {int(rounded_resp_rate*100)}%")

return response_rate

57 changes: 52 additions & 5 deletions tests/test_staging/test_staging_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from unittest.mock import Mock
from typing import Tuple
from datetime import date
import logging
from unittest.mock import patch

# Third Party Imports
import pandas as pd
Expand All @@ -17,6 +19,7 @@
from src.staging.staging_helpers import (
fix_anon_data,
getmappername,
load_validate_mapper,
load_snapshot_feather,
load_val_snapshot_json,
df_to_feather,
Expand Down Expand Up @@ -107,10 +110,57 @@ def test_getmappername(self):
), "getmappername not behaving as expected when split=False"


# load_validate_mapper [CANT TEST: TOO MANY HARD CODED PATHS]
class TestLoadValidateMapper:
"""Tests for load_validate_mapper."""

@patch("src.utils.local_file_mods.rd_file_exists")
@patch("src.utils.local_file_mods.rd_read_csv")
@patch("src.staging.validation.validate_data_with_schema")
def test_load_validate_mapper(
self,
mock_val_with_schema_func,
mock_read_csv_func,
mock_file_exists_func,
):
# Create a logger for this test
test_logger = logging.getLogger("test_load_validate_mapper")
test_logger.setLevel(logging.DEBUG)

# Mock data
mapper_path_key = "test_mapper_path"

config = {
"mapping_paths": {
"test_mapper_path": "/path/to/mapper.csv"
},
"global": {
"platform": "network",
},
}

# load_historic_data
mapper_df = pd.DataFrame(
{"col_one": [1, 2, 3, 4, 5, 6], "col_many": ["A", "A", "B", "C", "D", "D"]}
)
schema_path = "./config/test_schema.toml"

# Set mock return values
mock_file_exists_func.return_value = True
mock_read_csv_func.return_value = mapper_df

# Call the function
output = load_validate_mapper(
mapper_path_key,
config,
test_logger,
mock_file_exists_func,
mock_read_csv_func,
)

# Assertions
mock_file_exists_func.assert_called_once_with("/path/to/mapper.csv", raise_error=True)
mock_read_csv_func.assert_called_once_with("/path/to/mapper.csv")
mock_val_with_schema_func.assert_called_once_with(mapper_df, schema_path)
assert output.equals(mapper_df), "load_validate_mapper not behaving as expected."


class TestLoadSnapshotFeather(object):
Expand All @@ -132,9 +182,6 @@ def test_load_snapshot_feather(self, tmp_path):
), "Snapshot df has more columnss than expected."


# load_val_snapshot_json [CANT TEST: TOO MANY HARD CODED PATHS]


class TestDfToFeather(object):
"""Tests for df_to_Feather."""

Expand Down
Loading