Skip to content

Commit c36c02f

Browse files
authored
Make test_parsing more resilient to changes in pycparser (#224)
* Make test_parsing more resilient to changes in pycparser Several tests expect precise error messages from pycparser, which pycparser doesn't guarantee. While testing CFFI with pycparser 3.0, some tests needed to be made more resilient. I've used the .startswith() approach already used in this file, instead of exact string matching. Ref #223 * Loosen error message assertion even more
1 parent ee1a87b commit c36c02f

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

testing/cffi0/test_parsing.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,29 +197,29 @@ def test_dont_remove_comment_in_line_directives():
197197
198198
some syntax error here
199199
""")
200-
assert str(e.value) == "parse error\nbaz.c:9:14: before: syntax"
200+
assert str(e.value).startswith("parse error\nbaz.c:9:")
201201
#
202202
e = pytest.raises(CDefError, ffi.cdef, """
203203
#line 7 "foo//bar.c"
204204
205205
some syntax error here
206206
""")
207207
#
208-
assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
208+
assert str(e.value).startswith("parse error\nfoo//bar.c:8:")
209209
ffi = FFI(backend=FakeBackend())
210210
e = pytest.raises(CDefError, ffi.cdef, """
211211
\t # \t 8 \t "baz.c" \t
212212
213213
some syntax error here
214214
""")
215-
assert str(e.value) == "parse error\nbaz.c:9:14: before: syntax"
215+
assert str(e.value).startswith("parse error\nbaz.c:9:")
216216
#
217217
e = pytest.raises(CDefError, ffi.cdef, """
218218
# 7 "foo//bar.c"
219219
220220
some syntax error here
221221
""")
222-
assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
222+
assert str(e.value).startswith("parse error\nfoo//bar.c:8:")
223223

224224
def test_multiple_line_directives():
225225
ffi = FFI(backend=FakeBackend())
@@ -233,7 +233,7 @@ def test_multiple_line_directives():
233233
#line 8 "yadda.c"
234234
extern int zz;
235235
""")
236-
assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
236+
assert str(e.value).startswith("parse error\nbaz.c:7:")
237237
#
238238
e = pytest.raises(CDefError, ffi.cdef,
239239
""" # 5 "foo.c"
@@ -245,7 +245,7 @@ def test_multiple_line_directives():
245245
# 8 "yadda.c"
246246
extern int zz;
247247
""")
248-
assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
248+
assert str(e.value).startswith("parse error\nbaz.c:7:")
249249

250250
def test_commented_line_directive():
251251
ffi = FFI(backend=FakeBackend())
@@ -262,7 +262,7 @@ def test_commented_line_directive():
262262
some syntax error
263263
""")
264264
#
265-
assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
265+
assert str(e.value).startswith("parse error\nbar.c:9:")
266266
e = pytest.raises(CDefError, ffi.cdef, """
267267
/*
268268
# 5 "foo.c"
@@ -275,7 +275,7 @@ def test_commented_line_directive():
275275
*/
276276
some syntax error
277277
""")
278-
assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
278+
assert str(e.value).startswith("parse error\nbar.c:9:")
279279

280280
def test_line_continuation_in_defines():
281281
ffi = FFI(backend=FakeBackend())
@@ -365,7 +365,7 @@ def test_unknown_name():
365365
e = pytest.raises(CDefError, ffi.cast, "foobarbazunknown*", 0)
366366
assert str(e.value).startswith('cannot parse "foobarbazunknown*"')
367367
e = pytest.raises(CDefError, ffi.cast, "int(*)(foobarbazunknown)", 0)
368-
assert str(e.value).startswith('cannot parse "int(*)(foobarbazunknown)"')
368+
assert 'foobarbazunknown' in str(e.value)
369369

370370
def test_redefine_common_type():
371371
prefix = "" if sys.version_info < (3,) else "b"

0 commit comments

Comments
 (0)