From b3efb1e893ab69a2313013b39c650707bc2632eb Mon Sep 17 00:00:00 2001 From: Stu Kilgore Date: Tue, 8 Nov 2022 13:24:29 -0600 Subject: [PATCH 1/3] Convert color tests to pytest --- tests/functional/colors/test_colors.py | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/functional/colors/test_colors.py diff --git a/tests/functional/colors/test_colors.py b/tests/functional/colors/test_colors.py new file mode 100644 index 00000000000..7e92e039506 --- /dev/null +++ b/tests/functional/colors/test_colors.py @@ -0,0 +1,43 @@ +import pytest +import re +from dbt.tests.util import run_dbt_and_capture + + +models__do_nothing_then_fail_sql = """ +select 1, + +""" + + +@pytest.fixture(scope="class") +def models(): + return {"do_nothing_then_fail.sql": models__do_nothing_then_fail_sql} + + +@pytest.fixture(scope="class") +def project_config_update(): + return {'config-version': 2} + + +class TestColors: + def test_use_colors(self, project): + self.assert_colors_used( + "--use-colors", + expect_colors=True, + ) + + def test_no_use_colors(self, project): + self.assert_colors_used( + "--no-use-colors", + expect_colors=False, + ) + + def assert_colors_used(self, flag, expect_colors): + _, stdout = run_dbt_and_capture(args=[flag, "run"], expect_pass=False) + # pattern to match formatted log output + pattern = re.compile(r"\[31m.*|\[33m.*") + stdout_contains_formatting_characters = bool(pattern.search(stdout)) + if expect_colors: + assert stdout_contains_formatting_characters + else: + assert not stdout_contains_formatting_characters From 7c35a34d1d25174d72d5500ba8b885baed108002 Mon Sep 17 00:00:00 2001 From: Stu Kilgore Date: Tue, 8 Nov 2022 13:31:06 -0600 Subject: [PATCH 2/3] Add changie entry --- .changes/unreleased/Under the Hood-20221108-133104.yaml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changes/unreleased/Under the Hood-20221108-133104.yaml diff --git a/.changes/unreleased/Under the Hood-20221108-133104.yaml b/.changes/unreleased/Under the Hood-20221108-133104.yaml new file mode 100644 index 00000000000..4aea5ee8cd9 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20221108-133104.yaml @@ -0,0 +1,7 @@ +kind: Under the Hood +body: Convert use color tests to pytest +time: 2022-11-08T13:31:04.788547-06:00 +custom: + Author: stu-k + Issue: "5771" + PR: "6230" From ad6a050c20a197c157019cb05c7b642edee19062 Mon Sep 17 00:00:00 2001 From: Stu Kilgore Date: Tue, 8 Nov 2022 13:40:32 -0600 Subject: [PATCH 3/3] Remove old test files --- .../models/do_nothing_then_fail.sql | 1 - .../test_no_use_colors.py | 29 ------------------- .../061_use_colors_tests/test_use_colors.py | 29 ------------------- 3 files changed, 59 deletions(-) delete mode 100644 test/integration/061_use_colors_tests/models/do_nothing_then_fail.sql delete mode 100644 test/integration/061_use_colors_tests/test_no_use_colors.py delete mode 100644 test/integration/061_use_colors_tests/test_use_colors.py diff --git a/test/integration/061_use_colors_tests/models/do_nothing_then_fail.sql b/test/integration/061_use_colors_tests/models/do_nothing_then_fail.sql deleted file mode 100644 index 30f1a53ec18..00000000000 --- a/test/integration/061_use_colors_tests/models/do_nothing_then_fail.sql +++ /dev/null @@ -1 +0,0 @@ -select 1, diff --git a/test/integration/061_use_colors_tests/test_no_use_colors.py b/test/integration/061_use_colors_tests/test_no_use_colors.py deleted file mode 100644 index a923c8d855e..00000000000 --- a/test/integration/061_use_colors_tests/test_no_use_colors.py +++ /dev/null @@ -1,29 +0,0 @@ - -from test.integration.base import DBTIntegrationTest, use_profile -import logging -import re -import sys - -class TestNoUseColors(DBTIntegrationTest): - - @property - def project_config(self): - return {'config-version': 2} - - @property - def schema(self): - return "use_colors_tests_061" - - @property - def models(self): - return "models" - - @use_profile('postgres') - def test_postgres_no_use_colors(self): - # pattern to match formatted log output - pattern = re.compile(r'\[31m.*|\[33m.*') - - results, stdout = self.run_dbt_and_capture(args=['--no-use-colors', 'run'], expect_pass=False) - - stdout_contains_formatting_characters = bool(pattern.search(stdout)) - self.assertFalse(stdout_contains_formatting_characters) diff --git a/test/integration/061_use_colors_tests/test_use_colors.py b/test/integration/061_use_colors_tests/test_use_colors.py deleted file mode 100644 index 6b3dac6a1f1..00000000000 --- a/test/integration/061_use_colors_tests/test_use_colors.py +++ /dev/null @@ -1,29 +0,0 @@ - -from test.integration.base import DBTIntegrationTest, use_profile -import logging -import re -import sys - -class TestUseColors(DBTIntegrationTest): - - @property - def project_config(self): - return {'config-version': 2} - - @property - def schema(self): - return "use_colors_tests_061" - - @property - def models(self): - return "models" - - @use_profile('postgres') - def test_postgres_use_colors(self): - # pattern to match formatted log output - pattern = re.compile(r'\[31m.*|\[33m.*') - - results, stdout = self.run_dbt_and_capture(args=['--use-colors', 'run'], expect_pass=False) - - stdout_contains_formatting_characters = bool(pattern.search(stdout)) - self.assertTrue(stdout_contains_formatting_characters)