Skip to content

Commit

Permalink
main: fix example value merging
Browse files Browse the repository at this point in the history
  • Loading branch information
balinthaller committed Apr 13, 2021
1 parent 47aed1f commit db8b5d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions carte_cli/model/carte_table_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 17 additions & 3 deletions tests/model/test_carte_table_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ def test_from_frontmatter(self):
"name": "test-name",
"description": "test-description",
"type": "test-type",
"example": 2020,
}

result = ColumnMetadata.from_frontmatter(source_metadata)

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"}
Expand All @@ -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()
Expand All @@ -57,6 +62,7 @@ def test_to_frontmatter(self):
"name": "test-name",
"type": "test-type",
"description": "test-description",
"example": "test-example",
}


Expand Down Expand Up @@ -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",
}
Expand All @@ -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"
Expand Down

0 comments on commit db8b5d2

Please sign in to comment.