Skip to content

Commit

Permalink
fail_on_* params are optional
Browse files Browse the repository at this point in the history
fixes #2
  • Loading branch information
brew committed Sep 8, 2017
1 parent da45bc6 commit 4aaeb43
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
4 changes: 2 additions & 2 deletions datapackage_pipelines_goodtables/processors/validate.py
Expand Up @@ -55,8 +55,8 @@ def _split_json_log(json_log, level=logging.INFO, line_limit=None):

parameters, datapackage, res_iter = ingest()

fail_on_error = parameters['fail_on_error']
fail_on_warn = parameters['fail_on_warn']
fail_on_error = parameters.get('fail_on_error', True)
fail_on_warn = parameters.get('fail_on_warn', False)
goodtables_options = parameters.get('goodtables', {})


Expand Down
75 changes: 75 additions & 0 deletions tests/test_validate.py
@@ -0,0 +1,75 @@
import os
import datetime
import unittest
from decimal import Decimal

from datapackage_pipelines.utilities.lib_test_helpers import (
mock_processor_test
)

import datapackage_pipelines_goodtables.processors

import logging
log = logging.getLogger(__name__)

ROOT_PATH = os.path.join(os.path.dirname(__file__), '..')


class TestValidateProcessor(unittest.TestCase):

def test_validate_processor_no_resources_no_params(self):

# input arguments used by our mock `ingest`
datapackage = {
'name': 'my-datapackage',
'project': 'my-project',
'resources': []
}
params = {}

# Path to the processor we want to test
processor_dir = os.path.dirname(
datapackage_pipelines_goodtables.processors.__file__)
processor_path = os.path.join(processor_dir, 'validate.py')

# Trigger the processor with our mock `ingest` and capture what it will
# returned to `spew`.
spew_args, _ = mock_processor_test(processor_path,
(params, datapackage, []))

spew_dp = spew_args[0]

# Asserts for the datapackage
dp_resources = spew_dp['resources']
# No resources
assert len(dp_resources) == 0

def test_validate_processor_no_resources_with_params(self):

# input arguments used by our mock `ingest`
datapackage = {
'name': 'my-datapackage',
'project': 'my-project',
'resources': []
}
params = {
'fail_on_error': True,
'fail_on_warn': True
}

# Path to the processor we want to test
processor_dir = os.path.dirname(
datapackage_pipelines_goodtables.processors.__file__)
processor_path = os.path.join(processor_dir, 'validate.py')

# Trigger the processor with our mock `ingest` and capture what it will
# returned to `spew`.
spew_args, _ = mock_processor_test(processor_path,
(params, datapackage, []))

spew_dp = spew_args[0]

# Asserts for the datapackage
dp_resources = spew_dp['resources']
# No resources
assert len(dp_resources) == 0

0 comments on commit 4aaeb43

Please sign in to comment.