|
20 | 20 | write_orders_project, |
21 | 21 | ) |
22 | 22 |
|
23 | | -_MOVED: str = "models.finance._sqlbuild._macros.cents" |
| 23 | +_MOVED: str = "models.finance._sqlbuild._macros.python.cents" |
24 | 24 |
|
25 | 25 |
|
26 | 26 | @pytest.mark.parametrize( |
|
30 | 30 | description="direct, aliased and grouped imports of a carried macro module", |
31 | 31 | files={ |
32 | 32 | **cents_check( |
33 | | - "from models.staging._sqlbuild._macros.cents import to_cents\n" |
34 | | - "import models.staging._sqlbuild._macros.cents as cents_module\n" |
35 | | - "from models.staging._sqlbuild._macros.cents import (\n to_cents as cents,\n)", |
| 33 | + "from models.staging._sqlbuild._macros.python.cents import to_cents\n" |
| 34 | + "import models.staging._sqlbuild._macros.python.cents as cents_module\n" |
| 35 | + "from models.staging._sqlbuild._macros.python.cents import (\n to_cents as cents,\n)", |
36 | 36 | body=' assert to_cents("1") == cents_module.to_cents("1") == cents("1")\n', |
37 | 37 | ), |
38 | 38 | }, |
|
48 | 48 | description="a relative import from a macro module that stays", |
49 | 49 | files={ |
50 | 50 | **cents_check( |
51 | | - "from models.staging._sqlbuild._macros import cents as cents_module", |
| 51 | + "from models.staging._sqlbuild._macros.python import cents as cents_module", |
52 | 52 | body=' assert cents_module.to_cents("1")\n', |
53 | 53 | ), |
54 | | - "models/staging/_sqlbuild/_macros/totals.py": ( |
| 54 | + "models/staging/_sqlbuild/_macros/python/totals.py": ( |
55 | 55 | "from .cents import to_cents\n\n\n" |
56 | 56 | "def order_total(expression: str) -> str:\n" |
57 | 57 | ' return f"SUM({to_cents(expression)})"\n' |
58 | 58 | ), |
59 | 59 | "models/staging/stg_order_totals.sql": ( |
60 | 60 | "MODEL (description 'Test model stg_order_totals.',\n materialized view,\n);\n\n" |
61 | | - 'SELECT\n @order_total("amount") AS total_cents\nFROM __ref("stg_orders")\n' |
| 61 | + 'SELECT\n @py.order_total("amount") AS total_cents\nFROM __ref("stg_orders")\n' |
62 | 62 | ), |
63 | 63 | }, |
64 | 64 | expected_fragments={ |
65 | | - CENTS_CHECK: ("from macros import cents as cents_module",), |
66 | | - "models/staging/_sqlbuild/_macros/totals.py": ( |
67 | | - "from macros.cents import to_cents\n", |
| 65 | + CENTS_CHECK: ("from macros.python import cents as cents_module",), |
| 66 | + "models/staging/_sqlbuild/_macros/python/totals.py": ( |
| 67 | + "from macros.python.cents import to_cents\n", |
68 | 68 | ), |
69 | 69 | }, |
70 | 70 | ), |
@@ -102,38 +102,38 @@ def test_given_python_imports_of_a_moved_macro_when_moving_then_imports_follow_a |
102 | 102 | description="a dynamic import naming the macro module", |
103 | 103 | files=cents_check( |
104 | 104 | "import importlib\n\n" |
105 | | - 'CENTS = importlib.import_module("models.staging._sqlbuild._macros.cents")', |
| 105 | + 'CENTS = importlib.import_module("models.staging._sqlbuild._macros.python.cents")', |
106 | 106 | body=' assert CENTS.to_cents("1")\n', |
107 | 107 | ), |
108 | 108 | expected_location=f"{CENTS_CHECK}:6:9", |
109 | 109 | expected_reason=( |
110 | | - "imports models.staging._sqlbuild._macros.cents dynamically by name, which " |
| 110 | + "imports models.staging._sqlbuild._macros.python.cents dynamically by name, which " |
111 | 111 | "cannot be rewritten safely" |
112 | 112 | ), |
113 | 113 | ), |
114 | 114 | PythonImportRefusalE2ETestCase( |
115 | 115 | description="a star import from the macro module's package", |
116 | 116 | files=cents_check( |
117 | | - "from models.staging._sqlbuild._macros.cents import *\n" |
118 | | - "from models.staging._sqlbuild._macros import *" |
| 117 | + "from models.staging._sqlbuild._macros.python.cents import *\n" |
| 118 | + "from models.staging._sqlbuild._macros.python import *" |
119 | 119 | ), |
120 | 120 | expected_location=f"{CENTS_CHECK}:5:1", |
121 | 121 | expected_reason=( |
122 | | - "star-imports the package of models.staging._sqlbuild._macros.cents, which moves" |
| 122 | + "star-imports the package of models.staging._sqlbuild._macros.python.cents, which moves" |
123 | 123 | ), |
124 | 124 | ), |
125 | 125 | PythonImportRefusalE2ETestCase( |
126 | 126 | description="an import without an alias", |
127 | 127 | files=cents_check( |
128 | | - "import models.staging._sqlbuild._macros.cents", |
129 | | - body=' assert models.staging._sqlbuild._macros.cents.to_cents("1")\n', |
| 128 | + "import models.staging._sqlbuild._macros.python.cents", |
| 129 | + body=' assert models.staging._sqlbuild._macros.python.cents.to_cents("1")\n', |
130 | 130 | ), |
131 | 131 | expected_location=f"{CENTS_CHECK}:4:8", |
132 | | - expected_reason="imports models.staging._sqlbuild._macros.cents without an alias", |
| 132 | + expected_reason="imports models.staging._sqlbuild._macros.python.cents without an alias", |
133 | 133 | ), |
134 | 134 | PythonImportRefusalE2ETestCase( |
135 | 135 | description="a project Python file that is not UTF-8", |
136 | | - files=cents_check("from models.staging._sqlbuild._macros.cents import to_cents"), |
| 136 | + files=cents_check("from models.staging._sqlbuild._macros.python.cents import to_cents"), |
137 | 137 | binary_files={"rules/legacy.py": b"LABEL = '\xe9'\n"}, |
138 | 138 | expected_location="rules/legacy.py", |
139 | 139 | expected_reason="this Python file cannot be read as UTF-8", |
|
0 commit comments