Beispiel #1
0
def run():
    args = ap.parse_args()

    if args.ls:
        print('\n'.join(parser.listPluginNames()))
        sys.exit(0)

    if args.verbose:
        structlog.configure(
            logger_factory=structlog.PrintLoggerFactory(sys.stderr))

    infile = BytesIO(sys.stdin.read())
    try:
        parsed = parse(infile, exclude=args.exclude)
    except NoWillingParsers:
        if args.strict:
            raise
        else:
            infile.seek(0)
            sys.stdout.write(infile.read())
            sys.exit(0)

    if args.format == 'yaml':
        print(yaml.safe_dump(parsed, default_flow_style=False))
    elif args.format == 'json':
        print(json.dumps(parsed))
    elif args.format == 'grep':
        from ppo.output import giganticGrep
        giganticGrep(parsed, sys.stdout)
Beispiel #2
0
def run():
    args = ap.parse_args()

    if args.ls:
        print('\n'.join(parser.listPluginNames()))
        sys.exit(0)

    if args.verbose:
        structlog.configure(logger_factory=structlog.PrintLoggerFactory(sys.stderr))

    infile = BytesIO(sys.stdin.read())
    try:
        parsed = parse(infile, exclude=args.exclude)
    except NoWillingParsers:
        if args.strict:
            raise
        else:
            infile.seek(0)
            sys.stdout.write(infile.read())
            sys.exit(0)

    if args.format == 'yaml':
        print(yaml.safe_dump(parsed, default_flow_style=False))
    elif args.format == 'json':
        print(json.dumps(parsed))
    elif args.format == 'grep':
        from ppo.output import giganticGrep
        giganticGrep(parsed, sys.stdout)
Beispiel #3
0
    def func(self):
        structlog.get_logger().msg(testcase=name)
        fh_i = io.open(infile, 'rb')
        parsed = parse(fh_i)
        
        expected_output = None
        if outfile is None:
            self.fail('No expected output file present')
        fh_o = io.open(outfile, 'rb')
        if outfile.endswith('yml'):
            expected_output = yaml.load(fh_o)
        elif outfile.endswith('json'):
            expected_output = json.load(fh_o)
        else:
            # plain text
            expected_output = io.open(outfile, 'rb').read()

        # seeing differences in YAML is easier than python dicts
        expected_yaml = yaml.safe_dump(expected_output, default_flow_style=False)
        actual_yaml = yaml.safe_dump(parsed, default_flow_style=False)
        diff = diffStrings(expected_yaml, actual_yaml, 'expected', 'actual')
        self.assertEqual(expected_yaml, actual_yaml, '\n' + ''.join(diff))
Beispiel #4
0
    def func(self):
        structlog.get_logger().msg(testcase=name)
        with io.open(infile, 'rb') as fh_i:
            parsed = parse(fh_i)

        expected_output = None
        if outfile is None:
            self.fail('No expected output file present')
        with io.open(outfile, 'rb') as fh_o:
            if outfile.endswith('yml'):
                expected_output = yaml.load(fh_o)
            elif outfile.endswith('json'):
                expected_output = json.load(fh_o)
            else:
                # plain text
                expected_output = fh_o.read()

        # seeing differences in YAML is easier than python dicts
        expected_yaml = yaml.safe_dump(expected_output,
                                       default_flow_style=False)
        actual_yaml = yaml.safe_dump(parsed, default_flow_style=False)
        diff = diffStrings(expected_yaml, actual_yaml, 'expected', 'actual')
        self.assertEqual(expected_yaml, actual_yaml, '\n' + ''.join(diff))