diff --git a/src/synthale/recipes.py b/src/synthale/recipes.py index adba2d3..b2d3731 100644 --- a/src/synthale/recipes.py +++ b/src/synthale/recipes.py @@ -2,6 +2,7 @@ import os import re +import sys import pybeerxml @@ -42,12 +43,12 @@ def load_file(path): """Parse BeerXML file located at `path`. Return a list of MarkdownRecipe objects. If an exception is raised during - parsing, the message is printed to stdout and an empty list is returned. + parsing, the message is printed to stderr and an empty list is returned. """ try: result = pybeerxml.Parser().parse(path) except Exception as err: - print(err) + print('Error parsing {}: {}'.format(path, err), file=sys.stderr) return [] recipes = [] diff --git a/tests/test_recipes.py b/tests/test_recipes.py index 5a845b9..44ba5ee 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -5,13 +5,16 @@ import pybeerxml from synthale.recipes import MarkdownRecipe, load_file, load_all_files -def test_load_file(): +def test_load_file(capsys): """Load the sample XML file and ensure the name is parsed.""" result = load_file('tests/recipes/weizen.xml') assert result[0].recipe.name == 'Weizen' result = load_file('tests/recipes/bad-file') + captured = capsys.readouterr() assert result == [] + assert captured.err == ('Error parsing tests/recipes/bad-file: ' + 'syntax error: line 1, column 0\n') def test_load_all_files():