Exemplo n.º 1
0
 def test_preprocess_filters_too_many_filters_for_col(self):
     # two filter args for col `first`
     args = [
         "foo|num", "fake|add:1", "first|replace:a,b", "first|num|trunc"
     ]
     with self.assertRaises(FilterError):
         t = preprocess_filters(args)
Exemplo n.º 2
0
    def test_preprocess_filters_more_args(self):
        args = ["foo|num", "fake|add:1", "first|replace:a,b"]
        expected = {
            "foo": [["num"]],
            "fake": [["add", "1"]],
            "first": [["replace", "a", "b"]]
        }

        t = preprocess_filters(args)
        self.assertEqual(expected, t)
Exemplo n.º 3
0
    def test_preprocess_filters_replace(self):
        args = ["foo|num", "fake|add:1", "first|format:08[:comma:].1f"]
        expected = {
            "foo": [["num"]],
            "fake": [["add", "1"]],
            "first": [["format", "08,.1f"]]
        }

        t = preprocess_filters(args)
        self.assertEqual(expected, t)
Exemplo n.º 4
0
    def test_preprocess_filters_simple(self):
        args = ["foo|num", "fake|add:1", "first|num|add:1"]
        expected = {
            "foo": [["num"]],
            "fake": [["add", "1"]],
            "first": [["num"], ["add", "1"]]
        }

        t = preprocess_filters(args)
        self.assertEqual(expected, t)
Exemplo n.º 5
0
def main(args=None):
    global DEBUG
    if args is None:
        args = sys.argv[1:]

    parser = build_args_parser()
    args = parser.parse_args(args=args)
    DEBUG = args.debug
    debug(args, 'args=')

    if args.filters_list:
        print_filter_list_table(args.output_format)
        return 0

    if args.replacements_list:
        print_replacements_table(args.output_format)
        return 0

    if not args.sql:
        raise Error("You must specify the SQL to execute.")

    # Process table re-mappings, if any
    table_remapping = process_table_remapping(args.remap_table)
    debug(table_remapping, 'table_remapping=')

    # Pre-process the filters
    filters = preprocess_filters(args.filter)
    debug(filters, 'filters=')

    # Process the column re-mappings, if any
    column_remapping = process_column_remapping(args.remap_column)
    debug(column_remapping, 'column_remapping=')

    # Process delimiters
    input_delimiter = apply_char_replacements(args.input_delimiter)

    execute(args.sql,
            headers=args.headers,
            filters=filters,
            output=args.output,
            output_format=args.output_format,
            skip_lines=args.skip_lines,
            output_delimiter=',',
            column_remapping=column_remapping,
            table_remapping=table_remapping,
            auto_filter=args.auto_filter,
            save_db=args.save_db,
            load_db=args.load_db,
            input_format=args.input_format,
            input_delimiter=input_delimiter,
            input_encoding=args.input_encoding,
            debug_=args.debug)
    return 0
Exemplo n.º 6
0
 def test_preprocess_filters_bad_filter(self):
     args = ["foo|num", "fake|add:1", "firstbadfilter:a,b"]
     with self.assertRaises(FilterError):
         t = preprocess_filters(args)