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

Issue#62 Test cube validation #111

Merged
merged 3 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions csvqb/csvqb/models/cube/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def _validate_columns(self) -> List[ValidationError]:
errors.append(
ValidationError(f"Duplicate column title '{col.csv_column_title}'")
)
else:
existing_col_titles.add(col.csv_column_title)

maybe_column_data = None
if self.data is not None:
Expand Down
32 changes: 28 additions & 4 deletions csvqb/csvqb/tests/unit/cube/test_cube_errorvalidation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
import pandas as pd
from typing import List

import pandas as pd
import pytest

from csvqb.models.cube import *


Expand All @@ -19,7 +20,7 @@ def test_column_not_configured_error():

assert len(validation_errors) == 1
error = validation_errors[0]
assert "Some Dimension" in error.message
assert "Column 'Some Dimension'" in error.message


def test_column_title_wrong_error():
Expand All @@ -36,7 +37,30 @@ def test_column_title_wrong_error():

assert len(validation_errors) == 1
error = validation_errors[0]
assert "Some Column Title" in error.message
assert "Column 'Some Column Title'" in error.message


def test_two_column_same_title():
"""
If cube with two columns with the same title is defined, we get an error
"""
data = pd.DataFrame({
"Some Dimension": ["A", "B", "C"],
"Some Dimension": ["A", "B", "C"]
})

metadata = CatalogMetadata("Some Dataset")
columns: List[CsvColumn] = [
SuppressedCsvColumn("Some Dimension"),
SuppressedCsvColumn("Some Dimension")
]

cube = Cube(metadata, data, columns)
validation_errors = cube.validate()

assert len(validation_errors) == 1
error = validation_errors[0]
assert "Duplicate column title 'Some Dimension'" == error.message


if __name__ == "__main__":
Expand Down