Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compyle/ext_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from distutils.sysconfig import get_config_vars
from distutils.util import get_platform
from distutils.errors import CompileError, LinkError
from Cython.Compiler.Errors import PyrexError
import hashlib
import importlib
import io
Expand Down Expand Up @@ -282,7 +283,7 @@ def build(self, force=False):
_out = stream.get_output()
print(_out[0])
print(_out[1])
except (CompileError, LinkError):
except (PyrexError, CompileError, LinkError):
hline = "*"*80
print(hline + "\nERROR")
s_out = stream.get_output()
Expand Down
26 changes: 26 additions & 0 deletions compyle/tests/test_ext_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tempfile
from textwrap import dedent
from multiprocessing import Pool
import pytest
from unittest import TestCase, main, SkipTest

try:
Expand Down Expand Up @@ -107,6 +108,11 @@ def test_md5(self):
self.assertNotEqual(get_md5(data), get_md5(data + ' '))


@pytest.fixture(scope="function")
def use_capsys(request, capsys):
request.instance.capsys = capsys


class TestExtModule(TestCase):
def setUp(self):
self.root = tempfile.mkdtemp()
Expand Down Expand Up @@ -162,6 +168,26 @@ def test_load_module(self):
self.assertEqual(mod.f(), "hello world")
self.assertTrue(exists(s.ext_path))

@pytest.mark.usefixtures("use_capsys")
def test_compiler_errors_are_captured(self):
# Given
src = dedent('''\
# cython: language_level=3
def f():
print(bug)
''')
s = ExtModule(src, root=self.root)

# When
self.assertRaises(SystemExit, s.write_and_build)

# Then
captured = self.capsys.readouterr()
err = captured.out + captured.err
print(err)
self.assertTrue('Error compiling Cython file' in err)
self.assertTrue('def f()' in err)

def _create_dummy_module(self):
code = "# cython: language_level=3\ndef hello(): return 'hello'"
modname = 'test_rebuild.py'
Expand Down
Loading