Skip to content

Commit

Permalink
upload data loader testing
Browse files Browse the repository at this point in the history
  • Loading branch information
astridesa committed Nov 10, 2024
1 parent cd1eb8f commit 7fbf2c7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions data/test_data_loading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pytest
import json


@pytest.fixture
def load_data():
with open("function_calling_demo.jsonl", "r", encoding="utf8") as f:
data_list = f.readlines()
return data_list


def test_data_loading(load_data):
# Verify data was loaded correctly
assert load_data is not None, "Data should be loaded"
assert len(load_data) > 0, "Data list should not be empty"

# Verify each line is a valid JSON with required fields
for line in load_data:
try:
data = json.loads(line)
assert isinstance(
data, dict
), "Each line should be a JSON object (dictionary)"

# Check for "conversations" key
assert (
"conversations" in data
), "'conversations' key is missing in the JSON object"
assert isinstance(
data["conversations"], list
), "'conversations' should be a list"

# Check for 'user' and 'assistant' roles within "conversations"
roles = {conv["role"] for conv in data["conversations"] if "role" in conv}
assert "user" in roles, "Role 'user' is missing in conversations"
assert "assistant" in roles, "Role 'assistant' is missing in conversations"

except json.JSONDecodeError:
pytest.fail("Each line in the data file should be valid JSON")

0 comments on commit 7fbf2c7

Please sign in to comment.