def test_command_extension_and_extension_field_location(monkeypatch): url = 'https://github.com/open-contracting-extensions/ocds_location_extension/archive/v1.1.4.zip' assert_command(monkeypatch, main, [ 'mapping-sheet', '--infer-required', '--extension-field', 'extension', path('release-schema.json'), '--extension', url ], 'mapping-sheet_extension_extension-field_location.csv')
def test_command(monkeypatch, tmpdir): p = tmpdir.join('test.json') p.write(content) assert_command(monkeypatch, main, ['indent', str(p)], '') assert p.read() == '{\n "lorem": "ipsum"\n}\n'
def test_command_directory(monkeypatch, caplog, tmpdir): assert_command(monkeypatch, main, ['detect-format', str(tmpdir)], '') assert len(caplog.records) == 1 assert caplog.records[0].levelname == 'WARNING' assert caplog.records[0].message.endswith( ' is a directory. Set --recursive to recurse into directories.')
def test_ascii(monkeypatch, tmpdir): p = tmpdir.join('test.json') p.write(b'{"lorem":"ips\\u00fam"}') assert_command(monkeypatch, main, ['--ascii', 'indent', str(p)], '') assert p.read() == '{\n "lorem": "ips\\u00fam"\n}\n'
def test_command_nonexistent(monkeypatch, caplog): assert_command(monkeypatch, main, ['detect-format', 'nonexistent'], '') assert len(caplog.records) == 1 assert caplog.records[0].levelname == 'ERROR' assert caplog.records[ 0].message == 'nonexistent: No such file or directory'
def test_command_recursive(monkeypatch, tmpdir): tmpdir.join('test.json').write(content) tmpdir.join('test.txt').write(content) assert_command(monkeypatch, main, ['indent', '--recursive', str(tmpdir)], '') assert tmpdir.join('test.json').read() == '{\n "lorem": "ipsum"\n}\n' assert tmpdir.join('test.txt').read() == content.decode()
def test_command_invalid_json(monkeypatch, caplog, tmpdir): p = tmpdir.join('test.json') p.write(invalid) assert_command(monkeypatch, main, ['indent', str(p)], '') assert len(caplog.records) == 1 assert caplog.records[0].levelname == 'ERROR' assert ' is not valid JSON. (json.decoder.JSONDecodeError: ' in caplog.records[0].message
def test_command(monkeypatch, tmpdir): tmpdir.join('release-schema.json').write(schema) tmpdir.mkdir('codelists') for basename in ('a', 'b', 'c', 'd'): tmpdir.join('codelists', '{}.csv'.format(basename)).write(codelist) assert_command(monkeypatch, main, ['set-closed-codelist-enums', str(tmpdir)], '') assert tmpdir.join('release-schema.json').read() == schema_with_enum
def test_command_unknown_format(basename, result, monkeypatch, caplog): filename = 'detect-format_{}.json'.format(basename) assert_command(monkeypatch, main, ['detect-format', path(filename)], '') assert len(caplog.records) == 1 assert caplog.records[0].levelname == 'WARNING' assert caplog.records[ 0].message == 'tests/fixtures/{}: unknown (top-level JSON value is a {})'.format( filename, result)
def test_unused_codelists(monkeypatch, caplog, tmpdir): tmpdir.join('release-schema.json').write(schema) tmpdir.mkdir('codelists') for basename in ('a', 'b', 'c', 'd', 'e'): tmpdir.join('codelists', '{}.csv'.format(basename)).write(codelist) assert_command(monkeypatch, main, ['set-closed-codelist-enums', str(tmpdir)], '') assert tmpdir.join('release-schema.json').read() == schema_with_enum assert len(caplog.records) == 1 assert caplog.records[0].levelname == 'ERROR' assert caplog.records[0].message == 'unused codelists: e.csv'
def test_modified_codelists(monkeypatch, tmpdir): with TemporaryDirectory() as d: for directory in (tmpdir, d): os.mkdir(os.path.join(directory, 'codelists')) with open(os.path.join(directory, 'release-schema.json'), 'w') as f: f.write(schema) for basename in ('a', 'b', 'c', 'd'): tmpdir.join('codelists', '{}.csv'.format(basename)).write(codelist) with open(os.path.join(d, 'codelists', '+a.csv'), 'w') as f: f.write('Code\nbaz\n') with open(os.path.join(d, 'codelists', '-b.csv'), 'w') as f: f.write('Code,Description\nbar,bzz\n') assert_command(monkeypatch, main, ['set-closed-codelist-enums', str(tmpdir), d], '') with open(os.path.join(d, 'release-schema.json')) as f: assert f.read() == schema_with_modification
def test_conflicting_codelists(monkeypatch, caplog, tmpdir): with TemporaryDirectory() as d: for directory in (tmpdir, d): os.mkdir(os.path.join(directory, 'codelists')) with open(os.path.join(directory, 'release-schema.json'), 'w') as f: f.write(schema) for basename in ('a', 'b', 'c', 'd'): tmpdir.join('codelists', '{}.csv'.format(basename)).write(codelist) with open(os.path.join(d, 'codelists', 'a.csv'), 'w') as f: f.write('Code\nbaz\n') assert_command(monkeypatch, main, ['set-closed-codelist-enums', str(tmpdir), d], '') with open(os.path.join(d, 'release-schema.json')) as f: assert f.read() == schema_with_enum assert len(caplog.records) == 1 assert caplog.records[0].levelname == 'ERROR' assert caplog.records[0].message == 'conflicting codelists: a.csv'
def test_command_extension_field(monkeypatch): assert_command(monkeypatch, main, [ 'mapping-sheet', '--infer-required', '--extension-field', 'extension', path('release-schema.json') ], 'mapping-sheet_extension-field.csv')
def test_command_oc4ids(monkeypatch): assert_command( monkeypatch, main, ['mapping-sheet', path('project-schema.json')], 'mapping-sheet_oc4ids.csv')
def test_command(monkeypatch): assert_command( monkeypatch, main, ['mapping-sheet', '--infer-required', path('release-schema.json')], 'mapping-sheet.csv')
def test_command_bods(monkeypatch): assert_command(monkeypatch, main, [ 'mapping-sheet', '--order-by', 'path', path('bods/person-statement.json') ], 'mapping-sheet_bods.csv')
def test_command_sedl(monkeypatch): assert_command(monkeypatch, main, ['mapping-sheet', path('sedl-schema.json')], 'mapping-sheet_sedl.csv')
def test_command_root_path(filename, root_path, result, monkeypatch): expected = 'tests/fixtures/{}: {}\n'.format(filename, result) assert_command(monkeypatch, main, ['detect-format', '--root-path', root_path, path(filename)], expected)