Skip to content

fix(tests): use temp file for dataset #8237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions tests/datasets/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import tempfile
import unittest
import uuid

Expand All @@ -11,9 +12,6 @@
"This is content 2","What is that?","This is answer 2"
"""

with open("dummy.csv", "w") as file:
file.write(dummy_data)


class CSVDataset(Dataset):
def __init__(self, file_path, input_keys=None, *args, **kwargs) -> None:
Expand All @@ -32,17 +30,18 @@ def __init__(self, file_path, input_keys=None, *args, **kwargs) -> None:

class TestCSVDataset(unittest.TestCase):
def test_input_keys(self):
dataset = CSVDataset("dummy.csv", input_keys=["content", "question"])
self.assertIsNotNone(dataset.train)

for example in dataset.train:
print(example)
inputs = example.inputs()
print(f"Example inputs: {inputs}")
self.assertIsNotNone(inputs)
self.assertIn("content", inputs)
self.assertIn("question", inputs)
self.assertEqual(set(example._input_keys), {"content", "question"})
with tempfile.NamedTemporaryFile(mode="w+", suffix=".csv") as tmp_file:
tmp_file.write(dummy_data)
tmp_file.flush()
dataset = CSVDataset(tmp_file.name, input_keys=["content", "question"])
self.assertIsNotNone(dataset.train)

for example in dataset.train:
inputs = example.inputs()
self.assertIsNotNone(inputs)
self.assertIn("content", inputs)
self.assertIn("question", inputs)
self.assertEqual(set(example._input_keys), {"content", "question"})


if __name__ == "__main__":
Expand Down