Skip to content

Commit 28f534d

Browse files
committed
Fix fastobo.iter not forwarding SyntaxError when given a file handle
1 parent 257aeaf commit 28f534d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/py/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ pub fn init(py: Python, m: &PyModule) -> PyResult<()> {
125125
} else {
126126
match FrameReader::from_handle(fh, ordered, threads) {
127127
Ok(r) => Ok(r),
128+
Err(inner) if inner.is_instance::<pyo3::exceptions::PySyntaxError>(py) => {
129+
Err(inner)
130+
}
128131
Err(inner) => {
129132
raise!(py, PyTypeError("expected path or binary file handle") from inner);
130133
}

tests/test_fastobo.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# coding: utf-8
22

3+
import io
34
import os
45
import unittest
56

@@ -74,6 +75,10 @@ def test_type_error(self):
7475
with open(MS) as f:
7576
self.assertRaises(TypeError, fastobo.iter, f)
7677

78+
def test_syntax_error(self):
79+
f = io.BytesIO(b"format-version: 1.4\ndate: 05:20:2021 12:00\n")
80+
self.assertRaises(SyntaxError, fastobo.iter, f)
81+
7782
def test_threading_single(self):
7883
frame_count = sum(1 for _ in fastobo.iter(MS, threads=1))
7984
self.assertEqual(frame_count, MS_FRAMES)

0 commit comments

Comments
 (0)