Completed
Branch master (cebbe9)
by Chad
34:07 queued 19:22
created

test_utils   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 46
dl 0
loc 51
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B test_csv_to_pd() 0 43 3
1
import tempfile
2
import pandas as pd
3
import diff_classifier.utils as ut
4
import sys
5
from io import StringIO
6
import pandas.util.testing as pdt
7
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