Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Palazzo committed Sep 13, 2024
1 parent b8a468e commit db57309
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/unit/metadata/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import pandas as pd
import pytest

from sdv.errors import InvalidDataError
from sdv.metadata.errors import InvalidMetadataError
from sdv.metadata.metadata import Metadata
from tests.utils import DataFrameMatcher, get_multi_table_data, get_multi_table_metadata

Expand Down Expand Up @@ -551,6 +553,31 @@ def test_validate_data_no_relationships(self):
metadata.validate_data(data)
assert metadata.METADATA_SPEC_VERSION == 'V1'

def test_validate_table(self):
"""Test the ``validate_table``method."""
# Setup
metadata_multi_table = get_multi_table_metadata()
metadata_single_table = Metadata.load_from_dict(
metadata_multi_table.to_dict()['tables']['nesreca'], 'nesreca'
)
table = get_multi_table_data()['nesreca']

expected_error_wrong_name = re.escape(
'The provided data does not match the metadata:\n'
"The provided data is missing the tables {'nesreca'}."
)
expected_error_mutli_table = re.escape(
'Metadata contains more than one table, please specify the `table_name` to validate.'
)

# Run and Assert
metadata_single_table.validate_table(table)
metadata_single_table.validate_table(table, 'nesreca')
with pytest.raises(InvalidDataError, match=expected_error_wrong_name):
metadata_single_table.validate_table(table, 'wrong_name')
with pytest.raises(InvalidMetadataError, match=expected_error_mutli_table):
metadata_multi_table.validate_table(table)

@patch('sdv.metadata.metadata.Metadata')
def test_detect_from_dataframes(self, mock_metadata):
"""Test ``detect_from_dataframes``.
Expand Down

0 comments on commit db57309

Please sign in to comment.