Example #1
0
def diff():
    description = textwrap.dedent("""Print differences between two rule sets (sources)""")
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('--config', '-c',
        help="YAML configuration file", dest='config_file', type=str, default='fwunit.yaml')
    parser.add_argument('--verbose', action='store_true')
    parser.add_argument('--quiet', action='store_true')
    parser.add_argument('left', help='left source')
    parser.add_argument('right', help='right source')

    args, cfg = _setup(parser)
    if not args.verbose:
        logging.getLogger('').setLevel(logging.CRITICAL)

    diff_module.show_diff(cfg, args.left, args.right)
Example #2
0
def diff():
    description = textwrap.dedent(
        """Print differences between two rule sets (sources)""")
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('--config',
                        '-c',
                        help="YAML configuration file",
                        dest='config_file',
                        type=str,
                        default='fwunit.yaml')
    parser.add_argument('--verbose', action='store_true')
    parser.add_argument('--quiet', action='store_true')
    parser.add_argument('left', help='left source')
    parser.add_argument('right', help='right source')

    args, cfg = _setup(parser)
    if not args.verbose:
        logging.getLogger('').setLevel(logging.CRITICAL)

    diff_module.show_diff(cfg, args.left, args.right)
Example #3
0
def test_show_diff():
    with mock.patch('fwunit.analysis.sources.load_source') as load_source, \
         mock.patch('sys.stdout') as stdout:
        def fake_load_source(cfg, name):
            if name == 'left':
                return FakeSource(LEFT)
            else:
                return FakeSource(RIGHT)
        load_source.side_effect = fake_load_source
        written = []
        def fake_write(data):
            written.append(data)
        stdout.write.side_effect = fake_write
        diff.show_diff(None, 'left', 'right')
        written = ''.join(written)
        # rather than assert on exactly what's written, which may change as presentaiton improves,
        # just assert that we wrote lines starting with + or -, after stripping escape codes
        for line in filter(None, written.split('\n')):
            line = re.sub('\x1b[^m]+m', '', line)
            assert line.startswith('+') or line.startswith('-'), line