|
15 | 15 | assert_balanced_js_delimiters, |
16 | 16 | convert_decimals_to_floats, |
17 | 17 | convert_floats_to_decimals, |
18 | | - load_data, |
19 | 18 | serialize_datetime, |
20 | 19 | resolve_dotted_path, |
21 | 20 | get_text_from_html, |
22 | 21 | apply_params, |
23 | 22 | extract_object_schema, |
24 | 23 | ) |
25 | | -from bluebox.utils.exceptions import UnsupportedFileFormat |
26 | 24 |
|
27 | 25 |
|
28 | 26 | class TestGetTextFromHtml: |
@@ -313,106 +311,6 @@ def test_preserves_text_structure(self): |
313 | 311 | assert result == "Title\nParagraph 1\nParagraph 2" |
314 | 312 |
|
315 | 313 |
|
316 | | -class TestLoadData: |
317 | | - """Test cases for the load_data function.""" |
318 | | - |
319 | | - def test_load_dict_data(self, input_data_dir: Path) -> None: |
320 | | - """Test loading a JSON file containing a dictionary.""" |
321 | | - file_path = input_data_dir / "sample_dict.json" |
322 | | - result = load_data(file_path) |
323 | | - |
324 | | - assert isinstance(result, dict) |
325 | | - assert result["name"] == "John Doe" |
326 | | - assert result["age"] == 30 |
327 | | - assert result["city"] == "New York" |
328 | | - assert result["is_active"] is True |
329 | | - assert result["scores"] == [85.5, 92.0, 78.5] |
330 | | - assert result["metadata"]["created_at"] == "2023-01-15T10:30:00" |
331 | | - assert result["metadata"]["version"] == 1.2 |
332 | | - assert result["metadata"]["tags"] == ["test", "sample"] |
333 | | - |
334 | | - def test_load_list_data(self, input_data_dir: Path) -> None: |
335 | | - """Test loading a JSON file containing a list.""" |
336 | | - file_path = input_data_dir / "sample_list.json" |
337 | | - result = load_data(file_path) |
338 | | - |
339 | | - assert isinstance(result, list) |
340 | | - assert len(result) == 3 |
341 | | - assert result[0]["id"] == 1 |
342 | | - assert result[0]["name"] == "Item 1" |
343 | | - assert result[0]["price"] == 19.99 |
344 | | - assert result[1]["id"] == 2 |
345 | | - assert result[2]["id"] == 3 |
346 | | - |
347 | | - def test_load_empty_dict(self, input_data_dir: Path) -> None: |
348 | | - """Test loading an empty JSON file.""" |
349 | | - file_path = input_data_dir / "empty.json" |
350 | | - result = load_data(file_path) |
351 | | - |
352 | | - assert isinstance(result, dict) |
353 | | - assert result == {} |
354 | | - |
355 | | - def test_load_unsupported_file_format(self, input_data_dir: Path) -> None: |
356 | | - """Test that UnsupportedFileFormat is raised for unsupported file types.""" |
357 | | - file_path = input_data_dir / "unsupported.txt" |
358 | | - |
359 | | - with pytest.raises(UnsupportedFileFormat) as exc_info: |
360 | | - load_data(file_path) |
361 | | - |
362 | | - assert "No support for provided file type" in str(exc_info.value) |
363 | | - assert "unsupported.txt" in str(exc_info.value) |
364 | | - |
365 | | - def test_load_nonexistent_file(self, input_data_dir: Path) -> None: |
366 | | - """Test that FileNotFoundError is raised for nonexistent files.""" |
367 | | - file_path = input_data_dir / "nonexistent.json" |
368 | | - |
369 | | - with pytest.raises(FileNotFoundError): |
370 | | - load_data(file_path) |
371 | | - |
372 | | - def test_load_with_path_object(self, input_data_dir: Path) -> None: |
373 | | - """Test that function works with Path objects.""" |
374 | | - file_path = input_data_dir / "sample_dict.json" |
375 | | - result = load_data(file_path) |
376 | | - |
377 | | - assert isinstance(result, dict) |
378 | | - assert result["name"] == "John Doe" |
379 | | - |
380 | | - def test_load_jsonl(self, tmp_path: Path) -> None: |
381 | | - """Test loading a JSONL file returns list of dicts.""" |
382 | | - file_path = tmp_path / "data.jsonl" |
383 | | - file_path.write_text( |
384 | | - '{"id": 1, "name": "Alice"}\n' |
385 | | - '{"id": 2, "name": "Bob"}\n' |
386 | | - ) |
387 | | - result = load_data(file_path) |
388 | | - |
389 | | - assert isinstance(result, list) |
390 | | - assert len(result) == 2 |
391 | | - assert result[0]["name"] == "Alice" |
392 | | - assert result[1]["id"] == 2 |
393 | | - |
394 | | - def test_load_jsonl_empty_file(self, tmp_path: Path) -> None: |
395 | | - """Test loading an empty JSONL file returns empty list.""" |
396 | | - file_path = tmp_path / "empty.jsonl" |
397 | | - file_path.write_text("") |
398 | | - result = load_data(file_path) |
399 | | - |
400 | | - assert result == [] |
401 | | - |
402 | | - def test_load_jsonl_skips_blank_lines(self, tmp_path: Path) -> None: |
403 | | - """Test that blank lines in JSONL are skipped.""" |
404 | | - file_path = tmp_path / "data.jsonl" |
405 | | - file_path.write_text('{"a": 1}\n\n\n{"b": 2}\n') |
406 | | - result = load_data(file_path) |
407 | | - |
408 | | - assert len(result) == 2 |
409 | | - |
410 | | - def test_load_jsonl_nonexistent(self, tmp_path: Path) -> None: |
411 | | - """Test that FileNotFoundError is raised for nonexistent JSONL files.""" |
412 | | - with pytest.raises(FileNotFoundError): |
413 | | - load_data(tmp_path / "missing.jsonl") |
414 | | - |
415 | | - |
416 | 314 | class TestConvertFloatsToDecimals: |
417 | 315 | """Test cases for the convert_floats_to_decimals function.""" |
418 | 316 |
|
|
0 commit comments