-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathtest_test.py
More file actions
3510 lines (3132 loc) · 100 KB
/
test_test.py
File metadata and controls
3510 lines (3132 loc) · 100 KB
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
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import annotations
import datetime
import typing as t
import io
from pathlib import Path
import unittest
from unittest.mock import call, patch
from shutil import rmtree
import pandas as pd # noqa: TID253
import pytest
from pytest_mock.plugin import MockerFixture
from sqlglot import exp
from IPython.utils.capture import capture_output
from sqlmesh.cli.project_init import init_example_project
from sqlmesh.core import constants as c
from sqlmesh.core.config import (
Config,
DuckDBConnectionConfig,
SparkConnectionConfig,
GatewayConfig,
ModelDefaultsConfig,
)
from sqlmesh.core.context import Context, ExecutionContext
from sqlmesh.core.console import get_console
from sqlmesh.core.dialect import parse
from sqlmesh.core.engine_adapter import EngineAdapter
from sqlmesh.core.macros import MacroEvaluator, macro
from sqlmesh.core.model import Model, SqlModel, load_sql_based_model, model
from sqlmesh.core.model.common import ParsableSql
from sqlmesh.core.test.definition import ModelTest, PythonModelTest, SqlModelTest
from sqlmesh.core.test.result import ModelTextTestResult
from sqlmesh.core.test.context import TestExecutionContext
from sqlmesh.utils import Verbosity
from sqlmesh.utils.errors import ConfigError, SQLMeshError, TestError
from sqlmesh.utils.yaml import dump as dump_yaml
from sqlmesh.utils.yaml import load as load_yaml
from tests.utils.test_helpers import use_terminal_console
if t.TYPE_CHECKING:
from unittest import TestResult
pytestmark = pytest.mark.slow
SUSHI_FOO_META = "MODEL (name sushi.foo, kind FULL)"
def _create_test(
body: t.Dict[str, t.Any], test_name: str, model: Model, context: Context
) -> ModelTest:
test_type = SqlModelTest if isinstance(model, SqlModel) else PythonModelTest
return test_type(
body=body[test_name],
test_name=test_name,
model=model,
models=context._models,
engine_adapter=context.test_connection_config.create_engine_adapter(
register_comments_override=False
),
dialect=context.config.dialect,
path=None,
default_catalog=context.default_catalog,
)
def _create_model(
query: str,
meta: str = SUSHI_FOO_META,
dialect: t.Optional[str] = None,
default_catalog: t.Optional[str] = None,
**kwargs: t.Any,
) -> SqlModel:
parsed_definition = parse(f"{meta};{query}", default_dialect=dialect)
return t.cast(
SqlModel,
load_sql_based_model(
parsed_definition, dialect=dialect, default_catalog=default_catalog, **kwargs
),
)
def _check_successful_or_raise(
result: t.Optional[TestResult], expected_msg: t.Optional[str] = None
) -> None:
assert result is not None
if not result.wasSuccessful():
error_or_failure_traceback = (result.errors or result.failures)[0][1]
print(error_or_failure_traceback)
if expected_msg:
assert expected_msg in error_or_failure_traceback
else:
raise AssertionError(error_or_failure_traceback)
@pytest.fixture
def full_model_without_ctes(request) -> SqlModel:
return _create_model(
"SELECT id, value, ds FROM raw",
dialect=getattr(request, "param", None),
default_catalog="memory",
)
@pytest.fixture
def full_model_with_single_cte(request) -> SqlModel:
return _create_model(
"WITH source AS (SELECT id FROM raw) SELECT id FROM source",
dialect=getattr(request, "param", None),
default_catalog="memory",
)
@pytest.fixture
def full_model_with_two_ctes(request) -> SqlModel:
return _create_model(
"""
WITH source AS (
SELECT id FROM raw
),
renamed AS (
SELECT id AS fid FROM source
)
SELECT fid FROM RENAMED;
""",
dialect=getattr(request, "param", None),
default_catalog="memory",
)
def test_ctes(sushi_context: Context, full_model_with_two_ctes: SqlModel) -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
raw:
- id: 1
outputs:
ctes:
source:
- id: 1
renamed:
- fid: 1
query:
- fid: 1
vars:
start: 2022-01-01
end: 2022-01-01
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(full_model_with_two_ctes),
context=sushi_context,
).run()
)
def test_ctes_only(sushi_context: Context, full_model_with_two_ctes: SqlModel) -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
raw:
- id: 1
outputs:
ctes:
source:
- id: 1
renamed:
- fid: 1
vars:
start: 2022-01-01
end: 2022-01-01
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(full_model_with_two_ctes),
context=sushi_context,
).run()
)
def test_query_only(sushi_context: Context, full_model_with_two_ctes: SqlModel) -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
raw:
- id: 1
outputs:
query:
- fid: 1
vars:
start: 2022-01-01
end: 2022-01-01
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(full_model_with_two_ctes),
context=sushi_context,
).run()
)
def test_with_rows(sushi_context: Context, full_model_with_single_cte: SqlModel) -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
raw:
rows:
- id: 1
outputs:
ctes:
source:
rows:
- id: 1
query:
rows:
- id: 1
vars:
start: 2022-01-01
end: 2022-01-01
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(full_model_with_single_cte),
context=sushi_context,
).run()
)
def test_without_rows(sushi_context: Context, full_model_with_single_cte: SqlModel) -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
raw:
- id: 1
outputs:
ctes:
source:
- id: 1
query:
- id: 1
vars:
start: 2022-01-01
end: 2022-01-01
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(full_model_with_single_cte),
context=sushi_context,
).run()
)
def test_column_order(sushi_context: Context, full_model_without_ctes: SqlModel) -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
raw:
- id: 1
value: 2
ds: 3
outputs:
query:
- id: 1
ds: 3
value: 2
vars:
start: 2022-01-01
end: 2022-01-01
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(full_model_without_ctes),
context=sushi_context,
).run()
)
def test_row_order(sushi_context: Context, full_model_without_ctes: SqlModel) -> None:
# Input and output rows are in different orders
body = load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
raw:
- id: 1
value: 2
ds: 3
- id: 2
value: 3
ds: 4
outputs:
query:
- id: 2
value: 3
ds: 4
- id: 1
value: 2
ds: 3
vars:
start: 2022-01-01
end: 2022-01-01
"""
)
# Model query without ORDER BY should pass unit test
_check_successful_or_raise(
_create_test(
body=body,
test_name="test_foo",
model=sushi_context.upsert_model(full_model_without_ctes),
context=sushi_context,
).run()
)
full_model_without_ctes_dict = full_model_without_ctes.dict()
full_model_without_ctes_dict["query"] = full_model_without_ctes.query.order_by("id") # type: ignore
full_model_without_ctes_orderby = SqlModel(**full_model_without_ctes_dict)
# Model query with ORDER BY should fail unit test
_check_successful_or_raise(
_create_test(
body=body,
test_name="test_foo",
model=sushi_context.upsert_model(full_model_without_ctes_orderby),
context=sushi_context,
).run(),
expected_msg=(
"AssertionError: Data mismatch (exp: expected, act: actual)\n\n"
" id value ds \n"
" exp act exp act exp act\n"
"0 2 1 3 2 4 3\n"
"1 1 2 2 3 3 4\n"
),
)
model_sql = """
SELECT
ARRAY_AGG(DISTINCT id_contact_b ORDER BY id_contact_b) AS aggregated_duplicates
FROM
source
GROUP BY
id_contact_a
ORDER BY
id_contact_a
"""
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_array_order:
model: test
inputs:
source:
- id_contact_a: a
id_contact_b: b
- id_contact_a: a
id_contact_b: c
outputs:
query:
- aggregated_duplicates:
- c
- b
"""
),
test_name="test_array_order",
model=_create_model(model_sql),
context=Context(config=Config(model_defaults=ModelDefaultsConfig(dialect="duckdb"))),
).run(),
expected_msg=(
"""AssertionError: Data mismatch (exp: expected, act: actual)\n\n"""
" aggregated_duplicates \n"
" exp act\n"
"0 (c, b) (b, c)\n"
),
)
@pytest.mark.parametrize(
"waiter_names_input",
[
"""sushi.waiter_names:
- id: 1
- id: 2
name: null
- id: 3
name: 'bob'
""",
"""sushi.waiter_names:
format: csv
rows: |
id,name
1,
2,null
3,bob""",
],
)
def test_partial_data(sushi_context: Context, waiter_names_input: str) -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
f"""
test_foo:
model: sushi.foo
inputs:
{waiter_names_input}
outputs:
ctes:
source:
- id: 1
- id: 2
name: null
- id: 3
name: 'bob'
query:
- id: 1
str: nan
- id: 2
str: nan
- id: 3
name: 'bob'
str: nan
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(
_create_model(
"WITH source AS (SELECT id, name FROM sushi.waiter_names) "
"SELECT id, name, 'nan' as str FROM source",
default_catalog=sushi_context.default_catalog,
)
),
context=sushi_context,
).run()
)
@pytest.mark.parametrize(
"waiter_names_input",
[
"""sushi.waiter_names:
format: yaml
rows:
- id: 1
name: alice
- id: 2
name: 'bob'
""",
"""sushi.waiter_names:
format: csv
rows: |
id,name
1,alice
2,bob""",
"""sushi.waiter_names:
format: csv
csv_settings:
sep: "#"
rows: |
id#name
1#alice
2#bob""",
],
)
def test_format_inline(sushi_context: Context, waiter_names_input: str) -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
f"""
test_foo:
model: sushi.foo
inputs:
{waiter_names_input}
outputs:
query:
- id: 1
name: alice
- id: 2
name: 'bob'
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(
_create_model(
"SELECT id, name FROM sushi.waiter_names ",
default_catalog=sushi_context.default_catalog,
)
),
context=sushi_context,
).run()
)
@pytest.mark.parametrize(
["input_data", "filename", "file_data"],
[
[
"""sushi.waiter_names:
format: yaml
path: """,
"test_data.yaml",
"""- id: 1
name: alice
- id: 2
name: 'bob'
""",
],
[
"""sushi.waiter_names:
path: """,
"test_data.yaml",
"""rows:
- id: 1
name: alice
- id: 2
name: 'bob'
""",
],
[
"""sushi.waiter_names:
format: csv
path: """,
"test_data.csv",
"""id,name
1,alice
2,bob""",
],
],
)
def test_format_path(
sushi_context: Context, tmp_path: Path, input_data: str, filename: str, file_data: str
) -> None:
test_csv_file = tmp_path / filename
test_csv_file.write_text(file_data)
_check_successful_or_raise(
_create_test(
body=load_yaml(
f"""
test_foo:
model: sushi.foo
inputs:
{input_data}{str(test_csv_file)}
outputs:
query:
- id: 1
name: alice
- id: 2
name: 'bob'
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(
_create_model(
"SELECT id, name FROM sushi.waiter_names ",
default_catalog=sushi_context.default_catalog,
)
),
context=sushi_context,
).run()
)
def test_unsupported_format_failure(
sushi_context: Context, full_model_without_ctes: SqlModel
) -> None:
with pytest.raises(
TestError,
match="Unsupported data format 'xml' for 'sushi.waiter_names'",
):
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
description: XML format isn't supported to load data (fails intentionally)
inputs:
sushi.waiter_names:
format: xml
path: 'test_data.xml'
outputs:
query:
- id: 1
value: null
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(full_model_without_ctes),
context=sushi_context,
)
with pytest.raises(
TestError,
match="Unsupported data format 'xml' for 'sushi.waiter_names'",
):
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
description: XML without path doesn't raise error
inputs:
sushi.waiter_names:
format: xml
rows: |
<rows>
<row>
<id>1</id>
<name>alice</name>
</row>
<row>
<id>2</id>
<name>bob</name>
</row>
</rows>
outputs:
query:
- id: 1
name: alice
- id: 2
name: 'bob'
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(
_create_model(
"SELECT id, name FROM sushi.waiter_names ",
default_catalog=sushi_context.default_catalog,
)
),
context=sushi_context,
)
def test_partial_output_columns() -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
raw:
- a: 1
b: 2
c: 3
d: 4
- a: 5
b: 6
c: 7
outputs:
partial: true # Applies to all outputs
ctes:
t:
rows:
- c: 3
- c: 7
query:
rows:
- a: 1
b: 2
- a: 5
b: 6
"""
),
test_name="test_foo",
model=_create_model("WITH t AS (SELECT a, b, c, d FROM raw) SELECT a, b, c, d FROM t"),
context=Context(config=Config(model_defaults=ModelDefaultsConfig(dialect="duckdb"))),
).run()
)
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
raw:
- a: 1
b: 2
c: 3
d: 4
- a: 5
b: 6
c: 7
outputs:
ctes:
t:
partial: true
rows:
- c: 3
- c: 7
query:
rows:
- a: 1
b: 2
c: 3
d: 4
- a: 5
b: 6
c: 7
"""
),
test_name="test_foo",
model=_create_model("WITH t AS (SELECT a, b, c, d FROM raw) SELECT a, b, c, d FROM t"),
context=Context(config=Config(model_defaults=ModelDefaultsConfig(dialect="duckdb"))),
).run()
)
def test_partial_data_column_order(sushi_context: Context) -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
sushi.items:
- id: 1234
event_date: 2020-01-01
- id: 9876
name: hello
event_date: 2020-01-02
outputs:
query:
- id: 1234
event_date: 2020-01-01
- id: 9876
name: hello
event_date: 2020-01-02
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(
_create_model(
"SELECT id, name, price, event_date FROM sushi.items",
default_catalog=sushi_context.default_catalog,
)
),
context=sushi_context,
).run()
)
# - output df must differ if sorted by (id, event_date) vs. (event_date, id)
# - output partial must be true
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
sushi.items:
- id: 9876
event_date: 2020-01-01
- id: 1234
name: hello
event_date: 2020-01-02
outputs:
partial: true
query:
- event_date: 2020-01-01
id: 9876
- event_date: 2020-01-02
id: 1234
name: hello
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(
_create_model(
"SELECT id, name, price, event_date FROM sushi.items",
default_catalog=sushi_context.default_catalog,
)
),
context=sushi_context,
).run()
)
def test_partial_data_missing_schemas(sushi_context: Context) -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
unknown:
- a: 1
b: bla
- b: baz
outputs:
query:
- a: 1
b: bla
- b: baz
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(_create_model("SELECT * FROM unknown")),
context=sushi_context,
).run()
)
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
unknown:
- id: 1234
date: 2023-01-12
- id: 9876
date: 2023-02-10
outputs:
query:
- id: 1234
date: 2023-01-12
month: 2023-01-01
null_date:
- id: 9876
date: 2023-02-10
month: 2023-02-01
null_date:
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(
_create_model(
"SELECT *, DATE_TRUNC('month', date)::DATE AS month, NULL::DATE AS null_date, FROM unknown"
)
),
context=sushi_context,
).run()
)
def test_partially_inferred_schemas(sushi_context: Context, mocker: MockerFixture) -> None:
parent = _create_model(
"SELECT a, b, s::ROW(d DATE) AS s FROM sushi.unknown",
meta="MODEL (name sushi.parent, kind FULL, dialect trino)",
default_catalog="memory",
)
parent = t.cast(SqlModel, sushi_context.upsert_model(parent))
child = _create_model(
"SELECT a, b, s.d AS d FROM sushi.parent",
meta="MODEL (name sushi.child, kind FULL)",
default_catalog="memory",
)
child = t.cast(SqlModel, sushi_context.upsert_model(child))
body = load_yaml(
"""
test_child:
model: sushi.child
inputs:
sushi.parent:
- a: 1
b: bla
s:
d: 2020-01-01
outputs:
query:
- a: 1
b: bla
d: 2020-01-01
"""
)
mocker.patch("sqlmesh.core.test.definition.random_id", return_value="jzngz56a")
test = _create_test(body, "test_child", child, sushi_context)
spy_execute = mocker.spy(test.engine_adapter, "_execute")
_check_successful_or_raise(test.run())
spy_execute.assert_any_call(
'CREATE OR REPLACE VIEW "memory"."sqlmesh_test_jzngz56a"."memory__sushi__parent" ("s", "a", "b") AS '
"SELECT "
'CAST("s" AS STRUCT("d" DATE)) AS "s", '
'CAST("a" AS INT) AS "a", '
'CAST("b" AS TEXT) AS "b" '
"""FROM (VALUES ({'d': CAST('2020-01-01' AS DATE)}, 1, 'bla')) AS "t"("s", "a", "b")""",
False,
)
def test_uninferrable_schema() -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
raw:
- value: null
outputs:
query:
- value: null
"""
),
test_name="test_foo",
model=_create_model("SELECT value FROM raw"),
context=Context(config=Config(model_defaults=ModelDefaultsConfig(dialect="duckdb"))),
).run(),
expected_msg=(
"""Failed to infer the data type of column 'value' for '"raw"'. This issue can """
"be mitigated by casting the column in the model definition, setting its type in "
"external_models.yaml if it's an external model, setting the model's 'columns' property, "
"or setting its 'columns' mapping in the test itself\n"
),
)
def test_missing_column_failure(sushi_context: Context, full_model_without_ctes: SqlModel) -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
description: sushi.foo's output has a missing column (fails intentionally)
inputs:
raw:
- id: 1
value: 2
ds: 3
outputs:
query:
- id: 1
value: null
"""
),
test_name="test_foo",
model=sushi_context.upsert_model(full_model_without_ctes),
context=sushi_context,
).run(),
expected_msg=(
"AssertionError: Data mismatch (exp: expected, act: actual)\n\n"
" value ds \n"
" exp act exp act\n"
"0 None 2 None 3\n"
),
)
def test_row_difference_failure() -> None:
_check_successful_or_raise(
_create_test(
body=load_yaml(
"""
test_foo:
model: sushi.foo
inputs:
raw:
- value: 1
outputs:
query:
- value: 1
- value: 2
"""
),
test_name="test_foo",
model=_create_model("SELECT value FROM raw"),
context=Context(config=Config(model_defaults=ModelDefaultsConfig(dialect="duckdb"))),
).run(),
expected_msg=(
"AssertionError: Data mismatch (rows are different)\n\n"