예제 #1
0
파일: runner.py 프로젝트: iffy/ppo
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)
예제 #2
0
파일: runner.py 프로젝트: iffy/ppo
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)
예제 #3
0
파일: test_cases.py 프로젝트: iffy/ppo
    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))
예제 #4
0
파일: test_cases.py 프로젝트: iffy/ppo
    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))