def test_non_existing_module_works(self): A, B = FromOptionalDependency('invalid_module').do_import('A', 'B') self.assertEqual(A.__name__, 'A') self.assertEqual(B.__name__, 'B') self.assertRaises(LewisException, A, 'argument_one') self.assertRaises(LewisException, B, 'argument_one', 'argument_two')
def test_non_existing_module_works(self): A, B = FromOptionalDependency("invalid_module").do_import("A", "B") self.assertEqual(A.__name__, "A") self.assertEqual(B.__name__, "B") self.assertRaises(LewisException, A, "argument_one") self.assertRaises(LewisException, B, "argument_one", "argument_two")
def test_custom_exception_is_raised(self): A = FromOptionalDependency('invalid_module', ValueError('test')).do_import('A') self.assertRaises(ValueError, A)
def test_string_exception_is_raised(self): A = FromOptionalDependency('invalid_module', 'test').do_import('A') self.assertRaises(LewisException, A)
def test_non_existing_members_in_module_dont_work(self): self.assertRaises(AttributeError, FromOptionalDependency('time').do_import, 'sleep', 'bleep')
def test_existing_module_works(self): a = FromOptionalDependency('time').do_import('sleep') from time import sleep as b self.assertEqual(a, b)
LimitViolationException, ) from lewis.core.logging import has_log from lewis.core.utils import FromOptionalDependency, format_doc_text, seconds_since # pcaspy might not be available. To make EPICS-based adapters show up # in the listed adapters anyway dummy types are created in this case # and the failure is postponed to runtime, where a more appropriate # LewisException can be raised. missing_pcaspy_exception = LewisException( "In order to use EPICS-interfaces, pcaspy must be installed:\n" "\tpip install pcaspy\n" "A fully working installation of EPICS-base is required for this package. " "Please refer to the documentation for advice.") Driver, SimpleServer = FromOptionalDependency( "pcaspy", missing_pcaspy_exception).do_import("Driver", "SimpleServer") pcaspy_manager = FromOptionalDependency( "pcaspy.driver", missing_pcaspy_exception).do_import("manager") class BoundPV: """ Class to represent PVs that are bound to an adapter This class is very similar to :class:`~lewis.adapters.stream.Func`, in that it is the result of a binding operation between a user-specified :class:`PV`-object and a Device and/or Adapter object. Also, it should rarely be used directly. objects are generated automatically by :class:`EpicsAdapter`. The binding happens by supplying a ``target``-object which has an attribute or a property
from six import iteritems from lewis.core.utils import seconds_since, FromOptionalDependency, format_doc_text from lewis.core.exceptions import LewisException # pcaspy might not be available. To make EPICS-based adapters show up # in the listed adapters anyway dummy types are created in this case # and the failure is postponed to runtime, where a more appropriate # LewisException can be raised. missing_pcaspy_exception = LewisException( 'In order to use EPICS-interfaces, pcaspy must be installed:\n' '\tpip install pcaspy\n' 'A fully working installation of EPICS-base is required for this package. ' 'Please refer to the documentation for advice.') Driver, SimpleServer = FromOptionalDependency( 'pcaspy', missing_pcaspy_exception).do_import('Driver', 'SimpleServer') class PV(object): """ The PV-class is used to declare the EPICS-interface exposed by a sub-class of EpicsAdapter. The ``target_property`` argument specifies which property of the adapter the PV maps to. To make development easier it can also be a part of the exposed device. If the property exists on both the Adapter-subclass and the device, the former has precedence. This is useful for overriding behavior for protocol specific "quirks". If the PV should be read only, this needs to be specified via the corresponding parameter. The information about the poll interval is used py EpicsAdapter to update the PV in regular intervals. All other named arguments are forwarded to the pcaspy server's `pvdb`, so it's possible to pass on limits, types, enum-values and so on.
def test_custom_exception_is_raised(self): A = FromOptionalDependency("invalid_module", ValueError("test")).do_import("A") self.assertRaises(ValueError, A)
def test_string_exception_is_raised(self): A = FromOptionalDependency("invalid_module", "test").do_import("A") self.assertRaises(LewisException, A)