Skip to content

Commit

Permalink
Tests of getting flags esp in case where no C library installed
Browse files Browse the repository at this point in the history
  • Loading branch information
langmm committed Mar 8, 2018
1 parent 48e46a5 commit 654511c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
8 changes: 4 additions & 4 deletions cis_interface/drivers/GCCModelDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_zmq_flags():
for l in ["libzmq", "czmq"]:
plib = cis_cfg.get('windows', '%s_static' % l, False)
pinc = cis_cfg.get('windows', '%s_include' % l, False)
if not (plib and pinc): # pragma: debug
if not (plib and pinc):
raise Exception("Could not locate %s .lib and .h files." % l)
pinc_d = os.path.dirname(pinc)
plib_d, plib_f = os.path.split(plib)
Expand Down Expand Up @@ -62,6 +62,9 @@ def get_flags():
tuple(list, list): compile and linker flags.
"""
if (get_default_comm() == 'ZMQComm') and (not _zmq_installed_c): # pragma: windows
raise Exception(("ZeroMQ C libraries are not installed and IPC libraries " +
"are not available on Windows."))
_compile_flags = []
_linker_flags = []
if platform._is_win: # pragma: windows
Expand All @@ -80,9 +83,6 @@ def get_flags():
_compile_flags += ["-I" + x]
if get_default_comm() == 'IPCComm':
_compile_flags += ["-DIPCDEF"]
elif (get_default_comm() == 'ZMQComm') and (not _zmq_installed_c): # pragma: windows
raise Exception(("ZeroMQ C libraries are not installed and IPC libraries " +
"are not available on Windows."))
return _compile_flags, _linker_flags


Expand Down
35 changes: 34 additions & 1 deletion cis_interface/drivers/tests/test_GCCModelDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,40 @@
from cis_interface import platform, tools
from cis_interface.tests import scripts
import cis_interface.drivers.tests.test_ModelDriver as parent
from cis_interface.drivers.GCCModelDriver import GCCModelDriver
from cis_interface.drivers.GCCModelDriver import (
GCCModelDriver, get_zmq_flags, get_ipc_flags, get_flags)


@unittest.skipIf(not tools._zmq_installed_c, "ZMQ C Library not installed")
def test_get_zmq_flags():
r"""Test get_zmq_flags."""
get_zmq_flags()


@unittest.skipIf(tools._zmq_installed_c, "ZMQ C Library installed")
def test_get_zmq_flags_no_C_library(): # pragma: windows
r"""Test error from get_zmq_flags when C library not installed."""
nt.assert_raises(Exception, get_zmq_flags)


def test_get_ipc_flags():
r"""Test get_ipc_flags."""
cc, ld = get_ipc_flags()
if not tools._ipc_installed: # pragma: windows
nt.assert_equal(len(cc), 0)
nt.assert_equal(len(ld), 0)


@unittest.skipIf(not tools._c_library_avail, "C library not installed")
def test_get_flags():
r"""Test get_flags."""
get_flags()


@unittest.skipIf(tools._c_library_avail, "C library installed")
def test_get_flags_no_C_library(): # pragma: windows
r"""Test get_flags error when C library not installed."""
nt.assert_raises(Exception, get_flags)


@unittest.skipIf(tools._c_library_avail, "C Library installed")
Expand Down
3 changes: 2 additions & 1 deletion cis_interface/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def is_zmq_installed(check_c=True):
# Check existence of zmq python package
try:
import zmq
except ImportError: # pragma: windows
except ImportError: # pragma: debug
return False
assert(zmq)
if not check_c: # pragma: windows
Expand Down Expand Up @@ -163,6 +163,7 @@ def is_zmq_installed(check_c=True):
if is_zmq_installed(check_c=False):
logging.warning(("ZeroMQ C library not installed, but the Python package is. " +
"Running C and C++ models will be disabled."))
_zmq_installed_c = False
_zmq_installed = True
else: # pragma: debug
raise Exception('Neither ZMQ or IPC installed.')
Expand Down

0 comments on commit 654511c

Please sign in to comment.