mirror of
https://github.com/shouptech/synthale.git
synced 2026-02-03 15:39:45 +00:00
Write error to stderr
This commit is contained in:
parent
4a4586f373
commit
ca2f13d7b6
2 changed files with 7 additions and 3 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
import pybeerxml
|
import pybeerxml
|
||||||
|
|
||||||
|
|
@ -42,12 +43,12 @@ def load_file(path):
|
||||||
"""Parse BeerXML file located at `path`.
|
"""Parse BeerXML file located at `path`.
|
||||||
|
|
||||||
Return a list of MarkdownRecipe objects. If an exception is raised during
|
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:
|
try:
|
||||||
result = pybeerxml.Parser().parse(path)
|
result = pybeerxml.Parser().parse(path)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(err)
|
print('Error parsing {}: {}'.format(path, err), file=sys.stderr)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
recipes = []
|
recipes = []
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,16 @@ import pybeerxml
|
||||||
from synthale.recipes import MarkdownRecipe, load_file, load_all_files
|
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."""
|
"""Load the sample XML file and ensure the name is parsed."""
|
||||||
result = load_file('tests/recipes/weizen.xml')
|
result = load_file('tests/recipes/weizen.xml')
|
||||||
assert result[0].recipe.name == 'Weizen'
|
assert result[0].recipe.name == 'Weizen'
|
||||||
|
|
||||||
result = load_file('tests/recipes/bad-file')
|
result = load_file('tests/recipes/bad-file')
|
||||||
|
captured = capsys.readouterr()
|
||||||
assert result == []
|
assert result == []
|
||||||
|
assert captured.err == ('Error parsing tests/recipes/bad-file: '
|
||||||
|
'syntax error: line 1, column 0\n')
|
||||||
|
|
||||||
|
|
||||||
def test_load_all_files():
|
def test_load_all_files():
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue