Commit 22af7aef authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz

python: report dot errors

* python/spot/aux.py: Catch errors from dot and signal them.
* tests/python/_aux.ipynb: New file.
* tests/Makefile.am: Add it.
* tests/sanity/ipynb.pl: Support the convention that tests starting with
'_' should not be published on the web site.
parent c093b7b7
......@@ -23,6 +23,7 @@ Auxiliary functions for Spot's Python bindings
from functools import lru_cache
import subprocess
import sys
def extend(*classes):
......@@ -50,9 +51,16 @@ def str_to_svg(str):
"""
dot = subprocess.Popen(['dot', '-Tsvg'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
res = dot.communicate(str)
return res[0].decode('utf-8')
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = dot.communicate(str)
if stderr:
print("Calling 'dot' for the conversion to SVG produced the message:\n"
+ stderr.decode('utf-8'), file=sys.stderr)
ret = dot.wait()
if ret:
raise subprocess.CalledProcessError(ret, 'dot')
return stdout.decode('utf-8')
def ostream_to_svg(ostr):
......
......@@ -284,6 +284,7 @@ TESTS_twa = \
if USE_PYTHON
TESTS_python = \
python/_aux.ipynb \
python/acc_cond.ipynb \
python/accparse.ipynb \
python/accparse2.py \
......
{
"metadata": {
"name": "",
"signature": "sha256:6be10f711b59f226415bc570a040611b0a8c554e61bf92877b8af4040963e0ac"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import spot.aux"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Make sure `str_to_svg` reports errors from dot."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"spot.aux.str_to_svg(b'syntax error')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"Calling 'dot' for the conversion to SVG produced the message:\n",
"Error: <stdin>: syntax error in line 1 near 'syntax'\n",
"\n"
]
},
{
"ename": "CalledProcessError",
"evalue": "Command 'dot' returned non-zero exit status 1",
"output_type": "pyerr",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mCalledProcessError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-294a2c217b9a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mspot\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maux\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstr_to_svg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mb'syntax error'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/home/adl/git/spot/python/spot/aux.py\u001b[0m in \u001b[0;36mstr_to_svg\u001b[0;34m(str)\u001b[0m\n\u001b[1;32m 60\u001b[0m \u001b[0mret\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdot\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 61\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mret\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 62\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0msubprocess\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mCalledProcessError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mret\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'dot'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 63\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mstdout\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'utf-8'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 64\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mCalledProcessError\u001b[0m: Command 'dot' returned non-zero exit status 1"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
\ No newline at end of file
......@@ -65,9 +65,8 @@ close(FD);
open(FD, "$dir/../Makefile.am") or die "$!";
while (<FD>)
{
if (m:python/([\w-]+\.ipynb):)
if (m:python/([^_][\w-]*\.ipynb):)
{
# print "$1 exist";
unless (exists $seen{$1})
{
print STDERR "notebook $1 is not mentioned in tut.org";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment