Conditions | 3 |
Total Lines | 43 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import tempfile |
||
8 | def test_csv_to_pd(): |
||
9 | tf = tempfile.NamedTemporaryFile(suffix=".csv") |
||
10 | fid = open(tf.name, 'w') |
||
11 | fid.write("This file won't work. \n This file won't work. \n This file won't work.") |
||
12 | fid.close() |
||
13 | |||
14 | stdout_ = sys.stdout |
||
15 | stream = StringIO() |
||
16 | sys.stdout = stream |
||
17 | test = ut.csv_to_pd(tf.name) |
||
18 | sys.stdout = stdout_ |
||
19 | variable = stream.getvalue() |
||
20 | test_string = 'No data in csv file.\n' |
||
21 | assert(variable==test_string) |
||
22 | |||
23 | d = {'Track_ID': [], |
||
24 | 'Spot_ID': [], |
||
25 | 'Frame': [], |
||
26 | 'X': [], |
||
27 | 'Y': [], |
||
28 | 'Quality': [], |
||
29 | 'SN_Ratio': [], |
||
30 | 'Mean_Intensity': []} |
||
31 | cols = ['Track_ID', 'Spot_ID', 'Frame', 'X', 'Y', 'Quality', 'SN_Ratio', 'Mean_Intensity'] |
||
32 | data = pd.DataFrame(data=d, index=[]) |
||
33 | data = data[cols] |
||
34 | data = data.astype('float64') |
||
35 | pdt.assert_frame_equal(test, data) |
||
36 | |||
37 | tf = tempfile.NamedTemporaryFile(suffix=".csv") |
||
38 | fid = open(tf.name, 'w') |
||
39 | fid.write('Found 0 tracks.\nData starts here.\nTrack_ID,Spot_ID,Frame,X,Y,Quality,SN_Ratio,Mean_Intensity\n') |
||
40 | fid.close() |
||
41 | |||
42 | stdout_ = sys.stdout |
||
43 | stream = StringIO() |
||
44 | sys.stdout = stream |
||
45 | test = ut.csv_to_pd(tf.name) |
||
46 | sys.stdout = stdout_ |
||
47 | variable = stream.getvalue() |
||
48 | test_string = '' |
||
49 | assert(variable==test_string) |
||
50 | pdt.assert_frame_equal(test, data) |
||
51 |