Skip to content

Commit

Permalink
py: tao::pegtl::parse_error -> ValueError (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojdyr committed May 24, 2021
1 parent 6ee7016 commit d5718ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/gemmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
});

Expand Down
4 changes: 4 additions & 0 deletions tests/test_cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down

0 comments on commit d5718ef

Please sign in to comment.