Skip to content

Commit

Permalink
1. Add integration test for yaml schema extension warning. 2. Add int…
Browse files Browse the repository at this point in the history
…egration test for checking case-insensitive extensions
  • Loading branch information
sumanau7 authored and Sumanau Sareen committed Apr 7, 2020
1 parent 466ed1f commit f9343c4
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 15 deletions.
23 changes: 11 additions & 12 deletions core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
)
from dbt.exceptions import (
validator_error_message, JSONValidationException,
raise_invalid_schema_yml_version, ValidationException, CompilationException
raise_invalid_schema_yml_version, ValidationException,
CompilationException, warn_or_error
)
from dbt.logger import GLOBAL_LOGGER as logger
from dbt.node_types import NodeType
from dbt.parser.base import SimpleParser
from dbt.parser.search import FileBlock, FilesystemSearcher
Expand Down Expand Up @@ -133,18 +133,17 @@ def resource_type(self) -> NodeType:
def get_paths(self):
# TODO: In order to support this, make FilesystemSearcher accept a list
# of file patterns. eg: ['.yml', '.yaml']
yaml_files = FilesystemSearcher(
yaml_files = list(FilesystemSearcher(
self.project, self.project.all_source_paths, '.yaml'
)
))
if yaml_files:
logger.warning(
f'We have decided that dbt release July 1, 2020 onwards,'
f' will start parsing core config files with `.yaml`'
f' extension. That means that we will continue to support'
f' existing `.yml` extension along with `.yaml` extension.'
f' You should make sure these `.yaml` files are of correct'
f' schema or you can choose to remove this files from the'
f' project.'
warn_or_error(
'A future version of dbt will parse files with both'
' .yml and .yaml file extensions. dbt found'
f' {len(yaml_files)} files with .yaml extensions in'
' your dbt project. To avoid errors when upgrading'
' to a future release, either remove these files from'
' your dbt project, or change their extensions.'
)
return FilesystemSearcher(
self.project, self.project.all_source_paths, '.yml'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1 as id
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2

models:
- name: lowercase
columns:
- name: id
quote: true
tests:
- unique
- name: uppercase
columns:
- name: id
quote: true
tests:
- unique
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1 as id
40 changes: 40 additions & 0 deletions test/integration/008_schema_tests_test/test_schema_v2_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,43 @@ def test_postgres_argument_rendering(self):
results = self.run_dbt(['test', '--vars', '{myvar: foo}'])
self.assertEqual(len(results), 1)
self.run_dbt(['test'], expect_pass=False)


class TestSchemaCaseInsensitive(DBTIntegrationTest):
@property
def schema(self):
return "schema_tests_008"

@property
def models(self):
return "case-sensitive-models"

@use_profile('postgres')
def test_postgres_schema_lowercase_sql(self):
results = self.run_dbt(strict=False)
self.assertEqual(len(results), 2)
results = self.run_dbt(['test', '-m', 'lowercase'], strict=False)
self.assertEqual(len(results), 1)

@use_profile('postgres')
def test_postgres_schema_uppercase_sql(self):
results = self.run_dbt(strict=False)
self.assertEqual(len(results), 2)
results = self.run_dbt(['test', '-m', 'uppercase'], strict=False)
self.assertEqual(len(results), 1)


class TestSchemaYAMLExtension(DBTIntegrationTest):
@property
def schema(self):
return "schema_tests_008"

@property
def models(self):
return "case-sensitive-models"

@use_profile('postgres')
def test_postgres_yaml_extension(self):
with self.assertRaises(Exception) as exc:
self.run_dbt(["run"])
self.assertIn('yaml', str(exc.exception))
16 changes: 13 additions & 3 deletions test/unit/test_system_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,13 @@ def test__ok(self):
class TestFindMatching(unittest.TestCase):

def setUp(self):
self.base_dir = '/tmp'
self.base_dir = mkdtemp()
self.tempdir = mkdtemp(dir=self.base_dir)

def test_find_matching_lowercase_file_pattern(self):
with NamedTemporaryFile(prefix='sql-files', suffix='.sql', dir=self.tempdir) as named_file:
with NamedTemporaryFile(
prefix='sql-files', suffix='.sql', dir=self.tempdir
) as named_file:
file_path = os.path.dirname(named_file.name)
relative_path = os.path.basename(file_path)
out = dbt.clients.system.find_matching(
Expand Down Expand Up @@ -170,6 +172,14 @@ def test_find_matching_uppercase_file_pattern(self):
self.assertEqual(out, expected_output)

def test_find_matching_file_pattern_not_found(self):
with NamedTemporaryFile(prefix='sql-files', suffix='.SQLT', dir=self.tempdir) as named_file:
with NamedTemporaryFile(
prefix='sql-files', suffix='.SQLT', dir=self.tempdir
):
out = dbt.clients.system.find_matching(self.tempdir, [''], '*.sql')
self.assertEqual(out, [])

def tearDown(self):
try:
shutil.rmtree(self.base_dir)
except:
pass

0 comments on commit f9343c4

Please sign in to comment.