Skip to content

Commit

Permalink
Fix #23
Browse files Browse the repository at this point in the history
  • Loading branch information
di committed Apr 14, 2016
1 parent fff56fc commit dc99925
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ python:
- "3.5-dev" # 3.5 development branch
- "nightly" # currently points to 3.6-dev
install:
- pip install flake8
- pip install coveralls
# Coveralls 4.0 doesn't support Python 3.2
- if [ "$TRAVIS_PYTHON_VERSION" == "3.2" ]; then travis_retry pip install coverage==3.7.1; fi
- if [ "$TRAVIS_PYTHON_VERSION" != "3.2" ]; then travis_retry pip install coverage; fi
script:
- coverage run --source=vladiate setup.py test
- flake8 .
after_success:
- coveralls
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
BINDIR = $(PWD)/.state/env/bin

test: .state/env/pyvenv.cfg
$(BINDIR)/coverage run --source=vladiate setup.py test
$(BINDIR)/coverage report -m

lint: .state/env/pyvenv.cfg
$(BINDIR)/flake8 .

.state/env/pyvenv.cfg:
# Create our Python 3.5 virtual environment
rm -rf .state/env
python3.5 -m venv .state/env

# install/upgrade general requirements
.state/env/bin/python -m pip install --upgrade pip setuptools wheel

# install various types of requirements
.state/env/bin/python -m pip install coverage
.state/env/bin/python -m pip install flake8
9 changes: 7 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,17 @@ Running Vlads Programatically
Testing
~~~~~~~
To run the tests
To run the tests:
::
python setup.py test
make test
To run the linter:
::
make lint
Command Line Arguments
~~~~~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-line-length = 120
exclude = *.egg,.state,build
select = E,W,F,N
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8

import sys, os
from setuptools import setup, find_packages, Command
import sys
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand

version = '0.0.11'
Expand All @@ -20,7 +20,7 @@ def finalize_options(self):
self.test_suite = True

def run_tests(self):
#import here, cause outside the eggs aren't loaded
# import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)
Expand Down Expand Up @@ -63,7 +63,7 @@ def readme():
include_package_data=True,
zip_safe=False,
install_requires=['boto'],
tests_require=['pytest'],
tests_require=['pytest', 'flake8'],
cmdclass={'test': PyTest},
entry_points={
'console_scripts': [
Expand Down
2 changes: 1 addition & 1 deletion vladiate/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from vladiate.vlad import Vlad
from vladiate.vlad import Vlad # NOQA
1 change: 1 addition & 0 deletions vladiate/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class ValidationException(Exception):
''' Thrown when validation fails '''
pass


class BadValidatorException(Exception):
''' Thrown when a validator is bad '''
def __init__(self, extra):
Expand Down
15 changes: 11 additions & 4 deletions vladiate/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from argparse import ArgumentParser
from pkg_resources import get_distribution


def parse_args():
"""
Handle command-line arguments with argparse.ArgumentParser
Expand All @@ -27,8 +28,7 @@ def parse_args():
'-f', '--vladfile',
dest='vladfile',
default='vladfile',
help=
"Python module file to import, e.g. '../other.py'. Default: vladfile")
help="Python module file to import, e.g. '../other.py'. Default: vladfile")

# List vladiate commands found in loaded vladiate files/source files
parser.add_argument(
Expand Down Expand Up @@ -139,11 +139,15 @@ def load_vladfile(path):
vlads = dict(filter(is_vlad, vars(imported).items()))
return imported.__doc__, vlads


def _vladiate(vlad):
global result_queue
result_queue.put(vlad(vlad.source, validators=vlad.validators).validate())


result_queue = Queue()


def main():
arguments = parse_args()
logger = logs.logger
Expand Down Expand Up @@ -189,8 +193,11 @@ def main():
vlad(source=vlad.source).validate()

else:
proc_pool = Pool(arguments.processes
if arguments.processes <= vlad_classes else vlad_classes)
proc_pool = Pool(
arguments.processes
if arguments.processes <= vlad_classes
else vlad_classes
)
proc_pool.map(_vladiate, vlad_classes)
try:
if not result_queue.get_nowait():
Expand Down
1 change: 0 additions & 1 deletion vladiate/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

21 changes: 10 additions & 11 deletions vladiate/test/test_inputs.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import pytest

from ..inputs import *
from ..validators import *
from ..vlad import *
from ..inputs import S3File, StringIO, String
from ..vlad import Vlad


@pytest.mark.parametrize('kwargs', [
({'path':'s3://some.bucket/some/s3/key.csv'}),
({'bucket':'some.bucket', 'key':'/some/s3/key.csv'}),
({'path': 's3://some.bucket/some/s3/key.csv'}),
({'bucket': 'some.bucket', 'key': '/some/s3/key.csv'}),
])
def test_s3_input_works(kwargs):
S3File(**kwargs)


@pytest.mark.parametrize('kwargs', [
({}),
({'path':'s3://some.bucket/some/s3/key.csv', 'bucket':'some.bucket'}),
({'path':'s3://some.bucket/some/s3/key.csv', 'key':'/some/s3/key.csv'}),
({'bucket':'some.bucket'}),
({'key':'/some/s3/key.csv'}),
({'path': 's3://some.bucket/some/s3/key.csv', 'bucket': 'some.bucket'}),
({'path': 's3://some.bucket/some/s3/key.csv', 'key': '/some/s3/key.csv'}),
({'bucket': 'some.bucket'}),
({'key': '/some/s3/key.csv'}),
])
def test_s3_input_fails(kwargs):
with pytest.raises(ValueError):
S3File(**kwargs)


@pytest.mark.parametrize('kwargs', [
({'string_input':'ColA,ColB\n,'}),
({'string_io':StringIO('ColA,ColB\n,')}),
({'string_input': 'ColA,ColB\n,'}),
({'string_io': StringIO('ColA,ColB\n,')}),
])
def test_string_input_works(kwargs):
source = String(**kwargs)
Expand Down
7 changes: 5 additions & 2 deletions vladiate/test/test_validators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import pytest

from ..validators import *
from ..exceptions import *
from ..validators import (
EmptyValidator, FloatValidator, Ignore, IntValidator, RegexValidator,
SetValidator, UniqueValidator
)
from ..exceptions import BadValidatorException, ValidationException


class FakeRow(object):
Expand Down
5 changes: 3 additions & 2 deletions vladiate/test/test_vlads.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest

from ..vlad import Vlad
from ..inputs import *
from ..validators import *
from ..inputs import LocalFile
from ..validators import UniqueValidator, SetValidator, FloatValidator


def test_initialize_vlad():
Expand Down Expand Up @@ -56,6 +56,7 @@ def test_unused_validator_fails_validation():

def test_validators_in_class_variable_are_used():
source = LocalFile('vladiate/examples/vampires.csv')

class TestVlad(Vlad):
validators = {
'Column A': [
Expand Down

0 comments on commit dc99925

Please sign in to comment.