Exemplo n.º 1
0
 def test_removing_idx(idx):
     munge.remove_col_big_data(
         sample_file, sample_file_delcol, [idx], delimiter='\t')
     data1 = []
     with open(sample_file) as f:
         for line in f:
             row = line.strip().split()
             del row[idx]
             data1.append(row)
     data2 = []
     with open(sample_file_delcol) as f:
         for line in f:
             data2.append(line.strip().split())
     self.assertEqual(data1, data2)
Exemplo n.º 2
0
    def test_remove_col_big_data(self):
        sample_file = os.path.join(self.curdir, 'res', 'sample1.txt')
        sample_file_delcol = os.path.join(
            self.curdir, 'res', 'sample1.delcol.txt')

        def test_removing_idx(idx):
            munge.remove_col_big_data(
                sample_file, sample_file_delcol, [idx], delimiter='\t')
            data1 = []
            with open(sample_file) as f:
                for line in f:
                    row = line.strip().split()
                    del row[idx]
                    data1.append(row)
            data2 = []
            with open(sample_file_delcol) as f:
                for line in f:
                    data2.append(line.strip().split())
            self.assertEqual(data1, data2)

        for col in range(3):
            test_removing_idx(col)

        # Delete file created
        os.remove(sample_file_delcol)

        # Test removing two columns
        sample_file = os.path.join(self.curdir, 'res', 'sample1.txt')
        sample_file_delcol = os.path.join(self.curdir, 'res', 'sample1.delcol.txt')
        munge.remove_col_big_data(sample_file, sample_file_delcol, [0,2], delimiter='\t')
        data1 = []
        with open(sample_file) as f:
            for line in f:
                row = line.strip().split()
                data1.append([row[1]])
        data2 = []
        with open(sample_file_delcol) as f:
            for line in f:
                data2.append(line.strip().split())
        self.assertEqual(data1, data2)
        os.remove(sample_file_delcol)