def test_get_difference(source_stats, target_stats, expected_messages, expected_stats): result = cov.get_difference(Job(stats=source_stats, key="s"), Job(stats=target_stats, key="t")) assert result == create_result("Coverage Difference", expected_messages, stats=expected_stats)
def test_compare_response_ratio(source_stats, source_metadata, target_stats, target_metadata, expected_messages): source_job = Job(stats=source_stats, metadata=source_metadata) target_job = Job(stats=target_stats, metadata=target_metadata) result = compare_response_ratio(source_job, target_job) assert result == create_result("Compare Responses Per Item Ratio", expected_messages)
def test_job_items(mocker): mocker.patch("arche.readers.items.JobItems.job", return_value=Job(), autospec=True) mocker.patch( "arche.tools.api.get_items", return_value=job_items[1:3], autospec=True ) items = JobItems(key="112358/13/21", count=2, start_index=1, filters=None) np.testing.assert_array_equal(items.raw, job_items[1:3]) pd.testing.assert_frame_equal(items.df, expected_job_df.iloc[1:3]) assert items.count == 2 assert items.start == "112358/13/21/1"
def test_anomalies( mocker, jobs_stats: Dict, expected_messages: Dict, stats: pd.DataFrame ): jobs = [ Job(key=key, stats={"counts": counts, "totals": {"input_values": input_values}}) for key, counts, input_values in jobs_stats ] mocker.patch("arche.rules.coverage.api.get_jobs", return_value=jobs) result = cov.anomalies(jobs_stats[-1][0], [key for key, *_ in jobs_stats[:-1]]) assert result == create_result("Anomalies", expected_messages, stats=stats)
def test_job_items(mocker, start, count, expected_count): mocker.patch("arche.readers.items.JobItems.job", return_value=Job(), autospec=True) mocker.patch( "arche.tools.api.get_items", return_value=job_items[start:expected_count], autospec=True, ) items = JobItems(key="112358/13/21", start=start, count=count, filters=None, expand=False) np.testing.assert_array_equal(items.raw, job_items[start:count]) pd.testing.assert_frame_equal( items.df, expected_job_items.iloc[start:count].reset_index(drop=True)) assert items.count == count
def test_get_items_count(metadata, stats, expected_count): assert api.get_items_count(Job(metadata=metadata, stats=stats)) == expected_count
def test_check_response_ratio(stats, metadata, expected_messages): result = check_response_ratio(Job(metadata=metadata, stats=stats)) assert result == create_result("Responses Per Item Ratio", expected_messages)
def test_compare_fields_counts(source_stats, target_stats, expected_messages): result = compare_fields_counts(Job(stats=source_stats), Job(stats=target_stats)) assert result == create_result("Fields Counts", expected_messages)