def test_get_schema_from_url_request_fails(mocker): cm = mocker.MagicMock() cm.__enter__.return_value = cm cm.read.side_effect = ValueError( "'ValueError' object has no attribute 'decode'") mocker.patch("arche.readers.schema.urllib.request.urlopen", return_value=cm, autospec=True) with pytest.raises(ValueError) as excinfo: reader.get_schema_from_url("https://example.com/schema.json") assert str( excinfo.value) == "'ValueError' object has no attribute 'decode'"
def test_get_schema_from_url(schema_path, schema_contents, expected, mocker): mocker.patch( "arche.readers.schema.s3.get_contents_as_string", return_value=schema_contents, autospec=True, ) mocker.patch("arche.readers.schema.get_contents", return_value=schema_contents, autospec=True) assert reader.get_schema_from_url(schema_path) == expected
def test_get_schema_from_url_fails(path, expected_message): with pytest.raises(ValueError) as excinfo: reader.get_schema_from_url(path) assert str(excinfo.value) == expected_message