示例#1
0
def test_command_missing_ocid(monkeypatch, caplog):
    stdin = b'{"id":"1","date":"2001-02-03T04:05:06Z","tag":["planning"],"initiationType":"tender"}'

    with caplog.at_level(logging.ERROR):
        assert_streaming_error(monkeypatch, main, ['compile'], stdin)

        assert len(caplog.records) == 1
        assert caplog.records[0].levelname == 'CRITICAL'
        assert caplog.records[0].message == 'The `ocid` field of at least one release is missing.'
示例#2
0
def test_command_invalid_json(monkeypatch, caplog):
    with caplog.at_level(logging.ERROR):
        stdin = read('release-package_minimal.json', 'rb') + b'\n{\n'

        assert_streaming_error(monkeypatch, main, ['echo'], stdin, expected=read('release-package_minimal.json'))

        assert len(caplog.records) == 1
        assert caplog.records[0].levelname == 'CRITICAL'
        assert caplog.records[0].message.startswith('JSON error: ')
示例#3
0
def test_command_downgrade(monkeypatch, caplog):
    stdin = b'{}'

    assert_streaming_error(monkeypatch, main, ['upgrade', '1.1:1.0'], stdin)

    assert len(caplog.records) == 1
    assert caplog.records[0].levelname == 'CRITICAL'
    assert caplog.records[
        0].message == 'downgrade from 1.1 to 1.0 is not supported'
示例#4
0
def test_command_version_mismatch(monkeypatch, caplog):
    with caplog.at_level(logging.ERROR):
        assert_streaming_error(monkeypatch, main, ['compile', '--package', '--versioned'],
                               ['realdata/release-package_1.1-1.json', 'realdata/release-package_1.0-1.json'])

        assert len(caplog.records) == 1
        assert caplog.records[0].levelname == 'CRITICAL'
        assert caplog.records[0].message == "item 1: version error: this item uses version 1.0, but earlier items " \
            "used version 1.1\nTry first upgrading items to the same version:\n  cat file [file ...] | ocdskit " \
            "upgrade 1.0:1.1 | ocdskit compile --package --versioned"
示例#5
0
def test_command_bad_encoding_iso_8859_1(monkeypatch, caplog):
    with caplog.at_level(logging.ERROR):
        assert_streaming_error(monkeypatch, main, ['echo'],
                               ['realdata/release-package_encoding-iso-8859-1.json'])

        assert len(caplog.records) == 1
        assert caplog.records[0].levelname == 'CRITICAL'
        # macOS and Linux have different error messages.
        assert re.search(r"^encoding error: (?:'utf-8' codec can't decode byte 0xd3 in position \d+: invalid "
                         r"continuation byte|lexical error: invalid bytes in UTF8 string.(\n[^\n]+){2}\n)\n"
                         r"Try `--encoding iso-8859-1`\?$", caplog.records[0].message)