Skip to content

Commit

Permalink
Allow search in macro and analysis paths
Browse files Browse the repository at this point in the history
add tests
  • Loading branch information
Jacob Beck committed Feb 25, 2020
1 parent bcea7cc commit f7fd854
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Add a "docs" field to models, with a "show" subfield ([#1671](https://github.com/fishtown-analytics/dbt/issues/1671), [#2107](https://github.com/fishtown-analytics/dbt/pull/2107))
- Add a dbt-{dbt_version} user agent field to the bigquery connector ([#2121](https://github.com/fishtown-analytics/dbt/issues/2121), [#2146](https://github.com/fishtown-analytics/dbt/pull/2146))
- Add support for `generate_database_name` macro ([#1695](https://github.com/fishtown-analytics/dbt/issues/1695), [#2143](https://github.com/fishtown-analytics/dbt/pull/2143))
- Expand the search path for schema.yml (an dby extension, the default docs path) to include macro-paths and analysis-paths (in addition to source-paths, data-paths, and snapshot-paths) ([#2155](https://github.com/fishtown-analytics/dbt/issues/2155), [#2159](https://github.com/fishtown-analytics/dbt/pull/2159))

### Fixes
- Fix issue where dbt did not give an error in the presence of duplicate doc names ([#2054](https://github.com/fishtown-analytics/dbt/issues/2054), [#2080](https://github.com/fishtown-analytics/dbt/pull/2080))
Expand Down
15 changes: 11 additions & 4 deletions core/dbt/config/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,14 @@ def _parse_versions(versions: Union[List[str], str]) -> List[VersionSpecifier]:


def _all_source_paths(
source_paths: List[str], data_paths: List[str], snapshot_paths: List[str]
source_paths: List[str],
data_paths: List[str],
snapshot_paths: List[str],
analysis_paths: List[str],
macro_paths: List[str],
) -> List[str]:
return list(chain(source_paths, data_paths, snapshot_paths))
return list(chain(source_paths, data_paths, snapshot_paths, analysis_paths,
macro_paths))


T = TypeVar('T')
Expand Down Expand Up @@ -244,7 +249,8 @@ class Project:
@property
def all_source_paths(self) -> List[str]:
return _all_source_paths(
self.source_paths, self.data_paths, self.snapshot_paths
self.source_paths, self.data_paths, self.snapshot_paths,
self.analysis_paths, self.macro_paths
)

@staticmethod
Expand Down Expand Up @@ -323,7 +329,8 @@ def from_project_config(
snapshot_paths: List[str] = value_or(cfg.snapshot_paths, ['snapshots'])

all_source_paths: List[str] = _all_source_paths(
source_paths, data_paths, snapshot_paths
source_paths, data_paths, snapshot_paths, analysis_paths,
macro_paths
)

docs_paths: List[str] = value_or(cfg.docs_paths, all_source_paths)
Expand Down
8 changes: 8 additions & 0 deletions test/integration/029_docs_generate_tests/macros/macro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

{% docs macro_info %}
My custom test that I wrote that does nothing
{% enddocs %}

{% docs macro_arg_info %}
The model for my custom test
{% enddocs %}
10 changes: 10 additions & 0 deletions test/integration/029_docs_generate_tests/macros/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
macros:
- name: test_nothing
description: "{{ doc('macro_info') }}"
meta:
some_key: 100
arguments:
- name: model
type: Relation
description: "{{ doc('macro_arg_info') }}"
8 changes: 0 additions & 8 deletions test/integration/029_docs_generate_tests/ref_models/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,3 @@ My table
{% docs column_info %}
An ID field
{% enddocs %}

{% docs macro_info %}
My custom test that I wrote that does nothing
{% enddocs %}

{% docs macro_arg_info %}
The model for my custom test
{% enddocs %}
10 changes: 0 additions & 10 deletions test/integration/029_docs_generate_tests/ref_models/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,3 @@ sources:
columns:
- name: id
description: "{{ doc('column_info') }}"

macros:
- name: test_nothing
description: "{{ doc('macro_info') }}"
meta:
some_key: 100
arguments:
- name: model
type: Relation
description: "{{ doc('macro_arg_info') }}"
64 changes: 57 additions & 7 deletions test/integration/029_docs_generate_tests/test_docs_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,9 @@ def expected_seeded_manifest(self, model_database=None):
'test.test.unique_model_id': [],
},
'docs': {
'dbt.__overview__': ANY
'dbt.__overview__': ANY,
'test.macro_info': ANY,
'test.macro_arg_info': ANY,
},
'metadata': {
'project_id': '098f6bcd4621d373cade4e832627b4f6',
Expand All @@ -1239,6 +1241,29 @@ def expected_seeded_manifest(self, model_database=None):
'patches': [],
'macro_patches': [],
},
normalize('macros/macro.md'): {
'checksum': self._checksum_file('macros/macro.md'),
'docs': [
'test.macro_info',
'test.macro_arg_info',
],
'macros': [],
'nodes': [],
'patches': [],
'path': self._path_to('macros', 'macro.md'),
'sources': [],
'macro_patches': [],
},
normalize('macros/schema.yml'): {
'path': self._path_to('macros', 'schema.yml'),
'checksum': self._checksum_file('macros/schema.yml'),
'docs': [],
'macros': [],
'nodes': [],
'patches': [],
'sources': [],
'macro_patches': [['test', 'test_nothing']],
},
normalize('models/model.sql'): {
'path': self._path_to('models', 'model.sql'),
'checksum': self._checksum_file('models/model.sql'),
Expand Down Expand Up @@ -1704,19 +1729,19 @@ def expected_postgres_references_manifest(self, model_database=None):
'block_contents': 'My custom test that I wrote that does nothing',
'file_contents': macro_info,
'name': 'macro_info',
'original_file_path': docs_path,
'original_file_path': self.dir('macros/macro.md'),
'package_name': 'test',
'path': 'docs.md',
'path': 'macro.md',
'root_path': self.test_root_dir,
'unique_id': 'test.macro_info',
},
'test.macro_arg_info': {
'block_contents': 'The model for my custom test',
'file_contents': macro_arg_info,
'name': 'macro_arg_info',
'original_file_path': docs_path,
'original_file_path': self.dir('macros/macro.md'),
'package_name': 'test',
'path': 'docs.md',
'path': 'macro.md',
'root_path': self.test_root_dir,
'unique_id': 'test.macro_arg_info',
},
Expand Down Expand Up @@ -1806,13 +1831,24 @@ def expected_postgres_references_manifest(self, model_database=None):
'test.source_info',
'test.table_info',
'test.column_info',
],
'macros': [],
'nodes': [],
'patches': [],
'path': self._path_to('ref_models', 'docs.md'),
'sources': [],
'macro_patches': [],
},
normalize('macros/macro.md'): {
'checksum': self._checksum_file('macros/macro.md'),
'docs': [
'test.macro_info',
'test.macro_arg_info',
],
'macros': [],
'nodes': [],
'patches': [],
'path': self._path_to('ref_models', 'docs.md'),
'path': self._path_to('macros', 'macro.md'),
'sources': [],
'macro_patches': [],
},
Expand All @@ -1824,6 +1860,16 @@ def expected_postgres_references_manifest(self, model_database=None):
'patches': ['ephemeral_summary', 'view_summary'],
'path': self._path_to('ref_models', 'schema.yml'),
'sources': ['source.test.my_source.my_table'],
'macro_patches': [],
},
normalize('macros/schema.yml'): {
'path': self._path_to('macros', 'schema.yml'),
'checksum': self._checksum_file('macros/schema.yml'),
'docs': [],
'macros': [],
'nodes': [],
'patches': [],
'sources': [],
'macro_patches': [['test', 'test_nothing']],
},
normalize('seed/schema.yml'): {
Expand All @@ -1850,7 +1896,7 @@ def expected_postgres_references_manifest(self, model_database=None):
'meta': {
'some_key': 100,
},
'patch_path': self.dir('ref_models/schema.yml'),
'patch_path': self.dir('macros/schema.yml'),
'resource_type': 'macro',
'unique_id': 'macro.test.test_nothing',
'tags': [],
Expand Down Expand Up @@ -2256,6 +2302,8 @@ def expected_bigquery_complex_manifest(self):
},
'docs': {
'dbt.__overview__': ANY,
'test.macro_info': ANY,
'test.macro_arg_info': ANY,
},
'metadata': {
'project_id': '098f6bcd4621d373cade4e832627b4f6',
Expand Down Expand Up @@ -2557,6 +2605,8 @@ def expected_redshift_incremental_view_manifest(self):
},
'docs': {
'dbt.__overview__': ANY,
'test.macro_info': ANY,
'test.macro_arg_info': ANY,
},
'metadata': {
'project_id': '098f6bcd4621d373cade4e832627b4f6',
Expand Down

0 comments on commit f7fd854

Please sign in to comment.