예제 #1
0
 def test_04_file_load_list(self):
     f = cl.TextFile(self.fname)
     lst = f.load_file_to_list()
     self.assertEqual(len(lst), 3) 
     # now try with a dud file
     f_dud = cl.TextFile('blahdfgkjdlfgkjldkfgj.txt')
     self.assertEqual(len(f_dud.load_file_to_string()), 0)
예제 #2
0
 def test_10_count_line_in_file(self):
     t10 = cl.TextFile('chr31_delimited_data_file.csv')
     self.assertEqual(t10.count_lines_in_file(), 4)
     
     # check for non file
     t_fail = cl.TextFile('no such filename')
     self.assertEqual(t_fail.count_lines_in_file(), 0)
예제 #3
0
 def test_03_file_load_string(self):
     f = cl.TextFile(self.fname)
     txt = f.load_file_to_string()
     self.assertEqual(len(txt), 68) 
     
     # now try with a dud file
     f_dud = cl.TextFile('blahdfgkjdlfgkjldkfgj.txt')
     self.assertEqual(f_dud.load_file_to_string(), '')
예제 #4
0
 def test_12_get_file_sample(self):
     t11 = cl.TextFile(self.fname)
     self.assertEqual(t11.get_file_sample(1), '00000 # test file for cls_file\n')
     self.assertEqual(len(t11.get_file_sample(999)), 86)  # returns full sample file
     
     # check for non file
     t_fail = cl.TextFile('no such filename')
     self.assertEqual(t_fail.get_file_sample(1), '')
예제 #5
0
    def test_08_convert_to_csv(self):
        chr31_delimited_data = """D20130611000920130611PCFile0122 15UsageFacebook - Google Chrome
D20130611001020130611PCFile0123 1UsageGoogle - Google Chrome
D20130611001120130611PCFile0400 61UsageDesktop
D20130611001220130611PCFile0500 60UsageDesktop
"""
        with open('chr31_delimited_data_file.dat', 'w') as d:
            d.write(chr31_delimited_data)
            
        f = cl.TextFile('chr31_delimited_data_file.dat')
        #self.assertEqual(f.get_file_sample(1), '00000 D20130611000920130611PCFile0122 15UsageFacebook - Google Chrome')
        
        f.convert_to_csv('chr31_delimited_data_file.csv', chr(31))
        
        f_csv = cl.TextFile('chr31_delimited_data_file.csv')
        self.assertEqual(f_csv.get_file_sample(1), '00000 "D201306110009","20130611","PCFile","0122"," 15","Usage","","","","","","","","","Facebook - Google Chrome",""\n')
예제 #6
0
 def test_01_file_create(self):
     self.assertEqual(1, 1)  # dummy
     f = cl.TextFile(self.fname)
     f.delete()
     f.append_text('# test file for cls_file\n')
     f.append_text('this is the 2nd line\n')
     f.append_text('this is the last line\n')
예제 #7
0
 def test_07_get_file_sample(self):
     f = cl.TextFile(self.fname)
     self.assertTrue(len(str(f)) > 10)
     sample = f.get_file_sample(2)
     self.assertEqual(len(sample.split('\n')) - 1, 2)