|
1 | 1 | import os |
| 2 | +import sys |
2 | 3 | from collections import defaultdict |
3 | 4 | from unittest import mock |
4 | 5 |
|
|
7 | 8 |
|
8 | 9 | import dbt_common |
9 | 10 | from dbt import deprecations |
| 11 | +from dbt.cli.main import dbtRunner |
10 | 12 | from dbt.clients.registry import _get_cached |
11 | 13 | from dbt.events.types import ( |
12 | 14 | CustomKeyInConfigDeprecation, |
|
15 | 17 | DeprecationsSummary, |
16 | 18 | DuplicateYAMLKeysDeprecation, |
17 | 19 | GenericJSONSchemaValidationDeprecation, |
| 20 | + ModelParamUsageDeprecation, |
18 | 21 | PackageRedirectDeprecation, |
19 | 22 | WEOIncludeExcludeDeprecation, |
20 | 23 | ) |
@@ -491,3 +494,95 @@ def test_weo_include_exclude_deprecation( |
491 | 494 | assert "exclude" in event_catcher.caught_events[0].info.msg |
492 | 495 | else: |
493 | 496 | assert "exclude" not in event_catcher.caught_events[0].info.msg |
| 497 | + |
| 498 | + |
| 499 | +class TestModelsParamUsageDeprecation: |
| 500 | + |
| 501 | + @mock.patch.object(sys, "argv", ["dbt", "ls", "--models", "some_model"]) |
| 502 | + def test_models_usage(self, project): |
| 503 | + event_catcher = EventCatcher(ModelParamUsageDeprecation) |
| 504 | + |
| 505 | + assert len(event_catcher.caught_events) == 0 |
| 506 | + run_dbt( |
| 507 | + ["ls", "--models", "some_model"], |
| 508 | + callbacks=[event_catcher.catch], |
| 509 | + ) |
| 510 | + assert len(event_catcher.caught_events) == 1 |
| 511 | + |
| 512 | + |
| 513 | +class TestModelsParamUsageRunnerDeprecation: |
| 514 | + |
| 515 | + def test_models_usage(self, project): |
| 516 | + event_catcher = EventCatcher(ModelParamUsageDeprecation) |
| 517 | + |
| 518 | + assert len(event_catcher.caught_events) == 0 |
| 519 | + dbtRunner(callbacks=[event_catcher.catch]).invoke(["ls", "--models", "some_model"]) |
| 520 | + assert len(event_catcher.caught_events) == 1 |
| 521 | + |
| 522 | + |
| 523 | +class TestModelParamUsageDeprecation: |
| 524 | + @mock.patch.object(sys, "argv", ["dbt", "ls", "--model", "some_model"]) |
| 525 | + def test_model_usage(self, project): |
| 526 | + event_catcher = EventCatcher(ModelParamUsageDeprecation) |
| 527 | + |
| 528 | + assert len(event_catcher.caught_events) == 0 |
| 529 | + run_dbt( |
| 530 | + ["ls", "--model", "some_model"], |
| 531 | + callbacks=[event_catcher.catch], |
| 532 | + ) |
| 533 | + assert len(event_catcher.caught_events) == 1 |
| 534 | + |
| 535 | + |
| 536 | +class TestModelParamUsageRunnerDeprecation: |
| 537 | + |
| 538 | + def test_model_usage(self, project): |
| 539 | + event_catcher = EventCatcher(ModelParamUsageDeprecation) |
| 540 | + |
| 541 | + assert len(event_catcher.caught_events) == 0 |
| 542 | + dbtRunner(callbacks=[event_catcher.catch]).invoke(["ls", "--model", "some_model"]) |
| 543 | + assert len(event_catcher.caught_events) == 1 |
| 544 | + |
| 545 | + |
| 546 | +class TestMParamUsageDeprecation: |
| 547 | + @mock.patch.object(sys, "argv", ["dbt", "ls", "-m", "some_model"]) |
| 548 | + def test_m_usage(self, project): |
| 549 | + event_catcher = EventCatcher(ModelParamUsageDeprecation) |
| 550 | + |
| 551 | + assert len(event_catcher.caught_events) == 0 |
| 552 | + run_dbt( |
| 553 | + ["ls", "-m", "some_model"], |
| 554 | + callbacks=[event_catcher.catch], |
| 555 | + ) |
| 556 | + assert len(event_catcher.caught_events) == 1 |
| 557 | + |
| 558 | + |
| 559 | +class TestMParamUsageRunnerDeprecation: |
| 560 | + def test_m_usage(self, project): |
| 561 | + event_catcher = EventCatcher(ModelParamUsageDeprecation) |
| 562 | + |
| 563 | + assert len(event_catcher.caught_events) == 0 |
| 564 | + dbtRunner(callbacks=[event_catcher.catch]).invoke(["ls", "-m", "some_model"]) |
| 565 | + assert len(event_catcher.caught_events) == 1 |
| 566 | + |
| 567 | + |
| 568 | +class TestSelectParamNoModelUsageDeprecation: |
| 569 | + |
| 570 | + @mock.patch.object(sys, "argv", ["dbt", "ls", "--select", "some_model"]) |
| 571 | + def test_select_usage(self, project): |
| 572 | + event_catcher = EventCatcher(ModelParamUsageDeprecation) |
| 573 | + |
| 574 | + assert len(event_catcher.caught_events) == 0 |
| 575 | + run_dbt( |
| 576 | + ["ls", "--select", "some_model"], |
| 577 | + callbacks=[event_catcher.catch], |
| 578 | + ) |
| 579 | + assert len(event_catcher.caught_events) == 0 |
| 580 | + |
| 581 | + |
| 582 | +class TestSelectParamNoModelUsageRunnerDeprecation: |
| 583 | + def test_select_usage(self, project): |
| 584 | + event_catcher = EventCatcher(ModelParamUsageDeprecation) |
| 585 | + |
| 586 | + assert len(event_catcher.caught_events) == 0 |
| 587 | + dbtRunner(callbacks=[event_catcher.catch]).invoke(["ls", "--select", "some_model"]) |
| 588 | + assert len(event_catcher.caught_events) == 0 |
0 commit comments