()
| 110 | |
| 111 | @dlt.source(section="mock_data_source_state") |
| 112 | def mock_data_source_state(): |
| 113 | @dlt.resource(selected=True) |
| 114 | def _r_init(): |
| 115 | assert is_running_in_airflow_task() is True, "Must be running in Airflow task" |
| 116 | # will switch to spawn on Airflow |
| 117 | assert get_default_start_method("fork") == "spawn" |
| 118 | |
| 119 | dlt.current.source_state()["counter"] = 1 |
| 120 | dlt.current.source_state()["end_counter"] = 1 |
| 121 | yield ["-", "x", "!"] |
| 122 | |
| 123 | @dlt.resource(selected=False) |
| 124 | def _r1(): |
| 125 | dlt.current.source_state()["counter"] += 1 |
| 126 | dlt.current.resource_state()["counter"] = 1 |
| 127 | yield from ["a", "b", "c"] |
| 128 | |
| 129 | @dlt.transformer(data_from=_r1, selected=True) |
| 130 | def _t1(items, suffix): |
| 131 | dlt.current.source_state()["counter"] += 1 |
| 132 | dlt.current.resource_state("_r1")["counter"] += 1 |
| 133 | dlt.current.resource_state()["counter"] = 1 |
| 134 | yield list(map(lambda i: i + "_" + suffix, items)) |
| 135 | |
| 136 | @dlt.transformer(data_from=_r1) |
| 137 | def _t2(items, mul): |
| 138 | dlt.current.source_state()["counter"] += 1 |
| 139 | dlt.current.resource_state("_r1")["counter"] += 1 |
| 140 | dlt.current.resource_state()["counter"] = 1 |
| 141 | yield items * mul |
| 142 | |
| 143 | @dlt.transformer(data_from=_r1) |
| 144 | def _t3(items, mul): |
| 145 | dlt.current.source_state()["counter"] += 1 |
| 146 | dlt.current.resource_state("_r1")["counter"] += 1 |
| 147 | dlt.current.resource_state()["counter"] = 1 |
| 148 | for item in items: |
| 149 | yield item.upper() * mul |
| 150 | |
| 151 | # add something to init |
| 152 | @dlt.transformer(data_from=_r_init) |
| 153 | def _t_init_post(items): |
| 154 | for item in items: |
| 155 | yield item * 2 |
| 156 | |
| 157 | @dlt.resource |
| 158 | def _r_isolee(): |
| 159 | dlt.current.source_state()["end_counter"] += 1 |
| 160 | yield from ["AX", "CV", "ED"] |
| 161 | |
| 162 | return _r_init, _t_init_post, _r1, _t1("POST"), _t2(3), _t3(2), _r_isolee |
| 163 | |
| 164 | |
| 165 | def test_regular_run() -> None: |
no test coverage detected