Пример #1
0
def test_append_no_id():
    merger = Merger(rule_overrides={('nested', 'array',): APPEND})
    data = load(os.path.join('schema', 'identifier-merge-no-id.json'))

    with warnings.catch_warnings():
        warnings.simplefilter('error')  # no unexpected warnings

        compiled_release = merger.create_compiled_release(data + data)

    assert compiled_release == load(os.path.join('schema', 'identifier-merge-no-id-append.json'))
Пример #2
0
def test_append():
    merger = Merger(rule_overrides={('nested', 'array',): APPEND})

    with pytest.warns(DuplicateIdValueWarning):
        compiled_release = merger.create_compiled_release(releases + releases)

    assert compiled_release == load(os.path.join('schema', 'identifier-merge-duplicate-id-append.json'))
Пример #3
0
def test_merge_by_position():
    merger = Merger(rule_overrides={('nested', 'array',): MERGE_BY_POSITION})

    with pytest.warns(DuplicateIdValueWarning):
        compiled_release = merger.create_compiled_release(releases + releases)

    assert compiled_release == load(os.path.join('schema', 'identifier-merge-duplicate-id-by-position.json'))
Пример #4
0
def test_append(infix, cls, empty_merger):
    expected = load(os.path.join('1.1', f'lists-{infix}.json'))
    releases = load(os.path.join('1.1', 'lists.json'))

    merged_release = getattr(empty_merger,
                             f'create_{infix}_release')(releases[:1])

    merger = cls(merged_release, merge_rules=empty_merger.merge_rules)
    merger.append(releases[1])

    assert merger.asdict() == expected

    merger = cls(merged_release, schema={})
    merger.extend(releases[1:])

    assert merger.asdict() == expected
Пример #5
0
def get_test_cases():
    test_valid_argvalues = []

    release_schema_path = 'release-schema-{}.json'
    versioned_release_schema_path = 'versioned-release-validation-schema-{}.json'

    for minor_version, patch_tag in tags.items():
        filenames = glob(path(os.path.join(minor_version, '*.json')))
        assert len(filenames), 'ocds fixtures not found'
        for versioned, schema_path in ((False, release_schema_path), (True, versioned_release_schema_path)):
            schema = load(schema_path.format(patch_tag))
            for filename in filenames:
                if not versioned ^ filename.endswith('-versioned.json'):
                    test_valid_argvalues.append((filename, schema))

    return test_valid_argvalues
Пример #6
0
def pythonStringToJson(input_string, entry_function, test_cases):
    test_cases = tests.load(test_cases)
    out_s = StringIO.StringIO()
    test_s = ''

    if entry_function is not None and test_cases is not None:
        test_s = tests.get_test_string(test_cases, entry_function)

    def json_finalizer(input_code, output_trace):
        if test_cases:
            input_code, output_trace = tests.format_output(
                test_s, test_cases, input_code, output_trace)

        # Finalise output
        ret = dict(code=input_code, trace=output_trace)
        json_output = json.dumps(ret, indent=None)
        out_s.write(json_output)

    py_logger.exec_script_str_local(input_string + test_s, '', False, False,
                                    json_finalizer)

    return out_s.getvalue()
Пример #7
0
import os
import warnings

import pytest

from ocdsmerge import APPEND, MERGE_BY_POSITION, Merger
from ocdsmerge.exceptions import DuplicateIdValueWarning
from tests import load

releases = load(os.path.join('schema', 'identifier-merge-duplicate-id.json'))


@pytest.mark.vcr()
def test_warn(empty_merger):
    fields = ['identifierMerge', 'array']
    string = "Multiple objects have the `id` value '1' in the `nested.{}` array"

    with pytest.warns(DuplicateIdValueWarning) as records:
        empty_merger.create_compiled_release(releases)

    assert len(records) == 2

    for i, record in enumerate(records):
        message = string.format(fields[i])

        assert record.message.path == ('nested', fields[i],)
        assert record.message.id == '1'
        assert record.message.message == message
        assert str(record.message) == message