From c749c72698083e39f2d85659ca225c99235b8968 Mon Sep 17 00:00:00 2001 From: Robert Astel Date: Thu, 25 May 2023 11:45:23 -0400 Subject: [PATCH] Preserve quotes round trip (#33) --- dbt_invoke/internal/_utils.py | 2 ++ dbt_invoke/internal/_version.py | 2 +- tests/test_properties.py | 7 +++++++ .../test_property_files/customers_preserve_quotes.yml | 11 +++++++++++ .../customers_preserve_quotes_expected.yml | 11 +++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/test_property_files/customers_preserve_quotes.yml create mode 100644 tests/test_property_files/customers_preserve_quotes_expected.yml diff --git a/dbt_invoke/internal/_utils.py b/dbt_invoke/internal/_utils.py index 28d5599..05178e9 100644 --- a/dbt_invoke/internal/_utils.py +++ b/dbt_invoke/internal/_utils.py @@ -83,6 +83,7 @@ def parse_yaml(location): :return: The contents of the yaml file """ yaml = YAML(typ="rt") + yaml.preserve_quotes = True with open(location, 'r') as stream: try: parsed_yaml = yaml.load(stream) @@ -101,6 +102,7 @@ def write_yaml(location, data, mode='w'): :return: None """ yaml = YAML(typ="rt") + yaml.preserve_quotes = True try: with open(location, mode) as stream: yaml.dump(data, stream) diff --git a/dbt_invoke/internal/_version.py b/dbt_invoke/internal/_version.py index 020ed73..d93b5b2 100644 --- a/dbt_invoke/internal/_version.py +++ b/dbt_invoke/internal/_version.py @@ -1 +1 @@ -__version__ = '0.2.2' +__version__ = '0.2.3' diff --git a/tests/test_properties.py b/tests/test_properties.py index f4bd918..855df4e 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -211,6 +211,13 @@ def test_multiline_quotes(self): expected_file="customers_multiline_quotes_expected.yml", ) + def test_preserve_quotes(self): + self.edit_update_compare( + "customers_preserve_quotes.yml", + target_model="customers", + expected_file="customers_preserve_quotes_expected.yml", + ) + def test_long_string(self): self.edit_update_compare( "customers_long_string.yml", diff --git a/tests/test_property_files/customers_preserve_quotes.yml b/tests/test_property_files/customers_preserve_quotes.yml new file mode 100644 index 0000000..b5d5677 --- /dev/null +++ b/tests/test_property_files/customers_preserve_quotes.yml @@ -0,0 +1,11 @@ +version: 2 +models: +- name: customers + description: A description + config: + labels: {'contains_pii': 'no', 'created_by': 'somebody'} + columns: + - name: customer_id + description: '' + - name: created_at + description: '' diff --git a/tests/test_property_files/customers_preserve_quotes_expected.yml b/tests/test_property_files/customers_preserve_quotes_expected.yml new file mode 100644 index 0000000..b5d5677 --- /dev/null +++ b/tests/test_property_files/customers_preserve_quotes_expected.yml @@ -0,0 +1,11 @@ +version: 2 +models: +- name: customers + description: A description + config: + labels: {'contains_pii': 'no', 'created_by': 'somebody'} + columns: + - name: customer_id + description: '' + - name: created_at + description: ''