move validation tests to their own file
MODIFY
.travis.yml
.travis.yml
@@ -8,7 +8,7 @@ python:
- pypy
- pypy3
install:
- - pip install pytest flake8 check-manifest Cython
+ - pip install pytest flake8 check-manifest Cython numpy
script:
- ./run-tests.sh
- docker run --rm -v "$(pwd):/data" quay.io/pypa/manylinux1_x86_64 bash -c "/data/.travis_build_wheel.sh $TRAVIS_PYTHON_VERSION"

MODIFY
appveyor.yml
appveyor.yml
@@ -12,7 +12,7 @@ environment:
- PYTHON: "C:\\Python36-x64"
install:
- - "%PYTHON%\\python.exe -m pip install pytest flake8 check-manifest Cython wheel"
+ - "%PYTHON%\\python.exe -m pip install pytest flake8 check-manifest Cython wheel numpy"
build: off

MODIFY
fastavro/write.py
fastavro/write.py
@@ -10,6 +10,7 @@ writer = _write.writer
Writer = _write.Writer
schemaless_writer = _write.schemaless_writer
write_data = _write.write_data
+_validate = _write.validate
WRITERS = _write.WRITERS
LOGICAL_WRITERS = _write.LOGICAL_WRITERS

MODIFY
tests/test_fastavro.py
tests/test_fastavro.py
@@ -745,71 +745,6 @@ def test_validator():
pass
-def test_validator_numeric():
- for datum, schema in [
- (1, 'int'),
- (1, 'long'),
- (1.0, 'float'),
- (1.0, 'double'),
- (1, 'float'),
- (1, 'double'),
- ]:
- assert fastavro._write.validate(datum, schema)
-
- for datum, schema in [
- (1.0, 'int'),
- (1.0, 'long'),
- ("1.0", 'float'),
- ("1.0", 'double'),
- ("1", 'float'),
- ("1", 'double'),
- ]:
- assert not fastavro._write.validate(datum, schema)
- # and plenty more to add I suppose
-
-
-def test_validator_numeric_numpy():
- import numpy as np
- np_ints = [
- np.int_,
- np.intc,
- np.intp,
- np.int8,
- np.int16,
- np.int32,
- np.int64,
- np.uint8,
- np.uint16,
- np.uint32,
- np.uint64,
- ]
-
- np_floats = [
- np.float_,
- np.float16,
- np.float32,
- np.float64,
- ]
-
- schema_ints = ['int', 'long']
-
- schema_floats = ['float', 'double']
-
- # all these should work
- for nptype, schema in zip(np_ints, schema_ints):
- assert fastavro._write.validate(nptype(1), schema)
-
- for nptype, schema in zip(np_ints, schema_floats):
- assert fastavro._write.validate(nptype(1), schema)
-
- for nptype, schema in zip(np_floats, schema_floats):
- assert fastavro._write.validate(nptype(1), schema)
-
- # these shouldn't work
- for nptype, schema in zip(np_floats, schema_ints):
- assert not fastavro._write.validate(nptype(1), schema)
-
-
def test_is_avro_str():
for path in iglob('%s/*.avro' % data_dir):
assert fastavro.is_avro(path)

ADD
tests/test_validate.py
+from fastavro.write import _validate
+
+
+def test_validator_numeric():
+ for datum, schema in [
+ (1, 'int'),
+ (1, 'long'),
+ (1.0, 'float'),
+ (1.0, 'double'),
+ (1, 'float'),
+ (1, 'double'),
+ ]:
+ assert _validate(datum, schema)
+
+ for datum, schema in [
+ (1.0, 'int'),
+ (1.0, 'long'),
+ ("1.0", 'float'),
+ ("1.0", 'double'),
+ ("1", 'float'),
+ ("1", 'double'),
+ ]:
+ assert not _validate(datum, schema)
+ # and plenty more to add I suppose
+
+
+def test_validator_numeric_numpy():
+ import numpy as np
+ np_ints = [
+ np.int_,
+ np.intc,
+ np.intp,
+ np.int8,
+ np.int16,
+ np.int32,
+ np.int64,
+ np.uint8,
+ np.uint16,
+ np.uint32,
+ np.uint64,
+ ]
+
+ np_floats = [
+ np.float_,
+ np.float16,
+ np.float32,
+ np.float64,
+ ]
+
+ schema_ints = ['int', 'long']
+
+ schema_floats = ['float', 'double']
+
+ # all these should work
+ for nptype, schema in zip(np_ints, schema_ints):
+ assert _validate(nptype(1), schema)
+
+ for nptype, schema in zip(np_ints, schema_floats):
+ assert _validate(nptype(1), schema)
+
+ for nptype, schema in zip(np_floats, schema_floats):
+ assert _validate(nptype(1), schema)
+
+ # these shouldn't work
+ for nptype, schema in zip(np_floats, schema_ints):
+ assert not _validate(nptype(1), schema)

move validation tests to their own file