Skip to content

Commit

Permalink
More readable commandline output
Browse files Browse the repository at this point in the history
  • Loading branch information
titusz committed Jul 19, 2015
1 parent 43df0ee commit e2c89ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions src/onixcheck/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import click
from lxml import etree
from onixcheck.models import OnixFile
from onixcheck import validate

log = logging.getLogger('onixcheck')

Expand Down Expand Up @@ -52,16 +52,16 @@ def main(infile, debug):

click.echo('Validating: %s' % infile.name)

onix_file = OnixFile(infile)
log.debug(onix_file.meta)
messages = validate(infile)
is_valid = not messages

validator = onix_file.get_validator()
result = validator(onix_file.xml_tree())
click.echo('Valid: %s' % result)
for err in validator.error_log:
click.echo('Error: %s' % err)

if validator.error_log:
sys.exit(1)
if is_valid:
click.echo('VALID - No errors found')
else:
for msg in messages:
click.echo(msg)

if is_valid:
sys.exit(0)
else:
sys.exit(1)
6 changes: 3 additions & 3 deletions tests/test_onixcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ def test_main_o2_ref_valid():
def test_main_has_ns_valid():
runner = CliRunner()
result = runner.invoke(main, [data.VALID_ONIX3_REF_NS])
assert 'Validating' in result.output
assert 'validating' in result.output.lower()
assert result.exit_code == 0


def test_main_plain_invalid():
runner = CliRunner()
result = runner.invoke(main, [data.INVALID_ONIX3_REF])
assert 'Error' in result.output
assert 'error' in result.output.lower()
assert result.exit_code == 1


def test_main_debug():
runner = CliRunner()
result = runner.invoke(main, [data.VALID_ONIX3_REF, '-d'])
assert 'DEBUG' in result.output
assert 'debug' in result.output.lower()
assert result.exit_code == 0

0 comments on commit e2c89ff

Please sign in to comment.