From ab33a83fc5ea5fcb226eb8f72c8d4cd3b77472fc 2013-10-11 17:12:43 From: Thomas Kluyver Date: 2013-10-11 17:12:43 Subject: [PATCH] Add test for IPython.utils.localinterfaces --- diff --git a/IPython/utils/localinterfaces.py b/IPython/utils/localinterfaces.py index 3e828f4..d160b79 100644 --- a/IPython/utils/localinterfaces.py +++ b/IPython/utils/localinterfaces.py @@ -42,10 +42,10 @@ LOCALHOST = '' def _only_once(f): """decorator to only run a function once""" f.called = False - def wrapped(): + def wrapped(**kwargs): if f.called: return - ret = f() + ret = f(**kwargs) f.called = True return ret return wrapped @@ -203,7 +203,7 @@ def _load_ips_dumb(): PUBLIC_IPS[:] = [] @_only_once -def _load_ips(): +def _load_ips(suppress_exceptions=True): """load the IPs that point to this machine This function will only ever be called once. @@ -241,6 +241,8 @@ def _load_ips(): return _load_ips_gethostbyname() except Exception as e: + if not suppress_exceptions: + raise # unexpected error shouldn't crash, load dumb default values instead. warn("Unexpected error discovering local network interfaces: %s" % e) _load_ips_dumb() diff --git a/IPython/utils/tests/test_localinterfaces.py b/IPython/utils/tests/test_localinterfaces.py new file mode 100644 index 0000000..136e0f7 --- /dev/null +++ b/IPython/utils/tests/test_localinterfaces.py @@ -0,0 +1,15 @@ +#----------------------------------------------------------------------------- +# Copyright (C) 2013 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +from .. import localinterfaces + +def test_load_ips(): + # Override the machinery that skips it if it was called before + localinterfaces._load_ips.called = False + + # Just check this doesn't error + localinterfaces._load_ips(suppress_exceptions=False) \ No newline at end of file