|
2 | 2 |
|
3 | 3 | import base64 |
4 | 4 | import io |
5 | | -import json |
6 | 5 |
|
7 | 6 | import pytest |
8 | 7 |
|
9 | 8 | from rlm.utils.dataframe_utils import ( |
10 | | - build_context_code, |
11 | 9 | build_dataframe_context_code, |
12 | 10 | dataframe_metadata, |
13 | 11 | dataframe_to_parquet_b64, |
@@ -157,81 +155,3 @@ def test_custom_var_name(self): |
157 | 155 | exec(code, ns) |
158 | 156 | assert "my_df" in ns |
159 | 157 | assert ns["my_df"]["v"].tolist() == [1] |
160 | | - |
161 | | - |
162 | | -# --------------------------------------------------------------------------- |
163 | | -# Unified dispatch — build_context_code() |
164 | | -# --------------------------------------------------------------------------- |
165 | | - |
166 | | - |
167 | | -class TestBuildContextCode: |
168 | | - """Tests for the unified build_context_code() dispatcher.""" |
169 | | - |
170 | | - def test_string_payload(self): |
171 | | - code = build_context_code("hello world") |
172 | | - ns = {} |
173 | | - exec(code, ns) |
174 | | - assert ns["context"] == "hello world" |
175 | | - |
176 | | - def test_dict_payload(self): |
177 | | - payload = {"key": "value", "num": 42} |
178 | | - code = build_context_code(payload) |
179 | | - ns = {} |
180 | | - exec(code, ns) |
181 | | - assert ns["context"] == payload |
182 | | - |
183 | | - def test_list_payload(self): |
184 | | - payload = [1, 2, "three"] |
185 | | - code = build_context_code(payload) |
186 | | - ns = {} |
187 | | - exec(code, ns) |
188 | | - assert ns["context"] == payload |
189 | | - |
190 | | - def test_dataframe_payload(self): |
191 | | - pd = pytest.importorskip("pandas") |
192 | | - df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}) |
193 | | - code = build_context_code(df) |
194 | | - ns = {} |
195 | | - exec(code, ns) |
196 | | - assert ns["context"]["a"].tolist() == [1, 2] |
197 | | - assert ns["context"]["b"].tolist() == [3, 4] |
198 | | - |
199 | | - def test_empty_string(self): |
200 | | - code = build_context_code("") |
201 | | - ns = {} |
202 | | - exec(code, ns) |
203 | | - assert ns["context"] == "" |
204 | | - |
205 | | - def test_empty_dict(self): |
206 | | - code = build_context_code({}) |
207 | | - ns = {} |
208 | | - exec(code, ns) |
209 | | - assert ns["context"] == {} |
210 | | - |
211 | | - def test_empty_list(self): |
212 | | - code = build_context_code([]) |
213 | | - ns = {} |
214 | | - exec(code, ns) |
215 | | - assert ns["context"] == [] |
216 | | - |
217 | | - def test_special_chars_in_string(self): |
218 | | - payload = 'He said "hello" and she said \'goodbye\'\nNew line\ttab' |
219 | | - code = build_context_code(payload) |
220 | | - ns = {} |
221 | | - exec(code, ns) |
222 | | - assert ns["context"] == payload |
223 | | - |
224 | | - def test_custom_var_name(self): |
225 | | - code = build_context_code("data", var_name="my_var") |
226 | | - ns = {} |
227 | | - exec(code, ns) |
228 | | - assert ns["my_var"] == "data" |
229 | | - assert "context" not in ns |
230 | | - |
231 | | - def test_nested_dict(self): |
232 | | - payload = {"outer": {"inner": [1, 2, 3]}, "flag": True} |
233 | | - code = build_context_code(payload) |
234 | | - ns = {} |
235 | | - exec(code, ns) |
236 | | - assert ns["context"]["outer"]["inner"] == [1, 2, 3] |
237 | | - assert ns["context"]["flag"] is True |
0 commit comments