def test_append_line(self): """Append a line to a file """ tabfile = TabFile('test',self.fp,first_line_is_header=True,delimiter=',') line = 'chr3,10,9,8' tabfile.append(tabdata=line) self.assertEqual(str(tabfile[-1]),line)
def test_append_line_as_data(self): """Append a line to a file with data supplied as a list """ tabfile = TabFile('test',self.fp,first_line_is_header=True,delimiter=',') data = ['chr3','10','9','8'] tabfile.append(data=data) self.assertEqual(str(tabfile[-1]),','.join([str(x) for x in data]))
def test_add_tab_data_to_new_tabfile(self): """Test adding data as a tab-delimited line to a new empty TabFile """ data = 'chr1\t10000\t20000\t+' tabfile = TabFile() tabfile.append(tabdata=data) self.assertEqual(len(tabfile),1,"TabFile should now have one line") self.assertEqual(str(tabfile[0]),data)
def test_add_tab_data_to_new_tabfile(self): """Test adding data as a tab-delimited line to a new empty TabFile """ data = 'chr1\t10000\t20000\t+' tabfile = TabFile() tabfile.append(tabdata=data) self.assertEqual(len(tabfile), 1, "TabFile should now have one line") self.assertEqual(str(tabfile[0]), data)
def test_convert_values_to_type_append_tabdata(self): """Convert input values to appropriate types (e.g. integer) when appending tabdata """ tabfile = TabFile('test', self.fp, first_line_is_header=True) tabfile.append(tabdata="chr3\t5678\t7.9") for line in tabfile: self.assertTrue(isinstance(line[0], str)) self.assertTrue(isinstance(line[1], (int, long))) self.assertTrue(isinstance(line[2], float))
def test_convert_values_to_type_append_tabdata(self): """Convert input values to appropriate types (e.g. integer) when appending tabdata """ tabfile = TabFile('test',self.fp,first_line_is_header=True) tabfile.append(tabdata="chr3\t5678\t7.9") for line in tabfile: self.assertTrue(isinstance(line[0],str)) self.assertTrue(isinstance(line[1],(int,long))) self.assertTrue(isinstance(line[2],float))
def test_add_data_to_new_tabfile(self): """Test adding data as a list of items to a new empty TabFile """ data = ['chr1',10000,20000,'+'] tabfile = TabFile() tabfile.append(data=data) self.assertEqual(len(tabfile),1,"TabFile should now have one line") for i in range(len(data)): self.assertEqual(tabfile[0][i],data[i])
def test_add_data_to_new_tabfile(self): """Test adding data as a list of items to a new empty TabFile """ data = ['chr1', 10000, 20000, '+'] tabfile = TabFile() tabfile.append(data=data) self.assertEqual(len(tabfile), 1, "TabFile should now have one line") for i in range(len(data)): self.assertEqual(tabfile[0][i], data[i])
def test_convert_values_to_str_append_tabdata(self): """Convert all input values to strings when appending tabdata """ tabfile = TabFile('test',self.fp,first_line_is_header=True, convert=False) tabfile.append(tabdata="chr3\t5678\t7.9") for line in tabfile: for value in line: self.assertTrue(isinstance(value,str))
def test_convert_values_to_str_append_list(self): """Convert all input values to strings when appending a list """ tabfile = TabFile('test',self.fp,first_line_is_header=True, convert=False) tabfile.append(data=["chr3","5678","7.9"]) tabfile.append(data=["chr3",5678,7.9]) for line in tabfile: for value in line: self.assertTrue(isinstance(value,str))
def test_convert_values_to_type_append_list(self): """Convert input values to appropriate types (e.g. integer) when appending a list """ tabfile = TabFile('test', self.fp, first_line_is_header=True) tabfile.append(data=["chr3", "5678", "7.9"]) tabfile.append(data=["chr3", 5678, 7.9]) for line in tabfile: self.assertTrue(isinstance(line[0], str)) self.assertTrue(isinstance(line[1], (int, long))) self.assertTrue(isinstance(line[2], float))
def test_append_line_as_data(self): """Append a line to a file with data supplied as a list """ tabfile = TabFile('test', self.fp, first_line_is_header=True, delimiter=',') data = ['chr3', '10', '9', '8'] tabfile.append(data=data) self.assertEqual(str(tabfile[-1]), ','.join([str(x) for x in data]))
def test_append_line(self): """Append a line to a file """ tabfile = TabFile('test', self.fp, first_line_is_header=True, delimiter=',') line = 'chr3,10,9,8' tabfile.append(tabdata=line) self.assertEqual(str(tabfile[-1]), line)
def test_convert_values_to_type_append_list(self): """Convert input values to appropriate types (e.g. integer) when appending a list """ tabfile = TabFile('test',self.fp,first_line_is_header=True) tabfile.append(data=["chr3","5678","7.9"]) tabfile.append(data=["chr3",5678,7.9]) for line in tabfile: self.assertTrue(isinstance(line[0],str)) self.assertTrue(isinstance(line[1],(int,long))) self.assertTrue(isinstance(line[2],float))
def test_convert_values_to_str_append_tabdata(self): """Convert all input values to strings when appending tabdata """ tabfile = TabFile('test', self.fp, first_line_is_header=True, convert=False) tabfile.append(tabdata="chr3\t5678\t7.9") for line in tabfile: for value in line: self.assertTrue(isinstance(value, str))
def test_convert_values_to_str_append_list(self): """Convert all input values to strings when appending a list """ tabfile = TabFile('test', self.fp, first_line_is_header=True, convert=False) tabfile.append(data=["chr3", "5678", "7.9"]) tabfile.append(data=["chr3", 5678, 7.9]) for line in tabfile: for value in line: self.assertTrue(isinstance(value, str))
def test_append_tab_data_line(self): """Append a TabDataLine to a TabFile """ tabfile = TabFile('test',self.fp) self.assertEqual(len(tabfile),3) tabdataline = TabDataLine('chr1\t10000\t20000\t+') line = tabfile.append(tabdataline=tabdataline) self.assertEqual(len(tabfile),4) # Check new line is correct self.assertTrue(line is tabdataline)
def test_append_line_with_tab_data(self): """Append line to a TabFile populated from tabbed data """ data = 'chr1\t10000\t20000\t+' tabfile = TabFile('test',self.fp) self.assertEqual(len(tabfile),3) line = tabfile.append(tabdata=data) self.assertEqual(len(tabfile),4) # Check new line is correct self.assertTrue(str(line) == data)
def test_append_tab_data_line(self): """Append a TabDataLine to a TabFile """ tabfile = TabFile('test', self.fp) self.assertEqual(len(tabfile), 3) tabdataline = TabDataLine('chr1\t10000\t20000\t+') line = tabfile.append(tabdataline=tabdataline) self.assertEqual(len(tabfile), 4) # Check new line is correct self.assertTrue(line is tabdataline)
def test_append_empty_line(self): """Append a blank line to a TabFile """ tabfile = TabFile('test', self.fp) self.assertEqual(len(tabfile), 3) line = tabfile.append() self.assertEqual(len(tabfile), 4) # Check new line is empty for i in range(len(line)): self.assertTrue(str(line[i]) == '')
def test_append_empty_line(self): """Append a blank line to a TabFile """ tabfile = TabFile('test',self.fp) self.assertEqual(len(tabfile),3) line = tabfile.append() self.assertEqual(len(tabfile),4) # Check new line is empty for i in range(len(line)): self.assertTrue(str(line[i]) == '')
def test_append_line_with_tab_data(self): """Append line to a TabFile populated from tabbed data """ data = 'chr1\t10000\t20000\t+' tabfile = TabFile('test', self.fp) self.assertEqual(len(tabfile), 3) line = tabfile.append(tabdata=data) self.assertEqual(len(tabfile), 4) # Check new line is correct self.assertTrue(str(line) == data)
def test_append_line_with_data(self): """Append line to a TabFile populated with data """ data = ['chr1', 678, 901, 6.1] tabfile = TabFile('test', self.fp) self.assertEqual(len(tabfile), 3) line = tabfile.append(data=data) self.assertEqual(len(tabfile), 4) # Check new line is correct for i in range(len(data)): self.assertTrue(line[i] == data[i])
def test_append_line_with_data(self): """Append line to a TabFile populated with data """ data = ['chr1',678,901,6.1] tabfile = TabFile('test',self.fp) self.assertEqual(len(tabfile),3) line = tabfile.append(data=data) self.assertEqual(len(tabfile),4) # Check new line is correct for i in range(len(data)): self.assertTrue(line[i] == data[i])