test_cython.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import os
  2. import sys
  3. import pytest
  4. import zmq
  5. @pytest.mark.skipif(
  6. 'zmq.backend.cython' not in sys.modules, reason="Requires cython backend"
  7. )
  8. @pytest.mark.skipif(
  9. sys.platform.startswith('win'), reason="Don't try runtime Cython on Windows"
  10. )
  11. @pytest.mark.parametrize('language_level', [3, 2])
  12. def test_cython(language_level, request, tmpdir):
  13. import pyximport
  14. assert 'zmq.tests.cython_ext' not in sys.modules
  15. importers = pyximport.install(
  16. setup_args=dict(include_dirs=zmq.get_includes()),
  17. language_level=language_level,
  18. build_dir=str(tmpdir),
  19. )
  20. cython_ext = None
  21. def unimport():
  22. pyximport.uninstall(*importers)
  23. sys.modules.pop('zmq.tests.cython_ext', None)
  24. request.addfinalizer(unimport)
  25. # this import tests the compilation
  26. from . import cython_ext
  27. assert hasattr(cython_ext, 'send_recv_test')
  28. # call the compiled function
  29. # this shouldn't do much
  30. msg = b'my msg'
  31. received = cython_ext.send_recv_test(msg)
  32. assert received == msg