diff --git a/csvqb/csvqb/models/cube/cube.py b/csvqb/csvqb/models/cube/cube.py index 3fcfa242e..c01ec7df3 100644 --- a/csvqb/csvqb/models/cube/cube.py +++ b/csvqb/csvqb/models/cube/cube.py @@ -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: diff --git a/csvqb/csvqb/tests/unit/cube/test_cube_errorvalidation.py b/csvqb/csvqb/tests/unit/cube/test_cube_errorvalidation.py index efa032fe1..ac255d609 100644 --- a/csvqb/csvqb/tests/unit/cube/test_cube_errorvalidation.py +++ b/csvqb/csvqb/tests/unit/cube/test_cube_errorvalidation.py @@ -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 * @@ -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(): @@ -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__":