Exemplo n.º 1
0
def test_command(monkeypatch, tmpdir):
    with open(path('schema-strict.json'), 'rb') as f:
        schema = f.read()

    p = tmpdir.join('schema.json')
    p.write(schema)

    run_command(monkeypatch, main, ['schema-strict', str(p)])

    assert p.read() == expected
Exemplo n.º 2
0
def test_command_no_unique_items(monkeypatch, tmpdir):
    with open(path('schema-strict.json'), 'rb') as f:
        schema = f.read()

    p = tmpdir.join('schema.json')
    p.write(schema)

    run_command(monkeypatch, main, ['schema-strict', '--no-unique-items', str(p)])

    assert 'uniqueItems' not in json.loads(p.read())['properties']['array']
Exemplo n.º 3
0
def test_command_check(stderr, monkeypatch):
    with open(path('schema-strict.json'), 'rb') as f:
        expected = f.read()

    run_command(monkeypatch, main, ['schema-strict', '--check', path('schema-strict.json')])

    with open(path('schema-strict.json'), 'rb') as f:
        assert f.read() == expected

    assert stderr.getvalue() == 'ERROR: tests/fixtures/schema-strict.json is missing validation properties\n'
Exemplo n.º 4
0
def test_command_min_occurrences(monkeypatch):
    actual = run_command(monkeypatch, main, [
        'schema-report', '--min-occurrences', '1', '--no-codelists',
        path('test-schema.json')
    ])

    assert 'codelist,openCodelist' not in actual
    assert '1:' in actual
Exemplo n.º 5
0
def test_command_no_definitions(monkeypatch):
    actual = run_command(monkeypatch, main, [
        'schema-report', '--min-occurrences', '2', '--no-definitions',
        path('test-schema.json')
    ])

    assert 'codelist,openCodelist' in actual
    assert ':' not in actual
Exemplo n.º 6
0
def test_command_recursive(monkeypatch, caplog, tmpdir):
    content = b'{"records":[]}'
    tmpdir.join('test.json').write(content)
    tmpdir.join('.test.json').write(content)

    actual = run_command(monkeypatch, main,
                         ['detect-format', '--recursive',
                          str(tmpdir)])

    assert '/test.json: record package' in actual
    assert '.test.json' not in actual
    assert len(caplog.records) == 0
Exemplo n.º 7
0
def test_command(monkeypatch):
    actual = run_command(
        monkeypatch, main,
        ['schema-report', '--min-occurrences', '2',
         path('test-schema.json')])

    assert actual == 'codelist,openCodelist\n' \
                     'a.csv,False/True\n' \
                     'b.csv,False\n' \
                     'c.csv,False\n' \
                     'd.csv,False\n' \
                     '\n' \
                     " 2: {'codelist': 'a.csv', 'openCodelist': True, 'type': ['string', 'null']}\n"