From d5718ef98a3158f8921f1cdcd920f3f6d0f00afd Mon Sep 17 00:00:00 2001 From: Marcin Wojdyr Date: Mon, 24 May 2021 20:14:46 +0200 Subject: [PATCH] py: tao::pegtl::parse_error -> ValueError (#119) --- python/gemmi.cpp | 3 +++ tests/test_cif.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/python/gemmi.cpp b/python/gemmi.cpp index 5d578fc06..5dc4ba5bc 100644 --- a/python/gemmi.cpp +++ b/python/gemmi.cpp @@ -9,6 +9,7 @@ #include "gemmi/small.hpp" // for SmallStructure #include "gemmi/interop.hpp" // for atom_to_site, mx_to_sx_structure #include "gemmi/bessel.hpp" // for bessel_i1_over_i0 +#include "gemmi/third_party/tao/pegtl/parse_error.hpp" // for parse_error namespace py = pybind11; @@ -88,6 +89,8 @@ PYBIND11_MODULE(gemmi, mg) { } catch (const std::system_error &e) { const int errornum = e.code().value(); PyErr_SetObject(PyExc_IOError, py::make_tuple(errornum, e.what()).ptr()); + } catch (const tao::pegtl::parse_error &e) { + PyErr_SetString(PyExc_ValueError, e.what()); } }); diff --git a/tests/test_cif.py b/tests/test_cif.py index 7b4520e61..317764a63 100755 --- a/tests/test_cif.py +++ b/tests/test_cif.py @@ -243,6 +243,10 @@ def test_file_not_found(self): with self.assertRaises(IOError): cif.read('file-that-does-not-exist.cif') + def test_syntax_error(self): + with self.assertRaises(ValueError): + cif.read_string('data_a boom') + def test_line_endings(self): lines = ['data_a', '_a_field', ';', 'text line', '2nd line', ';'] for eol in ('\r\n', '\n'):