Ejemplo n.º 1
0
def test_iter_files_recursive():
    gen = utils.iter_files(TEST_DIR, ['xsd'], recursive=True)
    assert len(list(gen)) > 5
Ejemplo n.º 2
0
def test_iter_files_no_matches():
    gen = utils.iter_files(TEST_DIR, ['noext'])
    assert len(list(gen)) == 0
Ejemplo n.º 3
0
def test_iter_files_flat():
    gen = utils.iter_files(TEST_DIR, ['xsd'])
    assert len(list(gen)) == 0
    gen = utils.iter_files(TEST_DIR, ['PY'])
    assert len(list(gen)) > 5
Ejemplo n.º 4
0
def test_iter_files_simple():
    gen = utils.iter_files(TEST_DIR, ['py'])
    assert isinstance(gen, types.GeneratorType)
    assert len(list(gen)) > 5
Ejemplo n.º 5
0
def test_iter_files_simple():
    gen = utils.iter_files(TEST_DIR, ['py'])
    assert isinstance(gen, types.GeneratorType)
    assert len(list(gen)) > 5
Ejemplo n.º 6
0
def test_iter_files_recursive():
    gen = utils.iter_files(TEST_DIR, ['xsd'], recursive=True)
    assert len(list(gen)) > 5
Ejemplo n.º 7
0
def test_iter_files_flat():
    gen = utils.iter_files(TEST_DIR, ['xsd'])
    assert len(list(gen)) == 0
    gen = utils.iter_files(TEST_DIR, ['PY'])
    assert len(list(gen)) > 5
Ejemplo n.º 8
0
def test_iter_files_no_matches():
    gen = utils.iter_files(TEST_DIR, ['noext'])
    assert len(list(gen)) == 0
Ejemplo n.º 9
0
def main(argv=None):
    """Command line app main function.

    :param list | None argv: Overrides command options (for libuse or testing)
    """
    parser = create_parser()

    args = parser.parse_args() if argv is None else parser.parse_args(argv)

    schemas = ('xsd',) if not args.schemas else tuple(args.schemas)

    if args.debug:
        logging.basicConfig(
            level=logging.DEBUG,
            format='%(asctime)s - %(levelname)s - %(name)s - %(message)s'
        )
        print('DEBUG logging enabled.')

    try:
        import win_unicode_console
        win_unicode_console.enable()
        log.debug('Running with win-unicode-console patch')
    except Exception:
        pass

    log.debug('TYPE of path: %s' % type(args.path))
    # validate current working dir
    if not args.infile and not args.path:
        args.path = os.getcwdu()
        log.debug('NEW TYPE of path: %s' % type(args.path))

    all_valid = True

    if args.infile:
        log.debug('TYPE of infile.name: %s' % type(args.infile.name))
        print('Validating: %s' % args.infile.name)
        messages = validate(args.infile, schemas)
        is_valid = messages == []
        if is_valid:
            print('VALID - No errors found')
        else:
            print('INVALID - errors found:', file=sys.stderr)
            all_valid = False
            for msg in messages:
                if args.debug:
                    print(msg.__str__(), file=sys.stderr)
                else:
                    print(msg.short, file=sys.stderr)

    if args.path:
        tree_or_dir = 'tree' if args.recursive else 'dir'
        print()
        print('Validating all files in %s %s' % (tree_or_dir, args.path))

        for onix_file_path in iter_files(args.path, args.ext, args.recursive):
            print()
            print('Validating: %s' % onix_file_path)
            with open(onix_file_path, 'rb') as onix_file:
                messages = validate(onix_file, schemas)
                is_valid = messages == []

            if is_valid:
                print('VALID - No errors found')
            else:
                print('INVALID - errors found:', file=sys.stderr)
                all_valid = False
                for msg in messages:
                    if args.debug:
                        print(msg.__str__(), file=sys.stderr)
                    else:
                        print(msg.short, file=sys.stderr)
    if all_valid:
        return 0
    else:
        return 1
Ejemplo n.º 10
0
def main(argv=None):
    """Command line app main function.

    :param list | None argv: Overrides command options (for libuse or testing)
    """
    parser = create_parser()

    args = parser.parse_args() if argv is None else parser.parse_args(argv)

    schemas = ('xsd',) if not args.schemas else tuple(args.schemas)

    if args.debug:
        logging.basicConfig(
            level=logging.DEBUG,
            format='%(asctime)s - %(levelname)s - %(name)s - %(message)s'
        )
        print('DEBUG logging enabled.')

    try:
        import win_unicode_console
        win_unicode_console.enable()
        log.debug('Running with win-unicode-console patch')
    except Exception:
        pass

    log.debug('TYPE of path: %s' % type(args.path))
    # validate current working dir
    if not args.infile and not args.path:
        args.path = getcwd()
        log.debug('NEW TYPE of path: %s' % type(args.path))

    all_valid = True

    if args.infile:
        log.debug('TYPE of infile.name: %s' % type(args.infile.name))
        print('Validating: %s' % args.infile.name)
        messages = validate(args.infile, schemas)
        is_valid = messages == []
        if is_valid:
            print('VALID - No errors found')
        else:
            print('INVALID - errors found:', file=sys.stderr)
            all_valid = False
            for msg in messages:
                if args.debug:
                    print(msg.__str__(), file=sys.stderr)
                else:
                    print(msg.short, file=sys.stderr)

    if args.path:
        tree_or_dir = 'tree' if args.recursive else 'dir'
        print()
        print('Validating all files in %s %s' % (tree_or_dir, args.path))

        for onix_file_path in iter_files(args.path, args.ext, args.recursive):
            print()
            print('Validating: %s' % onix_file_path)
            with open(onix_file_path, 'rb') as onix_file:
                messages = validate(onix_file, schemas)
                is_valid = messages == []

            if is_valid:
                print('VALID - No errors found')
            else:
                print('INVALID - errors found:', file=sys.stderr)
                all_valid = False
                for msg in messages:
                    if args.debug:
                        print(msg.__str__(), file=sys.stderr)
                    else:
                        print(msg.short, file=sys.stderr)
    if all_valid:
        return 0
    else:
        return 1