forked from dbt-labs/dbt-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_graph_selector_methods.py
842 lines (689 loc) · 28.5 KB
/
test_graph_selector_methods.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
import copy
import pytest
from unittest import mock
from pathlib import Path
from dbt.contracts.files import FileHash
from dbt.contracts.graph.parsed import (
DependsOn,
NodeConfig,
ParsedModelNode,
ParsedExposure,
ParsedSeedNode,
ParsedDataTestNode,
ParsedSchemaTestNode,
ParsedSourceDefinition,
TestConfig,
TestMetadata,
ColumnInfo,
)
from dbt.contracts.graph.manifest import Manifest
from dbt.contracts.graph.unparsed import ExposureType, ExposureOwner
from dbt.contracts.state import PreviousState
from dbt.node_types import NodeType
from dbt.graph.selector_methods import (
MethodManager,
QualifiedNameSelectorMethod,
TagSelectorMethod,
SourceSelectorMethod,
PathSelectorMethod,
PackageSelectorMethod,
ConfigSelectorMethod,
TestNameSelectorMethod,
TestTypeSelectorMethod,
StateSelectorMethod,
ExposureSelectorMethod,
)
import dbt.exceptions
import dbt.contracts.graph.parsed
from .utils import replace_config
def make_model(pkg, name, sql, refs=None, sources=None, tags=None, path=None, alias=None, config_kwargs=None, fqn_extras=None):
if refs is None:
refs = []
if sources is None:
sources = []
if tags is None:
tags = []
if path is None:
path = f'{name}.sql'
if alias is None:
alias = name
if config_kwargs is None:
config_kwargs = {}
if fqn_extras is None:
fqn_extras = []
fqn = [pkg] + fqn_extras + [name]
depends_on_nodes = []
source_values = []
ref_values = []
for ref in refs:
ref_values.append([ref.name])
depends_on_nodes.append(ref.unique_id)
for src in sources:
source_values.append([src.source_name, src.name])
depends_on_nodes.append(src.unique_id)
return ParsedModelNode(
raw_sql=sql,
database='dbt',
schema='dbt_schema',
alias=alias,
name=name,
fqn=fqn,
unique_id=f'model.{pkg}.{name}',
package_name=pkg,
root_path='/usr/dbt/some-project',
path=path,
original_file_path=f'models/{path}',
config=NodeConfig(**config_kwargs),
tags=tags,
refs=ref_values,
sources=source_values,
depends_on=DependsOn(nodes=depends_on_nodes),
resource_type=NodeType.Model,
checksum=FileHash.from_contents(''),
)
def make_seed(pkg, name, path=None, loader=None, alias=None, tags=None, fqn_extras=None, checksum=None):
if alias is None:
alias = name
if tags is None:
tags = []
if path is None:
path = f'{name}.csv'
if fqn_extras is None:
fqn_extras = []
if checksum is None:
checksum = FileHash.from_contents('')
fqn = [pkg] + fqn_extras + [name]
return ParsedSeedNode(
raw_sql='',
database='dbt',
schema='dbt_schema',
alias=alias,
name=name,
fqn=fqn,
unique_id=f'seed.{pkg}.{name}',
package_name=pkg,
root_path='/usr/dbt/some-project',
path=path,
original_file_path=f'data/{path}',
tags=tags,
resource_type=NodeType.Seed,
checksum=FileHash.from_contents(''),
)
def make_source(pkg, source_name, table_name, path=None, loader=None, identifier=None, fqn_extras=None):
if path is None:
path = 'models/schema.yml'
if loader is None:
loader = 'my_loader'
if identifier is None:
identifier = table_name
if fqn_extras is None:
fqn_extras = []
fqn = [pkg] + fqn_extras + [source_name, table_name]
return ParsedSourceDefinition(
fqn=fqn,
database='dbt',
schema='dbt_schema',
unique_id=f'source.{pkg}.{source_name}.{table_name}',
package_name=pkg,
root_path='/usr/dbt/some-project',
path=path,
original_file_path=path,
name=table_name,
source_name=source_name,
loader='my_loader',
identifier=identifier,
resource_type=NodeType.Source,
loaded_at_field='loaded_at',
tags=[],
source_description='',
)
def make_unique_test(pkg, test_model, column_name, path=None, refs=None, sources=None, tags=None):
return make_schema_test(pkg, 'unique', test_model, {}, column_name=column_name)
def make_not_null_test(pkg, test_model, column_name, path=None, refs=None, sources=None, tags=None):
return make_schema_test(pkg, 'not_null', test_model, {}, column_name=column_name)
def make_schema_test(pkg, test_name, test_model, test_kwargs, path=None, refs=None, sources=None, tags=None, column_name=None):
kwargs = test_kwargs.copy()
ref_values = []
source_values = []
# this doesn't really have to be correct
if isinstance(test_model, ParsedSourceDefinition):
kwargs['model'] = "{{ source('" + test_model.source_name + \
"', '" + test_model.name + "') }}"
source_values.append([test_model.source_name, test_model.name])
else:
kwargs['model'] = "{{ ref('" + test_model.name + "')}}"
ref_values.append([test_model.name])
if column_name is not None:
kwargs['column_name'] = column_name
# whatever
args_name = test_model.search_name.replace(".", "_")
if column_name is not None:
args_name += '_' + column_name
node_name = f'{test_name}_{args_name}'
raw_sql = '{{ config(severity="ERROR") }}{{ test_' + \
test_name + '(**dbt_schema_test_kwargs) }}'
name_parts = test_name.split('.')
if len(name_parts) == 2:
namespace, test_name = name_parts
macro_depends = f'model.{namespace}.{test_name}'
elif len(name_parts) == 1:
namespace = None
macro_depends = f'model.dbt.{test_name}'
else:
assert False, f'invalid test name: {test_name}'
if path is None:
path = 'schema.yml'
if tags is None:
tags = ['schema']
if refs is None:
refs = []
if sources is None:
sources = []
depends_on_nodes = []
for ref in refs:
ref_values.append([ref.name])
depends_on_nodes.append(ref.unique_id)
for source in sources:
source_values.append([source.source_name, source.name])
depends_on_nodes.append(source.unique_id)
return ParsedSchemaTestNode(
raw_sql=raw_sql,
test_metadata=TestMetadata(
namespace=namespace,
name=test_name,
kwargs=kwargs,
),
database='dbt',
schema='dbt_postgres',
name=node_name,
alias=node_name,
fqn=['minimal', 'schema_test', node_name],
unique_id=f'test.{pkg}.{node_name}',
package_name=pkg,
root_path='/usr/dbt/some-project',
path=f'schema_test/{node_name}.sql',
original_file_path=f'models/{path}',
resource_type=NodeType.Test,
tags=tags,
refs=ref_values,
sources=[],
depends_on=DependsOn(
macros=[macro_depends],
nodes=depends_on_nodes
),
column_name=column_name,
checksum=FileHash.from_contents(''),
)
def make_data_test(pkg, name, sql, refs=None, sources=None, tags=None, path=None, config_kwargs=None):
if refs is None:
refs = []
if sources is None:
sources = []
if tags is None:
tags = ['data']
if path is None:
path = f'{name}.sql'
if config_kwargs is None:
config_kwargs = {}
fqn = ['minimal', 'data_test', name]
depends_on_nodes = []
source_values = []
ref_values = []
for ref in refs:
ref_values.append([ref.name])
depends_on_nodes.append(ref.unique_id)
for src in sources:
source_values.append([src.source_name, src.name])
depends_on_nodes.append(src.unique_id)
return ParsedDataTestNode(
raw_sql=sql,
database='dbt',
schema='dbt_schema',
name=name,
alias=name,
fqn=fqn,
unique_id=f'test.{pkg}.{name}',
package_name=pkg,
root_path='/usr/dbt/some-project',
path=path,
original_file_path=f'tests/{path}',
config=TestConfig(**config_kwargs),
tags=tags,
refs=ref_values,
sources=source_values,
depends_on=DependsOn(nodes=depends_on_nodes),
resource_type=NodeType.Test,
checksum=FileHash.from_contents(''),
)
def make_exposure(pkg, name, path=None, fqn_extras=None, owner=None):
if path is None:
path = 'schema.yml'
if fqn_extras is None:
fqn_extras = []
if owner is None:
owner = ExposureOwner(email='[email protected]')
fqn = [pkg, 'exposures'] + fqn_extras + [name]
return ParsedExposure(
name=name,
type=ExposureType.Notebook,
fqn=fqn,
unique_id=f'exposure.{pkg}.{name}',
package_name=pkg,
path=path,
root_path='/usr/src/app',
original_file_path=path,
owner=owner,
)
@pytest.fixture
def seed():
return make_seed(
'pkg',
'seed'
)
@pytest.fixture
def source():
return make_source(
'pkg',
'raw',
'seed',
identifier='seed'
)
@pytest.fixture
def ephemeral_model(source):
return make_model(
'pkg',
'ephemeral_model',
'select * from {{ source("raw", "seed") }}',
config_kwargs={'materialized': 'ephemeral'},
sources=[source],
)
@pytest.fixture
def view_model(ephemeral_model):
return make_model(
'pkg',
'view_model',
'select * from {{ ref("ephemeral_model") }}',
config_kwargs={'materialized': 'view'},
refs=[ephemeral_model],
tags=['uses_ephemeral'],
)
@pytest.fixture
def table_model(ephemeral_model):
return make_model(
'pkg',
'table_model',
'select * from {{ ref("ephemeral_model") }}',
config_kwargs={'materialized': 'table'},
refs=[ephemeral_model],
tags=['uses_ephemeral'],
path='subdirectory/table_model.sql'
)
@pytest.fixture
def ext_source():
return make_source(
'ext',
'ext_raw',
'ext_source',
)
@pytest.fixture
def ext_source_2():
return make_source(
'ext',
'ext_raw',
'ext_source_2',
)
@pytest.fixture
def ext_source_other():
return make_source(
'ext',
'raw',
'ext_source',
)
@pytest.fixture
def ext_source_other_2():
return make_source(
'ext',
'raw',
'ext_source_2',
)
@pytest.fixture
def ext_model(ext_source):
return make_model(
'ext',
'ext_model',
'select * from {{ source("ext_raw", "ext_source") }}',
sources=[ext_source],
)
@pytest.fixture
def union_model(seed, ext_source):
return make_model(
'pkg',
'union_model',
'select * from {{ ref("seed") }} union all select * from {{ source("ext_raw", "ext_source") }}',
config_kwargs={'materialized': 'table'},
refs=[seed],
sources=[ext_source],
fqn_extras=['unions'],
path='subdirectory/union_model.sql',
tags=['unions'],
)
@pytest.fixture
def table_id_unique(table_model):
return make_unique_test('pkg', table_model, 'id')
@pytest.fixture
def table_id_not_null(table_model):
return make_not_null_test('pkg', table_model, 'id')
@pytest.fixture
def view_id_unique(view_model):
return make_unique_test('pkg', view_model, 'id')
@pytest.fixture
def ext_source_id_unique(ext_source):
return make_unique_test('ext', ext_source, 'id')
@pytest.fixture
def view_test_nothing(view_model):
return make_data_test('pkg', 'view_test_nothing', 'select * from {{ ref("view_model") }} limit 0', refs=[view_model])
@pytest.fixture
def manifest(seed, source, ephemeral_model, view_model, table_model, ext_source, ext_model, union_model, ext_source_2, ext_source_other, ext_source_other_2, table_id_unique, table_id_not_null, view_id_unique, ext_source_id_unique, view_test_nothing):
nodes = [seed, ephemeral_model, view_model, table_model, union_model, ext_model,
table_id_unique, table_id_not_null, view_id_unique, ext_source_id_unique, view_test_nothing]
sources = [source, ext_source, ext_source_2,
ext_source_other, ext_source_other_2]
manifest = Manifest(
nodes={n.unique_id: n for n in nodes},
sources={s.unique_id: s for s in sources},
macros={},
docs={},
files={},
exposures={},
disabled=[],
selectors={},
)
return manifest
def search_manifest_using_method(manifest, method, selection):
selected = method.search(set(manifest.nodes) | set(
manifest.sources) | set(manifest.exposures), selection)
results = {manifest.expect(uid).search_name for uid in selected}
return results
def test_select_fqn(manifest):
methods = MethodManager(manifest, None)
method = methods.get_method('fqn', [])
assert isinstance(method, QualifiedNameSelectorMethod)
assert method.arguments == []
assert search_manifest_using_method(
manifest, method, 'pkg.unions') == {'union_model'}
assert not search_manifest_using_method(manifest, method, 'ext.unions')
# sources don't show up, because selection pretends they have no FQN. Should it?
assert search_manifest_using_method(manifest, method, 'pkg') == {
'union_model', 'table_model', 'view_model', 'ephemeral_model', 'seed'}
assert search_manifest_using_method(
manifest, method, 'ext') == {'ext_model'}
def test_select_tag(manifest):
methods = MethodManager(manifest, None)
method = methods.get_method('tag', [])
assert isinstance(method, TagSelectorMethod)
assert method.arguments == []
assert search_manifest_using_method(manifest, method, 'uses_ephemeral') == {
'view_model', 'table_model'}
assert not search_manifest_using_method(manifest, method, 'missing')
def test_select_source(manifest):
methods = MethodManager(manifest, None)
method = methods.get_method('source', [])
assert isinstance(method, SourceSelectorMethod)
assert method.arguments == []
# the lookup is based on how many components you provide: source, source.table, package.source.table
assert search_manifest_using_method(manifest, method, 'raw') == {
'raw.seed', 'raw.ext_source', 'raw.ext_source_2'}
assert search_manifest_using_method(
manifest, method, 'raw.seed') == {'raw.seed'}
assert search_manifest_using_method(
manifest, method, 'pkg.raw.seed') == {'raw.seed'}
assert search_manifest_using_method(
manifest, method, 'pkg.*.*') == {'raw.seed'}
assert search_manifest_using_method(
manifest, method, 'raw.*') == {'raw.seed', 'raw.ext_source', 'raw.ext_source_2'}
assert search_manifest_using_method(
manifest, method, 'ext.raw.*') == {'raw.ext_source', 'raw.ext_source_2'}
assert not search_manifest_using_method(manifest, method, 'missing')
assert not search_manifest_using_method(manifest, method, 'raw.missing')
assert not search_manifest_using_method(
manifest, method, 'missing.raw.seed')
assert search_manifest_using_method(manifest, method, 'ext.*.*') == {
'ext_raw.ext_source', 'ext_raw.ext_source_2', 'raw.ext_source', 'raw.ext_source_2'}
assert search_manifest_using_method(manifest, method, 'ext_raw') == {
'ext_raw.ext_source', 'ext_raw.ext_source_2'}
assert search_manifest_using_method(
manifest, method, 'ext.ext_raw.*') == {'ext_raw.ext_source', 'ext_raw.ext_source_2'}
assert not search_manifest_using_method(manifest, method, 'pkg.ext_raw.*')
# TODO: this requires writing out files
@pytest.mark.skip('TODO: write manifest files to disk')
def test_select_path(manifest):
methods = MethodManager(manifest, None)
method = methods.get_method('path', [])
assert isinstance(method, PathSelectorMethod)
assert method.arguments == []
assert search_manifest_using_method(
manifest, method, 'subdirectory/*.sql') == {'union_model', 'table_model'}
assert search_manifest_using_method(
manifest, method, 'subdirectory/union_model.sql') == {'union_model'}
assert search_manifest_using_method(
manifest, method, 'models/*.sql') == {'view_model', 'ephemeral_model'}
assert not search_manifest_using_method(manifest, method, 'missing')
assert not search_manifest_using_method(
manifest, method, 'models/missing.sql')
assert not search_manifest_using_method(
manifest, method, 'models/missing*')
def test_select_package(manifest):
methods = MethodManager(manifest, None)
method = methods.get_method('package', [])
assert isinstance(method, PackageSelectorMethod)
assert method.arguments == []
assert search_manifest_using_method(manifest, method, 'pkg') == {'union_model', 'table_model', 'view_model', 'ephemeral_model',
'seed', 'raw.seed', 'unique_table_model_id', 'not_null_table_model_id', 'unique_view_model_id', 'view_test_nothing'}
assert search_manifest_using_method(manifest, method, 'ext') == {
'ext_model', 'ext_raw.ext_source', 'ext_raw.ext_source_2', 'raw.ext_source', 'raw.ext_source_2', 'unique_ext_raw_ext_source_id'}
assert not search_manifest_using_method(manifest, method, 'missing')
def test_select_config_materialized(manifest):
methods = MethodManager(manifest, None)
method = methods.get_method('config', ['materialized'])
assert isinstance(method, ConfigSelectorMethod)
assert method.arguments == ['materialized']
assert search_manifest_using_method(manifest, method, 'view') == {
'view_model', 'ext_model'}
assert search_manifest_using_method(manifest, method, 'table') == {
'table_model', 'union_model'}
def test_select_test_name(manifest):
methods = MethodManager(manifest, None)
method = methods.get_method('test_name', [])
assert isinstance(method, TestNameSelectorMethod)
assert method.arguments == []
assert search_manifest_using_method(manifest, method, 'unique') == {
'unique_table_model_id', 'unique_view_model_id', 'unique_ext_raw_ext_source_id'}
assert search_manifest_using_method(manifest, method, 'not_null') == {
'not_null_table_model_id'}
assert not search_manifest_using_method(manifest, method, 'notatest')
def test_select_test_type(manifest):
methods = MethodManager(manifest, None)
method = methods.get_method('test_type', [])
assert isinstance(method, TestTypeSelectorMethod)
assert method.arguments == []
assert search_manifest_using_method(manifest, method, 'schema') == {
'unique_table_model_id', 'not_null_table_model_id', 'unique_view_model_id', 'unique_ext_raw_ext_source_id'}
assert search_manifest_using_method(manifest, method, 'data') == {
'view_test_nothing'}
def test_select_exposure(manifest):
exposure = make_exposure('test', 'my_exposure')
manifest.exposures[exposure.unique_id] = exposure
methods = MethodManager(manifest, None)
method = methods.get_method('exposure', [])
assert isinstance(method, ExposureSelectorMethod)
assert search_manifest_using_method(
manifest, method, 'my_exposure') == {'my_exposure'}
assert not search_manifest_using_method(
manifest, method, 'not_my_exposure')
@pytest.fixture
def previous_state(manifest):
writable = copy.deepcopy(manifest).writable_manifest()
state = PreviousState(Path('/path/does/not/exist'))
state.manifest = writable
return state
def add_node(manifest, node):
manifest.nodes[node.unique_id] = node
def change_node(manifest, node, change=None):
if change is not None:
node = change(node)
manifest.nodes[node.unique_id] = node
def statemethod(manifest, previous_state):
methods = MethodManager(manifest, previous_state)
method = methods.get_method('state', [])
assert isinstance(method, StateSelectorMethod)
assert method.arguments == []
return method
def test_select_state_no_change(manifest, previous_state):
method = statemethod(manifest, previous_state)
assert not search_manifest_using_method(manifest, method, 'modified')
assert not search_manifest_using_method(manifest, method, 'new')
def test_select_state_nothing(manifest, previous_state):
previous_state.manifest = None
method = statemethod(manifest, previous_state)
with pytest.raises(dbt.exceptions.RuntimeException) as exc:
search_manifest_using_method(manifest, method, 'modified')
assert 'no comparison manifest' in str(exc.value)
with pytest.raises(dbt.exceptions.RuntimeException) as exc:
search_manifest_using_method(manifest, method, 'new')
assert 'no comparison manifest' in str(exc.value)
def test_select_state_added_model(manifest, previous_state):
add_node(manifest, make_model('pkg', 'another_model', 'select 1 as id'))
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(
manifest, method, 'modified') == {'another_model'}
assert search_manifest_using_method(
manifest, method, 'new') == {'another_model'}
def test_select_state_changed_model_sql(manifest, previous_state, view_model):
change_node(manifest, view_model.replace(raw_sql='select 1 as id'))
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(
manifest, method, 'modified') == {'view_model'}
assert not search_manifest_using_method(manifest, method, 'new')
def test_select_state_changed_model_fqn(manifest, previous_state, view_model):
change_node(manifest, view_model.replace(
fqn=view_model.fqn[:-1]+['nested']+view_model.fqn[-1:]))
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(
manifest, method, 'modified') == {'view_model'}
assert not search_manifest_using_method(manifest, method, 'new')
def test_select_state_added_seed(manifest, previous_state):
add_node(manifest, make_seed('pkg', 'another_seed'))
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(
manifest, method, 'modified') == {'another_seed'}
assert search_manifest_using_method(
manifest, method, 'new') == {'another_seed'}
def test_select_state_changed_seed_checksum_sha_to_sha(manifest, previous_state, seed):
change_node(manifest, seed.replace(
checksum=FileHash.from_contents('changed')))
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(
manifest, method, 'modified') == {'seed'}
assert not search_manifest_using_method(manifest, method, 'new')
def test_select_state_changed_seed_checksum_path_to_path(manifest, previous_state, seed):
change_node(previous_state.manifest, seed.replace(
checksum=FileHash(name='path', checksum=seed.original_file_path)))
change_node(manifest, seed.replace(checksum=FileHash(
name='path', checksum=seed.original_file_path)))
method = statemethod(manifest, previous_state)
with mock.patch('dbt.contracts.graph.parsed.warn_or_error') as warn_or_error_patch:
assert not search_manifest_using_method(manifest, method, 'modified')
warn_or_error_patch.assert_called_once()
msg = warn_or_error_patch.call_args[0][0]
assert msg.startswith('Found a seed (pkg.seed) >1MB in size')
with mock.patch('dbt.contracts.graph.parsed.warn_or_error') as warn_or_error_patch:
assert not search_manifest_using_method(manifest, method, 'new')
warn_or_error_patch.assert_not_called()
def test_select_state_changed_seed_checksum_sha_to_path(manifest, previous_state, seed):
change_node(manifest, seed.replace(checksum=FileHash(
name='path', checksum=seed.original_file_path)))
method = statemethod(manifest, previous_state)
with mock.patch('dbt.contracts.graph.parsed.warn_or_error') as warn_or_error_patch:
assert search_manifest_using_method(
manifest, method, 'modified') == {'seed'}
warn_or_error_patch.assert_called_once()
msg = warn_or_error_patch.call_args[0][0]
assert msg.startswith('Found a seed (pkg.seed) >1MB in size')
with mock.patch('dbt.contracts.graph.parsed.warn_or_error') as warn_or_error_patch:
assert not search_manifest_using_method(manifest, method, 'new')
warn_or_error_patch.assert_not_called()
def test_select_state_changed_seed_checksum_path_to_sha(manifest, previous_state, seed):
change_node(previous_state.manifest, seed.replace(
checksum=FileHash(name='path', checksum=seed.original_file_path)))
method = statemethod(manifest, previous_state)
with mock.patch('dbt.contracts.graph.parsed.warn_or_error') as warn_or_error_patch:
assert search_manifest_using_method(
manifest, method, 'modified') == {'seed'}
warn_or_error_patch.assert_not_called()
with mock.patch('dbt.contracts.graph.parsed.warn_or_error') as warn_or_error_patch:
assert not search_manifest_using_method(manifest, method, 'new')
warn_or_error_patch.assert_not_called()
def test_select_state_changed_seed_fqn(manifest, previous_state, seed):
change_node(manifest, seed.replace(
fqn=seed.fqn[:-1]+['nested']+seed.fqn[-1:]))
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(
manifest, method, 'modified') == {'seed'}
assert not search_manifest_using_method(manifest, method, 'new')
def test_select_state_changed_seed_relation_documented(manifest, previous_state, seed):
seed_doc_relation = replace_config(seed, persist_docs={'relation': True})
change_node(manifest, seed_doc_relation)
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(
manifest, method, 'modified') == {'seed'}
assert not search_manifest_using_method(manifest, method, 'new')
def test_select_state_changed_seed_relation_documented_nodocs(manifest, previous_state, seed):
seed_doc_relation = replace_config(seed, persist_docs={'relation': True})
seed_doc_relation_documented = seed_doc_relation.replace(
description='a description')
change_node(previous_state.manifest, seed_doc_relation)
change_node(manifest, seed_doc_relation_documented)
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(
manifest, method, 'modified') == {'seed'}
assert not search_manifest_using_method(manifest, method, 'new')
def test_select_state_changed_seed_relation_documented_withdocs(manifest, previous_state, seed):
seed_doc_relation = replace_config(seed, persist_docs={'relation': True})
seed_doc_relation_documented = seed_doc_relation.replace(
description='a description')
change_node(previous_state.manifest, seed_doc_relation_documented)
change_node(manifest, seed_doc_relation)
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(
manifest, method, 'modified') == {'seed'}
assert not search_manifest_using_method(manifest, method, 'new')
def test_select_state_changed_seed_columns_documented(manifest, previous_state, seed):
# changing persist_docs, even without changing the description -> changed
seed_doc_columns = replace_config(seed, persist_docs={'columns': True})
change_node(manifest, seed_doc_columns)
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(
manifest, method, 'modified') == {'seed'}
assert not search_manifest_using_method(manifest, method, 'new')
def test_select_state_changed_seed_columns_documented_nodocs(manifest, previous_state, seed):
seed_doc_columns = replace_config(seed, persist_docs={'columns': True})
seed_doc_columns_documented_columns = seed_doc_columns.replace(
columns={'a': ColumnInfo(name='a', description='a description')},
)
change_node(previous_state.manifest, seed_doc_columns)
change_node(manifest, seed_doc_columns_documented_columns)
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(
manifest, method, 'modified') == {'seed'}
assert not search_manifest_using_method(manifest, method, 'new')
def test_select_state_changed_seed_columns_documented_withdocs(manifest, previous_state, seed):
seed_doc_columns = replace_config(seed, persist_docs={'columns': True})
seed_doc_columns_documented_columns = seed_doc_columns.replace(
columns={'a': ColumnInfo(name='a', description='a description')},
)
change_node(manifest, seed_doc_columns)
change_node(previous_state.manifest, seed_doc_columns_documented_columns)
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(
manifest, method, 'modified') == {'seed'}
assert not search_manifest_using_method(manifest, method, 'new')