1
+ import tempfile
1
2
import unittest
2
3
import uuid
3
4
11
12
"This is content 2","What is that?","This is answer 2"
12
13
"""
13
14
14
- with open ("dummy.csv" , "w" ) as file :
15
- file .write (dummy_data )
16
-
17
15
18
16
class CSVDataset (Dataset ):
19
17
def __init__ (self , file_path , input_keys = None , * args , ** kwargs ) -> None :
@@ -32,17 +30,18 @@ def __init__(self, file_path, input_keys=None, *args, **kwargs) -> None:
32
30
33
31
class TestCSVDataset (unittest .TestCase ):
34
32
def test_input_keys (self ):
35
- dataset = CSVDataset ("dummy.csv" , input_keys = ["content" , "question" ])
36
- self .assertIsNotNone (dataset .train )
37
-
38
- for example in dataset .train :
39
- print (example )
40
- inputs = example .inputs ()
41
- print (f"Example inputs: { inputs } " )
42
- self .assertIsNotNone (inputs )
43
- self .assertIn ("content" , inputs )
44
- self .assertIn ("question" , inputs )
45
- self .assertEqual (set (example ._input_keys ), {"content" , "question" })
33
+ with tempfile .NamedTemporaryFile (mode = "w+" , suffix = ".csv" ) as tmp_file :
34
+ tmp_file .write (dummy_data )
35
+ tmp_file .flush ()
36
+ dataset = CSVDataset (tmp_file .name , input_keys = ["content" , "question" ])
37
+ self .assertIsNotNone (dataset .train )
38
+
39
+ for example in dataset .train :
40
+ inputs = example .inputs ()
41
+ self .assertIsNotNone (inputs )
42
+ self .assertIn ("content" , inputs )
43
+ self .assertIn ("question" , inputs )
44
+ self .assertEqual (set (example ._input_keys ), {"content" , "question" })
46
45
47
46
48
47
if __name__ == "__main__" :
0 commit comments