Esempio n. 1
0
def test_timesys_errors():
    output = io.StringIO()
    validate(get_pkg_data_filename('data/timesys_errors.xml'), output,
             xmllint=False)
    outstr = output.getvalue()
    assert("E23: Invalid timeorigin attribute 'bad-origin'" in outstr)
    assert("E22: ID attribute is required for all TIMESYS elements" in outstr)
    assert("W48: Unknown attribute 'refposition_mispelled' on TIMESYS"
           in outstr)
Esempio n. 2
0
def test_no_resource_check():
    output = io.StringIO()

    with catch_warnings():
        # We can't test xmllint, because we can't rely on it being on the
        # user's machine.
        result = validate(get_pkg_data_filename('data/no_resource.xml'),
                          output, xmllint=False)

    assert result is False

    output.seek(0)
    output = output.readlines()

    # Uncomment to generate new groundtruth
    # with open('no_resource.txt', 'wt', encoding='utf-8') as fd:
    #     fd.write(u''.join(output))

    with open(
        get_pkg_data_filename('data/no_resource.txt'),
            'rt', encoding='utf-8') as fd:
        truth = fd.readlines()

    truth = truth[1:]
    output = output[1:-1]

    sys.stdout.writelines(
        difflib.unified_diff(truth, output, fromfile='truth', tofile='output'))

    assert truth == output
Esempio n. 3
0
def test_validate(test_path_object=False):
    """
    test_path_object is needed for test below ``test_validate_path_object``
    so that file could be passed as pathlib.Path object.
    """
    output = io.StringIO()
    fpath = get_pkg_data_filename('data/regression.xml')
    if test_path_object:
        fpath = pathlib.Path(fpath)

    # We can't test xmllint, because we can't rely on it being on the
    # user's machine.
    result = validate(fpath, output, xmllint=False)

    assert result is False

    output.seek(0)
    output = output.readlines()

    # Uncomment to generate new groundtruth
    # with open('validation.txt', 'wt', encoding='utf-8') as fd:
    #    fd.write(u''.join(output))

    with open(get_pkg_data_filename('data/validation.txt'),
              'rt',
              encoding='utf-8') as fd:
        truth = fd.readlines()

    truth = truth[1:]
    output = output[1:-1]

    sys.stdout.writelines(
        difflib.unified_diff(truth, output, fromfile='truth', tofile='output'))

    assert truth == output
Esempio n. 4
0
def test_no_resource_check():
    output = io.StringIO()

    with catch_warnings():
        # We can't test xmllint, because we can't rely on it being on the
        # user's machine.
        result = validate(get_pkg_data_filename('data/no_resource.xml'),
                          output, xmllint=False)

    assert result is False

    output.seek(0)
    output = output.readlines()

    # Uncomment to generate new groundtruth
    # with open('no_resource.txt', 'wt', encoding='utf-8') as fd:
    #     fd.write(u''.join(output))

    with open(
        get_pkg_data_filename('data/no_resource.txt'),
            'rt', encoding='utf-8') as fd:
        truth = fd.readlines()

    truth = truth[1:]
    output = output[1:-1]

    sys.stdout.writelines(
        difflib.unified_diff(truth, output, fromfile='truth', tofile='output'))

    assert truth == output
Esempio n. 5
0
def test_validate_xmllint_true(mock_subproc_popen):
    process_mock = mock.Mock()
    attrs = {'communicate.return_value': ('ok', 'ko'), 'returncode': 0}
    process_mock.configure_mock(**attrs)
    mock_subproc_popen.return_value = process_mock

    assert validate(get_pkg_data_filename('data/empty_table.xml'),
                    xmllint=True)
Esempio n. 6
0
def test_validate_xmllint_true(mock_subproc_popen):
    process_mock = mock.Mock()
    attrs = {'communicate.return_value': ('ok', 'ko'),
             'returncode': 0}
    process_mock.configure_mock(**attrs)
    mock_subproc_popen.return_value = process_mock

    assert validate(get_pkg_data_filename('data/empty_table.xml'),
                    xmllint=True)
Esempio n. 7
0
def test_validate(test_path_object=False):
    """
    test_path_object is needed for test below ``test_validate_path_object``
    so that file could be passed as pathlib.Path object.
    """
    output = io.StringIO()
    fpath = get_pkg_data_filename('data/regression.xml')
    if test_path_object:
        fpath = pathlib.Path(fpath)

    # We can't test xmllint, because we can't rely on it being on the
    # user's machine.
    with catch_warnings():
        result = validate(fpath,
                          output, xmllint=False)

    assert result is False

    output.seek(0)
    output = output.readlines()

    # Uncomment to generate new groundtruth
    # with open('validation.txt', 'wt', encoding='utf-8') as fd:
    #     fd.write(u''.join(output))

    with open(
        get_pkg_data_filename('data/validation.txt'),
            'rt', encoding='utf-8') as fd:
        truth = fd.readlines()

    truth = truth[1:]
    output = output[1:-1]

    sys.stdout.writelines(
        difflib.unified_diff(truth, output, fromfile='truth', tofile='output'))

    assert truth == output