Skip to content

Commit

Permalink
bugfix: wrong invocation of SchemaParseException (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianneubauer authored and Ryan P committed May 25, 2018
1 parent f88c550 commit 41c0995
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion confluent_kafka/avro/load.py
Expand Up @@ -27,7 +27,7 @@ def loads(schema_str):
return schema.parse(schema_str)
else:
return schema.Parse(schema_str)
except schema.AvroException.SchemaParseException as e:
except schema.SchemaParseException as e:
raise ClientError("Schema parse failed: %s" % (str(e)))


Expand Down
14 changes: 13 additions & 1 deletion setup.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python

import os
from setuptools import setup, find_packages
from distutils.core import Extension
import sys
Expand All @@ -14,6 +15,16 @@
'confluent_kafka/src/Producer.c',
'confluent_kafka/src/Consumer.c'])


def get_install_requirements(path):
content = open(os.path.join(os.path.dirname(__file__), path)).read()
return [
req
for req in content.split("\n")
if req != '' and not req.startswith('#')
]


setup(name='confluent-kafka',
version='0.11.4',
description='Confluent\'s Apache Kafka client for Python',
Expand All @@ -24,5 +35,6 @@
packages=find_packages(exclude=("tests", "tests.*")),
data_files=[('', ['LICENSE.txt'])],
extras_require={
'avro': ['fastavro', 'requests', avro]
'avro': ['fastavro', 'requests', avro],
'dev': get_install_requirements("test-requirements.txt")
})
2 changes: 2 additions & 0 deletions test-requirements.txt
@@ -0,0 +1,2 @@
pytest
flake8
10 changes: 10 additions & 0 deletions tests/avro/invalid_scema.avsc
@@ -0,0 +1,10 @@
{
"type" : "record",
"name" : "string_key",
"namespace" : "OrbitDbProducer",
"fields" : [ {
"name" : "key",
"type" : "array",
"items": "string"
} ]
}
7 changes: 6 additions & 1 deletion tests/avro/test_util.py
Expand Up @@ -21,7 +21,7 @@
#

import unittest

import pytest
from avro import schema
from tests.avro import data_gen
from confluent_kafka import avro
Expand All @@ -35,3 +35,8 @@ def test_schema_from_string(self):
def test_schema_from_file(self):
parsed = avro.load(data_gen.get_schema_path('adv_schema.avsc'))
self.assertTrue(isinstance(parsed, schema.Schema))

def test_schema_load_parse_error(self):
with pytest.raises(avro.ClientError) as excinfo:
avro.load(data_gen.get_schema_path("invalid_scema.avsc"))
assert 'Schema parse failed:' in str(excinfo.value)

0 comments on commit 41c0995

Please sign in to comment.