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 5, 2020
1 parent 7be464e commit edb3a72
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 11 deletions.
22 changes: 11 additions & 11 deletions core/dbt/parser/schemas.py
Expand Up @@ -29,7 +29,8 @@
)
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
Expand Down Expand Up @@ -133,18 +134,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'
)
).__iter__())
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
@@ -0,0 +1 @@
select 1 as id
Empty file.
@@ -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
@@ -0,0 +1 @@
select 1 as id
40 changes: 40 additions & 0 deletions test/integration/008_schema_tests_test/test_schema_v2_tests.py
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))

0 comments on commit edb3a72

Please sign in to comment.