Skip to content

Commit 0e5f82d

Browse files
committed
unit tests for toonify
1 parent 45aafe2 commit 0e5f82d

File tree

9 files changed

+173
-170
lines changed

9 files changed

+173
-170
lines changed

bluebox/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
BrowserConnectionError,
5050
TransactionIdentificationFailedError,
5151
LLMStructuredOutputError,
52-
UnsupportedFileFormat,
5352
)
5453

5554
# Core modules (for advanced usage)
@@ -82,7 +81,6 @@
8281
"BrowserConnectionError",
8382
"TransactionIdentificationFailedError",
8483
"LLMStructuredOutputError",
85-
"UnsupportedFileFormat",
8684
# Core modules
8785
"agents",
8886
"cdp",

bluebox/utils/data_utils.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
Data loading, writing, and transformation utilities.
55
66
Contains:
7-
- load_data(): Load JSON/JSONL files
87
- write_json_file(), write_jsonl(): Save data to files
98
- get_text_from_html(): Extract text from HTML
109
- resolve_dotted_path(): Access nested dict values by dot notation
@@ -30,39 +29,11 @@
3029
import tldextract
3130
from bs4 import BeautifulSoup
3231

33-
from bluebox.utils.exceptions import UnsupportedFileFormat
3432
from bluebox.utils.logger import get_logger
3533

3634
logger = get_logger(name=__name__)
3735

3836

39-
def load_data(file_path: Path) -> dict | list:
40-
"""
41-
Load data from a file.
42-
Raises:
43-
UnsupportedFileFormat: If the file is of an unsupported type.
44-
Args:
45-
file_path: Path to the JSON or JSONL file.
46-
Returns:
47-
dict | list: Data contained in file. JSONL files return a list of parsed objects.
48-
"""
49-
file_path_str = str(file_path)
50-
if file_path_str.endswith(".json"):
51-
with open(file_path_str, mode="r", encoding="utf-8") as data_file:
52-
return json.load(data_file)
53-
54-
if file_path_str.endswith(".jsonl"):
55-
records: list[Any] = []
56-
with open(file_path_str, mode="r", encoding="utf-8") as data_file:
57-
for line in data_file:
58-
line = line.strip()
59-
if line:
60-
records.append(json.loads(line))
61-
return records
62-
63-
raise UnsupportedFileFormat(f"No support for provided file type: {file_path_str}.")
64-
65-
6637
def convert_floats_to_decimals(obj: Any) -> Any:
6738
"""
6839
Convert all float values in a JSON-like object to Decimal values.

bluebox/utils/exceptions.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@
44
Custom exceptions for bluebox-sdk.
55
66
Contains:
7-
- UnsupportedFileFormat: Invalid file type
87
- ApiKeyNotFoundError: Missing API key
98
- BrowserConnectionError, ChromiumConnectionError: CDP connection failures
109
- NavigationError, NavigationBlockedError: Page navigation failures
1110
- RoutineExecutionError: Routine run failures
1211
- HTTPClientError, HTTPServerError: HTTP request failures
1312
"""
1413

15-
class UnsupportedFileFormat(Exception):
16-
"""
17-
Raised when encountering an unsupported file type for some operation.
18-
"""
19-
2014

2115
class ApiKeyNotFoundError(Exception):
2216
"""

tests/data/input/empty.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/data/input/sample_dict.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/data/input/sample_list.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/data/input/unsupported.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/unit/utils/test_data_utils.py

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
assert_balanced_js_delimiters,
1616
convert_decimals_to_floats,
1717
convert_floats_to_decimals,
18-
load_data,
1918
serialize_datetime,
2019
resolve_dotted_path,
2120
get_text_from_html,
2221
apply_params,
2322
extract_object_schema,
2423
)
25-
from bluebox.utils.exceptions import UnsupportedFileFormat
2624

2725

2826
class TestGetTextFromHtml:
@@ -313,106 +311,6 @@ def test_preserves_text_structure(self):
313311
assert result == "Title\nParagraph 1\nParagraph 2"
314312

315313

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-
416314
class TestConvertFloatsToDecimals:
417315
"""Test cases for the convert_floats_to_decimals function."""
418316

0 commit comments

Comments
 (0)