Exemplo n.º 1
0
 def test_custom_quoted_pluck(self):
     p = Processor(fields=[0, 10, 11], quotechar='|', skip=1)
     output = [row for row in p.process(SAMPLE_CUSTOM_QUOTED_CSV)]
     expected = [['0200', '-35.277272', '149.117136'], ['0221', '-35.201372', '149.095065']]
     self.assertEqual(expected, output)
Exemplo n.º 2
0
import sys
from csvfilter import Processor


def contains_cheese(row):
    return 'cheese' in row 

processor = Processor(fields=[1,2,3])
processor.add_validator(contains_cheese)
generator = processor.process(sys.stdin)

for cheesy_row in generator:
    do_something(cheesy_row)
Exemplo n.º 3
0
 def test_single_col_plucking_with_skip(self):
     p = Processor(fields=[0], skip=1)
     output = [row for row in p.process(SAMPLE_CSV)]
     self.assertEqual([['d'], ['g']], output)
Exemplo n.º 4
0
 def test_pluck_with_pipes(self):
     p = Processor(fields=[0], delimiter='|')
     output = [row for row in p.process(SAMPLE_PSV)]
     self.assertEqual([['a'], ['d'], ['g']], output)
Exemplo n.º 5
0
 def test_single_col_dropping(self):
     p = Processor(fields=[1], invert=True)
     output = [row for row in p.process(SAMPLE_CSV)]
     self.assertEqual([['a', 'c'], ['d', 'f'], ['g', 'i']], output)
Exemplo n.º 6
0
 def test_multiple_col_dropping(self):
     p = Processor(fields=[0,2], invert=True)
     output = [row for row in p.process(SAMPLE_CSV)]
     self.assertEqual([['b'], ['e'], ['h']], output)
Exemplo n.º 7
0
 def test_multiple_col_plucking(self):
     p = Processor(fields=[0, 2])
     output = [row for row in p.process(SAMPLE_CSV)]
     self.assertEqual([['a', 'c'], ['d', 'f'], ['g', 'i']], output)
Exemplo n.º 8
0
 def test_multiple_col_plucking_with_reordering(self):
     p = Processor(fields=[2, 1])
     output = [row for row in p.process(SAMPLE_CSV)]
     self.assertEqual([['c', 'b'], ['f', 'e'], ['i', 'h']], output)
Exemplo n.º 9
0
 def test_validator(self):
     p = Processor()
     p.add_validator(lambda row: row[0] == 'a')
     output = [row for row in p.process(SAMPLE_CSV)]
     self.assertEqual([['a', 'b', 'c']], output)
Exemplo n.º 10
0
 def test_no_config_does_no_processing(self):
     p = Processor()
     output = [row for row in p.process(SAMPLE_CSV)]
     self.assertEqual([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']], output)
Exemplo n.º 11
0
import sys
from csvfilter import Processor


def contains_cheese(row):
    return 'cheese' in row


processor = Processor(fields=[1, 2, 3])
processor.add_validator(contains_cheese)
generator = processor.process(sys.stdin)

for cheesy_row in generator:
    do_something(cheesy_row)
Exemplo n.º 12
0
 def test_tab_delimited_input(self):
     p = Processor(delimiter="\t")
     output = [row for row in p.process(SAMPLE_TSV)]
     self.assertEqual([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']],
                      output)
Exemplo n.º 13
0
 def test_tab_delimited_input(self):
     p = Processor(delimiter="\t")
     output = [row for row in p.process(SAMPLE_TSV)]
     self.assertEqual([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']],
                      output)