diff --git a/python/spot/aux.py b/python/spot/aux.py index d5bc34aaa..a85c26f30 100644 --- a/python/spot/aux.py +++ b/python/spot/aux.py @@ -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): diff --git a/tests/Makefile.am b/tests/Makefile.am index d4b68775c..93bd6a86a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -284,6 +284,7 @@ TESTS_twa = \ if USE_PYTHON TESTS_python = \ + python/_aux.ipynb \ python/acc_cond.ipynb \ python/accparse.ipynb \ python/accparse2.py \ diff --git a/tests/python/_aux.ipynb b/tests/python/_aux.ipynb new file mode 100644 index 000000000..ed3527d71 --- /dev/null +++ b/tests/python/_aux.ipynb @@ -0,0 +1,73 @@ +{ + "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: : 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\u001b[0m in \u001b[0;36m\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 diff --git a/tests/sanity/ipynb.pl b/tests/sanity/ipynb.pl index a0709c4cc..dfebecf51 100755 --- a/tests/sanity/ipynb.pl +++ b/tests/sanity/ipynb.pl @@ -65,9 +65,8 @@ close(FD); open(FD, "$dir/../Makefile.am") or die "$!"; while () { - 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";