Example #1
0
def grep():
    grepio = StringIO()
    grepargs = ["-a", "-c", "1-77", "-r", "TRUMP|BIDEN", SRC_PATH]
    grep = CSVGrep(grepargs, grepio)
    grep.run()
    grep_output = grepio.getvalue()
    grep_lines = grep_output.splitlines()
Example #2
0
    def test_string_match(self):
        args = [
            '-c', '1', '-m', 'ILLINOIS',
            'examples/realdata/FY09_EDU_Recipients_by_State.csv'
        ]
        output_file = six.StringIO()
        utility = CSVGrep(args, output_file)

        utility.main()

        input_file = six.StringIO(output_file.getvalue())
        reader = agate.reader(input_file)

        self.assertEqual(next(reader), [
            'State Name', 'State Abbreviate', 'Code',
            'Montgomery GI Bill-Active Duty',
            'Montgomery GI Bill- Selective Reserve',
            'Dependents\' Educational Assistance',
            'Reserve Educational Assistance Program',
            'Post-Vietnam Era Veteran\'s Educational Assistance Program',
            'TOTAL', ''
        ])
        self.assertEqual(next(reader), [
            'ILLINOIS', 'IL', '17', '15,659', '2,491', '2,025', '1,770', '19',
            '21,964', ''
        ])
Example #3
0
    def test_no_match(self):
        args = ['-c', '1', '-m', 'NO MATCH', 'examples/dummy.csv']
        output_file = six.StringIO()
        utility = CSVGrep(args, output_file)

        utility.main()

        input_file = six.StringIO(output_file.getvalue())
        reader = agate.reader(input_file)

        self.assertEqual(next(reader), ['a', 'b', 'c'])
Example #4
0
    def test_no_match(self):
        args = ['-c', '1', '-m', 'NO MATCH', 'examples/dummy.csv']
        output_file = six.StringIO()
        utility = CSVGrep(args, output_file)

        utility.main()

        input_file = six.StringIO(output_file.getvalue())
        reader = CSVKitReader(input_file)

        self.assertEqual(next(reader), ['a', 'b', 'c'])
Example #5
0
    def test_display_column_names(self):
        args = ['-n', 'examples/realdata/FY09_EDU_Recipients_by_State.csv']
        output_file = six.StringIO()

        utility = CSVGrep(args, output_file)
        utility.main()

        input_file = six.StringIO(output_file.getvalue())
        reader = agate.reader(input_file)

        self.assertEqual(next(reader), ['  1: State Name'])
        self.assertEqual(next(reader), ['  2: State Abbreviate'])
Example #6
0
    def test_display_column_names(self):
        args = ['-n', 'examples/realdata/FY09_EDU_Recipients_by_State.csv']
        output_file = six.StringIO()

        utility = CSVGrep(args, output_file)
        utility.main()

        input_file = six.StringIO(output_file.getvalue())
        reader = CSVKitReader(input_file)

        self.assertEqual(next(reader), ['  1: State Name'])
        self.assertEqual(next(reader), ['  2: State Abbreviate'])
Example #7
0
    def test_string_match(self):
        args = ['-c', '1', '-m', 'ILLINOIS', 'examples/realdata/FY09_EDU_Recipients_by_State.csv']
        output_file = six.StringIO()
        utility = CSVGrep(args, output_file)

        utility.main()

        input_file = six.StringIO(output_file.getvalue())
        reader = CSVKitReader(input_file)

        self.assertEqual(next(reader), ['State Name', 'State Abbreviate', 'Code', 'Montgomery GI Bill-Active Duty', 'Montgomery GI Bill- Selective Reserve', 'Dependents\' Educational Assistance', 'Reserve Educational Assistance Program', 'Post-Vietnam Era Veteran\'s Educational Assistance Program', 'TOTAL', ''])
        self.assertEqual(next(reader), ['ILLINOIS', 'IL', '17', '15,659', '2,491', '2,025', '1,770', '19', '21,964', ''])
Example #8
0
    def test_re_match(self):
        args = ['-c', '3', '-r', '^(3|9)$', 'examples/dummy.csv']
        output_file = StringIO.StringIO()
        utility = CSVGrep(args, output_file)

        utility.main()

        input_file = StringIO.StringIO(output_file.getvalue())
        reader = CSVKitReader(input_file)

        self.assertEqual(reader.next(), ['a', 'b', 'c'])
        self.assertEqual(reader.next(), ['1', '2', '3'])
Example #9
0
    def test_re_match(self):
        args = ['-c', '3', '-r', '^(3|9)$', 'examples/dummy.csv']
        output_file = StringIO.StringIO()
        utility = CSVGrep(args, output_file)

        utility.main()

        input_file = StringIO.StringIO(output_file.getvalue())
        reader = CSVKitReader(input_file)

        self.assertEqual(reader.next(), ['a', 'b', 'c'])
        self.assertEqual(reader.next(), ['1', '2', '3'])
Example #10
0
    def test_invalid_column(self):
        args = ['-c', '0', '-m', '1', 'examples/dummy.csv']
        output_file = six.StringIO()
        utility = CSVGrep(args, output_file)

        self.assertRaises(ColumnIdentifierError, utility.main)