Skip to content

Commit

Permalink
tests multi table
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Palazzo committed Oct 25, 2023
1 parent 615db52 commit c963d11
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from unittest.mock import Mock

import pandas as pd
from tqdm import tqdm

from sdmetrics.demos import load_demo
from sdmetrics.reports.multi_table._properties import Structure


class TestStructure:

def test_end_to_end(self):
"""Test Structure multi-table."""
# Setup
real_data, synthetic_data, metadata = load_demo(modality='multi_table')
structure = Structure()

# Run
result = structure.get_score(real_data, synthetic_data, metadata)

# Assert
assert result == 1.0

expected_details = pd.DataFrame({
'Table': ['users', 'sessions', 'transactions'],
'Metric': ['TableFormat', 'TableFormat', 'TableFormat'],
'Score': [1.0, 1.0, 1.0],
})
pd.testing.assert_frame_equal(structure.details, expected_details)

def test_with_progress_bar(self):
"""Test that the progress bar is correctly updated."""
# Setup
real_data, synthetic_data, metadata = load_demo(modality='multi_table')
structure = Structure()
num_tables = len(metadata['tables'])

progress_bar = tqdm(total=num_tables)
mock_update = Mock()
progress_bar.update = mock_update

# Run
result = structure.get_score(real_data, synthetic_data, metadata, progress_bar)

# Assert
assert result == 1.0
assert mock_update.call_count == num_tables
14 changes: 14 additions & 0 deletions tests/unit/reports/multi_table/_properties/test_structure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Test Structure multi-table class."""
from sdmetrics.reports.multi_table._properties import Structure
from sdmetrics.reports.single_table._properties import Structure as SingleTableStructure


def test__init__():
"""Test the ``__init__`` method."""
# Setup
synthesis = Structure()

# Assert
assert synthesis._properties == {}
assert synthesis._single_table_property == SingleTableStructure
assert synthesis._num_iteration_case == 'table'

0 comments on commit c963d11

Please sign in to comment.