Skip to content

Commit

Permalink
[Feature] Supports non half width alphanumeric for generic test (#8203)
Browse files Browse the repository at this point in the history
* Supports non half width alphanumeric for generic test

* Unify conditional statements

* add CHANGELOG entries

* added test for Japanese

* Move the fix further upstream

* Remove the changes in core/dbt/task/runnable.py

* Fix accidental removal of `_` substitution character

---------

Co-authored-by: Doug Beatty <[email protected]>
  • Loading branch information
d-kaneshiro and dbeatty10 authored Nov 9, 2023
1 parent e547c0e commit f45b013
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230725-122847.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Supports non half width alphanumeric for generic test
time: 2023-07-25T12:28:47.88711+09:00
custom:
Author: d-kaneshiro
Issue: "8204"
2 changes: 1 addition & 1 deletion core/dbt/parser/generic_test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def synthesize_generic_test_names(

flat_args.extend([str(part) for part in parts])

clean_flat_args = [re.sub("[^0-9a-zA-Z_]+", "_", arg) for arg in flat_args]
clean_flat_args = [re.sub(r"\W+", "_", arg) for arg in flat_args]
unique = "__".join(clean_flat_args)

# for the file path + alias, the name must be <64 characters
Expand Down
50 changes: 50 additions & 0 deletions tests/adapter/dbt/tests/adapter/basic/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
10,Nora,1976-03-01T16:51:39
""".lstrip()

seeds_jp_base_csv = """
id,名前,ふりがな,部署コード,イニシャル
1,比嘉,ひが,10000,H
2,金城,きんじょう,10000,K
3,大城,おおしろ,10001,O
4,宮城,みやぎ,10001,M
5,新垣,あらかき,10002,A
6,玉城,たましろ,10002,T
7,上原,うえはら,10002,U
8,島袋,しまぶくろ,10003,S
9,平良,たいら,10003,T
10,山城,やましろ,10003,Y
""".lstrip()


seeds_added_csv = (
seeds_base_csv
Expand Down Expand Up @@ -61,6 +75,18 @@
- name: id
tests:
- not_null
- name: 名前
tests:
- not_null
- name: ふりがな
tests:
- not_null
- name: 部署コード
tests:
- not_null
- name: イニシャル
tests:
- not_null
"""

generic_test_view_yml = """
Expand All @@ -71,6 +97,18 @@
- name: id
tests:
- not_null
- name: 名前
tests:
- not_null
- name: ふりがな
tests:
- not_null
- name: 部署コード
tests:
- not_null
- name: イニシャル
tests:
- not_null
"""

generic_test_table_yml = """
Expand All @@ -81,6 +119,18 @@
- name: id
tests:
- not_null
- name: 名前
tests:
- not_null
- name: ふりがな
tests:
- not_null
- name: 部署コード
tests:
- not_null
- name: イニシャル
tests:
- not_null
"""

test_passing_sql = """
Expand Down
8 changes: 4 additions & 4 deletions tests/adapter/dbt/tests/adapter/basic/test_generic_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from dbt.tests.util import run_dbt
from dbt.tests.adapter.basic.files import (
seeds_base_csv,
seeds_jp_base_csv,
generic_test_seed_yml,
base_view_sql,
base_table_sql,
Expand All @@ -19,7 +19,7 @@ def project_config_update(self):
@pytest.fixture(scope="class")
def seeds(self):
return {
"base.csv": seeds_base_csv,
"base.csv": seeds_jp_base_csv,
"schema.yml": generic_test_seed_yml,
}

Expand All @@ -39,15 +39,15 @@ def test_generic_tests(self, project):

# test command selecting base model
results = run_dbt(["test", "-m", "base"])
assert len(results) == 1
assert len(results) == 5

# run command
results = run_dbt(["run"])
assert len(results) == 2

# test command, all tests
results = run_dbt(["test"])
assert len(results) == 3
assert len(results) == 15


class TestGenericTests(BaseGenericTests):
Expand Down

0 comments on commit f45b013

Please sign in to comment.