From 407ca09add06663164743c77bea25885d0fff498 Mon Sep 17 00:00:00 2001 From: R-Palazzo Date: Wed, 24 Jul 2024 15:08:56 +0200 Subject: [PATCH 1/2] def tests --- tests/test_property.py | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/test_property.py diff --git a/tests/test_property.py b/tests/test_property.py new file mode 100644 index 00000000..4e7cb0c5 --- /dev/null +++ b/tests/test_property.py @@ -0,0 +1,59 @@ +"""Tests that are common to all properties.""" + +import numpy as np +import pytest + +from sdmetrics.demos import load_demo +from sdmetrics.reports.multi_table import _properties as multi_table_properties +from sdmetrics.reports.single_table import _properties as single_table_properties + +REAL_DATA_ST, SYNTHETIC_DATA_ST, METADATA_ST = load_demo(modality='single_table') +REAL_DATA_MT, SYNTHETIC_DATA_MT, METADATA_MT = load_demo(modality='multi_table') +SINGLE_TABLE_PROPERTIES = [ + property + for property_name, property in vars(single_table_properties).items() + if property_name != 'BaseSingleTableProperty' and isinstance(property, type) +] +MULTI_TABLE_PROPERTIES = [ + property + for property_name, property in vars(multi_table_properties).items() + if property_name != 'BaseMultiTableProperty' and isinstance(property, type) +] + + +@pytest.mark.parametrize('property', SINGLE_TABLE_PROPERTIES) +def test_shuffling_data_single_table(property): + """Test the property score is the same when shuffling the data for single-table.""" + # Setup + property_instance = property() + + # Run + score = property_instance.get_score(REAL_DATA_ST, SYNTHETIC_DATA_ST, METADATA_ST) + score_shuffled = property_instance.get_score( + REAL_DATA_ST.sample(frac=1), SYNTHETIC_DATA_ST.sample(frac=1), METADATA_ST + ) + + # Assert + assert score_shuffled == score + + +@pytest.mark.parametrize('property', MULTI_TABLE_PROPERTIES) +def test_property_multi_table(property): + """Test the property score is the same when shuffling the data for multi-table.""" + # Setup + property_instance = property() + real_data_shuffled = { + table_name: table.sample(frac=1) for table_name, table in REAL_DATA_MT.items() + } + synthetic_data_shuffled = { + table_name: SYNTHETIC_DATA_MT[table_name].sample(frac=1) for table_name in SYNTHETIC_DATA_MT + } + + # Run + score = property_instance.get_score(REAL_DATA_MT, SYNTHETIC_DATA_MT, METADATA_MT) + score_shuffled = property_instance.get_score( + real_data_shuffled, synthetic_data_shuffled, METADATA_MT + ) + + # Assert + assert np.isclose(score, score_shuffled, rtol=1e-10) From 3d92eade6d2128b76db6b38b77fb70e0341af3eb Mon Sep 17 00:00:00 2001 From: R-Palazzo Date: Wed, 24 Jul 2024 15:30:09 +0200 Subject: [PATCH 2/2] change test name + location --- tests/{ => integration}/test_property.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename tests/{ => integration}/test_property.py (95%) diff --git a/tests/test_property.py b/tests/integration/test_property.py similarity index 95% rename from tests/test_property.py rename to tests/integration/test_property.py index 4e7cb0c5..054ddabd 100644 --- a/tests/test_property.py +++ b/tests/integration/test_property.py @@ -38,7 +38,7 @@ def test_shuffling_data_single_table(property): @pytest.mark.parametrize('property', MULTI_TABLE_PROPERTIES) -def test_property_multi_table(property): +def test_shuffling_data_multi_table(property): """Test the property score is the same when shuffling the data for multi-table.""" # Setup property_instance = property() @@ -56,4 +56,4 @@ def test_property_multi_table(property): ) # Assert - assert np.isclose(score, score_shuffled, rtol=1e-10) + assert np.isclose(score, score_shuffled, rtol=1e-12)