From db8b5d2b92c9595c7f80b04cf760e172d83f7cf3 Mon Sep 17 00:00:00 2001 From: Balint Haller Date: Tue, 13 Apr 2021 10:27:22 +0200 Subject: [PATCH] main: fix example value merging --- carte_cli/model/carte_table_model.py | 6 ++++++ tests/model/test_carte_table_model.py | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/carte_cli/model/carte_table_model.py b/carte_cli/model/carte_table_model.py index b1d3ea8..0e4baee 100644 --- a/carte_cli/model/carte_table_model.py +++ b/carte_cli/model/carte_table_model.py @@ -193,12 +193,18 @@ def merge_columns(self, existing, preserve_descriptions=True): if preserve_descriptions and column_name in existing_columns_dict else column.description ) + merged_example = ( + existing_columns_dict[column_name].example_value + if preserve_descriptions and column_name in existing_columns_dict + else column.example_value + ) merged_columns.append( ColumnMetadata( name=column_name, column_type=column.column_type, description=merged_description, values=column.values, + example_value=merged_example, ) ) return merged_columns diff --git a/tests/model/test_carte_table_model.py b/tests/model/test_carte_table_model.py index 2cb8952..cc4f774 100644 --- a/tests/model/test_carte_table_model.py +++ b/tests/model/test_carte_table_model.py @@ -26,6 +26,7 @@ def test_from_frontmatter(self): "name": "test-name", "description": "test-description", "type": "test-type", + "example": 2020, } result = ColumnMetadata.from_frontmatter(source_metadata) @@ -33,6 +34,7 @@ def test_from_frontmatter(self): assert result.name == "test-name" assert result.description == "test-description" assert result.column_type == "test-type" + assert result.example_value == 2020 def test_from_frontmatter_no_values(self): source_metadata = {"name": "test-name"} @@ -48,7 +50,10 @@ def test_from_frontmatter_raises_with_no_name(self): def test_to_frontmatter(self): source = ColumnMetadata( - name="test-name", column_type="test-type", description="test-description" + name="test-name", + column_type="test-type", + description="test-description", + example_value="test-example", ) result = source.to_frontmatter() @@ -57,6 +62,7 @@ def test_to_frontmatter(self): "name": "test-name", "type": "test-type", "description": "test-description", + "example": "test-example", } @@ -102,7 +108,14 @@ def test_from_frontmatter(self): "database": "test-db", "location": "test-location", "connection": "test-connection", - "columns": [], + "columns": [ + { + "name": "column-a", + "type": "test-type", + "example": "test-example", + "description": "test-description", + } + ], "tags": [{"key": "a", "value": "val1"}, {"key": "b", "value": "val2"}], "table_type": "table", } @@ -113,7 +126,8 @@ def test_from_frontmatter(self): assert result.database == "test-db" assert result.location == "test-location" assert result.connection == "test-connection" - assert result.columns == [] + assert result.columns[0].__repr__() == ColumnMetadata("column-a", "test-type", "test-description", example_value="test-example").__repr__() + assert len(result.columns) == 1 assert result.table_type == TableType.TABLE assert result.tags[0].key == "a" assert result.tags[0].value == "val1"