def testAddedProperty(self): """ Tests the add_property method """ pelix_test_name = "PELIX_TEST" pelix_test = "42" pelix_test_2 = "123" # Test without pre-set properties framework = FrameworkFactory.get_framework() self.assertIsNone(framework.get_property(pelix_test_name), "Magic property value") # Add the property self.assertTrue(framework.add_property(pelix_test_name, pelix_test), "add_property shouldn't fail on first call") self.assertEqual(framework.get_property(pelix_test_name), pelix_test, "Invalid property value") # Update the property (must fail) self.assertFalse(framework.add_property(pelix_test_name, pelix_test_2), "add_property must fail on second call") self.assertEqual(framework.get_property(pelix_test_name), pelix_test, "Invalid property value") FrameworkFactory.delete_framework(framework)
def testBundleStart(self): """ Tests if a bundle can be started before the framework itself """ framework = FrameworkFactory.get_framework() context = framework.get_bundle_context() assert isinstance(context, BundleContext) # Install a bundle bundle = context.install_bundle(SIMPLE_BUNDLE) self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be in RESOLVED state") # Starting the bundle now should fail self.assertRaises(BundleException, bundle.start) self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be in RESOLVED state") # Start the framework framework.start() # Bundle should have been started now self.assertEqual(bundle.get_state(), Bundle.ACTIVE, "Bundle should be in ACTIVE state") # Stop the framework framework.stop() self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be in RESOLVED state") # Try to start the bundle again (must fail) self.assertRaises(BundleException, bundle.start) self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be in RESOLVED state") FrameworkFactory.delete_framework()
def testWaitForStop(self): """ Tests the wait_for_stop() method """ # Set up a framework framework = FrameworkFactory.get_framework() # No need to wait for the framework... self.assertTrue(framework.wait_for_stop(), "wait_for_stop() must return True " "on stopped framework") # Start the framework framework.start() # Start the framework killer threading.Thread(target=_framework_killer, args=(framework, 0.5)).start() # Wait for stop start = time.time() self.assertTrue(framework.wait_for_stop(), "wait_for_stop(None) should return True") end = time.time() self.assertLess(end - start, 1, "Wait should be less than 1 sec") FrameworkFactory.delete_framework(framework)
def testWaitForStopTimeout(self): """ Tests the wait_for_stop() method """ # Set up a framework framework = FrameworkFactory.get_framework() framework.start() # Start the framework killer threading.Thread(target=_framework_killer, args=(framework, 0.5)).start() # Wait for stop (timeout not raised) start = time.time() self.assertTrue(framework.wait_for_stop(1), "wait_for_stop() should return True") end = time.time() self.assertLess(end - start, 1, "Wait should be less than 1 sec") # Restart framework framework.start() # Start the framework killer threading.Thread(target=_framework_killer, args=(framework, 2)).start() # Wait for stop (timeout raised) start = time.time() self.assertFalse(framework.wait_for_stop(1), "wait_for_stop() should return False") end = time.time() self.assertLess(end - start, 1.2, "Wait should be less than 1.2 sec") # Wait for framework to really stop framework.wait_for_stop() FrameworkFactory.delete_framework()
def testDuplicatedFactory(self): """ Tests the behavior of iPOPO if two bundles provide the same factory. """ # Start the framework self.framework = FrameworkFactory.get_framework() self.framework.start() ipopo = install_ipopo(self.framework) # Install bundles: both provide a "basic-component-factory" factory # and instantiate a component (both with different names) module_A = install_bundle(self.framework, "tests.ipopo.ipopo_bundle") module_B = install_bundle(self.framework, "tests.ipopo.ipopo_bundle_copy") # Ensure that the module providing the factory is the correct one self.assertIs(module_A, ipopo.get_factory_bundle( module_A.BASIC_FACTORY).get_module(), "Duplicated factory is not provided by the first module") self.assertIs(module_A, ipopo.get_factory_bundle( module_B.BASIC_FACTORY).get_module(), "Duplicated factory is not provided by the first module") # Component of module A must be there self.assertIsNotNone( ipopo.get_instance_details(module_A.BASIC_INSTANCE), "Component from module A not started") # Component of module B must be absent self.assertRaises(ValueError, ipopo.get_instance_details, module_B.BASIC_INSTANCE)
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.context = self.framework.get_bundle_context()
def testFrameworkRestart(self): """ Tests call to Framework.update(), that restarts the framework """ framework = FrameworkFactory.get_framework() context = framework.get_bundle_context() # Register the stop listener context.add_framework_stop_listener(self) # Calling update while the framework is stopped should do nothing framework.update() self.assertFalse(self.stopping, "Stop listener called") # Start and update the framework self.assertTrue(framework.start(), "Framework couldn't be started") framework.update() # The framework must have been stopped and must be active self.assertTrue(self.stopping, "Stop listener not called") self.assertEqual(framework.get_state(), Bundle.ACTIVE, "Framework hasn't been restarted") framework.stop() FrameworkFactory.delete_framework(framework)
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.ipopo = install_ipopo(self.framework)
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.ipopo_bundle = install_bundle(self.framework, "pelix.ipopo.core")
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.ipopo = install_ipopo(self.framework) self.module = install_bundle(self.framework)
def setUp(self): """ Called before each test. Initiates a framework and loads the current module as the first bundle """ self.test_bundle_name = "tests.framework.service_bundle" self.framework = FrameworkFactory.get_framework() self.framework.start()
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.ipopo = install_ipopo(self.framework) self.module = install_bundle(self.framework, "tests.ipopo.ipopo_fields_bundle")
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() # Compatibility issue if sys.version_info[0] < 3: self.assertCountEqual = self.assertItemsEqual
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.ipopo = install_ipopo(self.framework) # Install the test bundle self.module = install_bundle(self.framework)
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.test_bundle_name = SIMPLE_BUNDLE self.bundle = None self.received = []
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.context = self.framework.get_bundle_context() # Get the path to the current test package self.test_root = os.path.join( os.path.abspath(os.path.dirname(__file__)), "vault")
def testFrameworkStopper(self): """ Tests FrameworkException stop flag handling """ framework = FrameworkFactory.get_framework() context = framework.get_bundle_context() # Install the bundle bundle = context.install_bundle(SIMPLE_BUNDLE) module_ = bundle.get_module() # Set module in raiser stop mode module_.fw_raiser = True module_.fw_raiser_stop = True log_off() self.assertFalse(framework.start(), "Framework should be stopped") self.assertEqual(framework.get_state(), Bundle.RESOLVED, "Framework should be stopped") self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be stopped") log_on() # Set module in raiser non-stop mode module_.fw_raiser_stop = False log_off() self.assertTrue(framework.start(), "Framework should be stopped") self.assertEqual(framework.get_state(), Bundle.ACTIVE, "Framework should be started") self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be stopped") log_on() # Start the module module_.fw_raiser = False bundle.start() self.assertEqual(bundle.get_state(), Bundle.ACTIVE, "Bundle should be active") # Set module in raiser mode module_.fw_raiser = True module_.fw_raiser_stop = True # Stop the framework log_off() self.assertTrue(framework.stop(), "Framework couldn't be stopped") self.assertEqual(framework.get_state(), Bundle.RESOLVED, "Framework should be stopped") self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be stopped") log_on() FrameworkFactory.delete_framework()
def testFrameworkStopper(self): """ Tests FrameworkException stop flag handling """ framework = FrameworkFactory.get_framework() context = framework.get_bundle_context() # Install the bundle bundle = context.install_bundle(SIMPLE_BUNDLE) module = bundle.get_module() # Set module in raiser stop mode module.fw_raiser = True module.fw_raiser_stop = True log_off() self.assertFalse(framework.start(), "Framework should be stopped") self.assertEqual(framework.get_state(), Bundle.RESOLVED, "Framework should be stopped") self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be stopped") log_on() # Set module in raiser non-stop mode module.fw_raiser_stop = False log_off() self.assertTrue(framework.start(), "Framework should be stopped") self.assertEqual(framework.get_state(), Bundle.ACTIVE, "Framework should be started") self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be stopped") log_on() # Start the module module.fw_raiser = False bundle.start() self.assertEqual(bundle.get_state(), Bundle.ACTIVE, "Bundle should be active") # Set module in raiser mode module.fw_raiser = True module.fw_raiser_stop = True # Stop the framework log_off() self.assertTrue(framework.stop(), "Framework couldn't be stopped") self.assertEqual(framework.get_state(), Bundle.RESOLVED, "Framework should be stopped") self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be stopped") log_on() FrameworkFactory.delete_framework(framework)
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.context = self.framework.get_bundle_context() self.test_bundle_name = SIMPLE_BUNDLE # File path, without extension self.test_bundle_loc = os.path.join( os.path.dirname(__file__), self.test_bundle_name.rsplit('.', 1)[1])
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start() self.context = self.framework.get_bundle_context() self.test_bundle_name = SIMPLE_BUNDLE # File path, without extension self.test_bundle_loc = os.path.abspath( self.test_bundle_name.replace('.', os.sep))
def testFrameworkStartRaiser(self): """ Tests framework start and stop with a bundle raising exception """ framework = FrameworkFactory.get_framework() context = framework.get_bundle_context() # Register the stop listener context.add_framework_stop_listener(self) # Install the bundle bundle = context.install_bundle(SIMPLE_BUNDLE) module = bundle.get_module() # Set module in raiser mode module.raiser = True # Framework can start... log_off() self.assertTrue(framework.start(), "Framework should be started") log_on() self.assertEqual(framework.get_state(), Bundle.ACTIVE, "Framework should be in ACTIVE state") self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be in RESOLVED state") # Stop the framework self.assertTrue(framework.stop(), "Framework should be stopped") # Remove raiser mode module.raiser = False # Framework can start self.assertTrue(framework.start(), "Framework couldn't be started") self.assertEqual(framework.get_state(), Bundle.ACTIVE, "Framework should be in ACTIVE state") self.assertEqual(bundle.get_state(), Bundle.ACTIVE, "Bundle should be in ACTIVE state") # Set module in raiser mode module.raiser = True # Stop the framework log_off() self.assertTrue(framework.stop(), "Framework couldn't be stopped") log_on() self.assertTrue(self.stopping, "Stop listener not called") FrameworkFactory.delete_framework(framework)
def testFrameworkStartRaiser(self): """ Tests framework start and stop with a bundle raising exception """ framework = FrameworkFactory.get_framework() context = framework.get_bundle_context() # Register the stop listener context.add_framework_stop_listener(self) # Install the bundle bundle = context.install_bundle(SIMPLE_BUNDLE) module_ = bundle.get_module() # Set module in raiser mode module_.raiser = True # Framework can start... log_off() self.assertTrue(framework.start(), "Framework should be started") log_on() self.assertEqual(framework.get_state(), Bundle.ACTIVE, "Framework should be in ACTIVE state") self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be in RESOLVED state") # Stop the framework self.assertTrue(framework.stop(), "Framework should be stopped") # Remove raiser mode module_.raiser = False # Framework can start self.assertTrue(framework.start(), "Framework couldn't be started") self.assertEqual(framework.get_state(), Bundle.ACTIVE, "Framework should be in ACTIVE state") self.assertEqual(bundle.get_state(), Bundle.ACTIVE, "Bundle should be in ACTIVE state") # Set module in raiser mode module_.raiser = True # Stop the framework log_off() self.assertTrue(framework.stop(), "Framework couldn't be stopped") log_on() self.assertTrue(self.stopping, "Stop listener not called") FrameworkFactory.delete_framework()
def testUninstall(self): """ Tests if the framework raises an exception if uninstall() is called """ # Set up a framework framework = FrameworkFactory.get_framework() self.assertRaises(BundleException, framework.uninstall) # Even once started... framework.start() self.assertRaises(BundleException, framework.uninstall) framework.stop() FrameworkFactory.delete_framework(framework)
def testBundleZero(self): """ Tests if bundle 0 is the framework """ framework = FrameworkFactory.get_framework() self.assertIsNone(framework.get_bundle_by_name(None), "None name is not bundle 0") self.assertIs(framework, framework.get_bundle_by_id(0), "Invalid bundle 0") pelix_name = framework.get_symbolic_name() self.assertIs(framework, framework.get_bundle_by_name(pelix_name), "Invalid system bundle name") FrameworkFactory.delete_framework()
def testUninstall(self): """ Tests if the framework raises an exception if uninstall() is called """ # Set up a framework framework = FrameworkFactory.get_framework() self.assertRaises(BundleException, framework.uninstall) # Even once started... framework.start() self.assertRaises(BundleException, framework.uninstall) framework.stop() FrameworkFactory.delete_framework()
def setUp(self): """ Starts a framework and install the shell bundle """ # Start the framework self.framework = FrameworkFactory.get_framework() self.framework.start() self.context = self.framework.get_bundle_context() # Install the bundle self.context.install_bundle("pelix.shell.core").start() # Get the utility service svc_ref = self.context.get_service_reference(SERVICE_SHELL_UTILS) self.utility = self.context.get_service(svc_ref)
def setUp(self): """ Called before each test. Initiates a framework. """ # Prepare the framework self.framework = FrameworkFactory.get_framework() self.framework.start() context = self.framework.get_bundle_context() # Install & start the waiting list bundle install_bundle(self.framework, "pelix.ipopo.waiting") # Get the service svc_ref = context.get_service_reference( constants.SERVICE_IPOPO_WAITING_LIST) self.waiting = context.get_service(svc_ref)
def setUp(self): """ Starts a framework and install the shell bundle """ # Start the framework self.framework = FrameworkFactory.get_framework() self.framework.start() self.context = self.framework.get_bundle_context() # Install the shell bundle self.context.install_bundle("pelix.ipopo.core").start() self.context.install_bundle("pelix.shell.core").start() # Get the local shell self.shell = self.context.get_service( self.context.get_service_reference(SERVICE_SHELL))
def framework(self) -> Framework: """ The currently running Pelix framework instance, or a new one if none is running (anyway, the framework instance will continue after deletion of this BundleLoader instance) """ if FrameworkFactory.is_framework_running(): self._framework = FrameworkFactory.get_framework() # Do not use self.context, because it will call back this. context = self._framework.get_bundle_context() if not context.get_service_reference(SERVICE_IPOPO): self._framework.install_bundle(SERVICE_IPOPO) else: self._framework = pelix.framework.create_framework(()) self._framework.install_bundle(SERVICE_IPOPO) self._framework.start() return self._framework
def testPropertiesWithoutPreset(self): """ Test framework properties """ pelix_test_name = "PELIX_TEST" pelix_test = "42" # Test without pre-set properties framework = FrameworkFactory.get_framework() self.assertIsNone(framework.get_property(pelix_test_name), "Magic property value") os.environ[pelix_test_name] = pelix_test self.assertEqual(framework.get_property(pelix_test_name), pelix_test, "Invalid property value") del os.environ[pelix_test_name] FrameworkFactory.delete_framework()
def setUp(self): """ Sets up the test environment """ # Start a framework self.framework = FrameworkFactory.get_framework() self.framework.start() # Install iPOPO self.ipopo = install_ipopo(self.framework) # Install HTTP service install_bundle(self.framework, "pelix.http.basic") # Install test bundle self.servlets = install_bundle(self.framework, "tests.http.servlets_bundle")
def testInsideFramework(self): """ Tests the behavior of a manipulated class attributes """ # Start the framework self.framework = FrameworkFactory.get_framework() self.framework.start() ipopo = install_ipopo(self.framework) module = install_bundle(self.framework) # Instantiate the test class instance = module.ComponentFactoryA() # Check fields presence and values self.assertTrue( instance._test_ctrl, "Default service controller is On") self.assertIsNone(instance._req_1, "Requirement is not None") self.assertEqual( instance.prop_1, 10, "Constructor property value lost") self.assertEqual(instance.usable, True, "Incorrect property value") del instance # Instantiate component A (validated) instance = ipopo.instantiate(module.FACTORY_A, NAME_A) # Check fields presence and values self.assertTrue( instance._test_ctrl, "Default service controller is On") self.assertIsNone(instance._req_1, "Requirement is not None") self.assertIsNone(instance.prop_1, "Default property value is None") self.assertEqual(instance.usable, True, "Incorrect property value") instance.prop_1 = 42 instance.usable = False self.assertEqual(instance.prop_1, 42, "Property value not modified") self.assertEqual(instance.usable, False, "Property value not modified") # Set A usable again instance.change(True) self.assertEqual(instance.usable, True, "Property value not modified")
def testInsideFramework(self): """ Tests the behavior of a manipulated class attributes """ # Start the framework self.framework = FrameworkFactory.get_framework() self.framework.start() ipopo = install_ipopo(self.framework) module = install_bundle(self.framework) # Instantiate the test class instance = module.ComponentFactoryA() # Check fields presence and values self.assertTrue(instance._test_ctrl, "Default service controller is On") self.assertIsNone(instance._req_1, "Requirement is not None") self.assertEqual(instance.prop_1, 10, "Constructor property value lost") self.assertEqual(instance.usable, True, "Incorrect property value") del instance # Instantiate component A (validated) instance = ipopo.instantiate(module.FACTORY_A, NAME_A) # Check fields presence and values self.assertTrue(instance._test_ctrl, "Default service controller is On") self.assertIsNone(instance._req_1, "Requirement is not None") self.assertIsNone(instance.prop_1, "Default property value is None") self.assertEqual(instance.usable, True, "Incorrect property value") instance.prop_1 = 42 instance.usable = False self.assertEqual(instance.prop_1, 42, "Property value not modified") self.assertEqual(instance.usable, False, "Property value not modified") # Set A usable again instance.change(True) self.assertEqual(instance.usable, True, "Property value not modified")
def test_init_bundle_loader_from_scratch(delete_framework): """ Tests that creating a Loader instance will start a correctly configured Pelix framework """ assert not FrameworkFactory.is_framework_running() loader = BundleLoader() _ = loader.framework # a first call for initiating the framework framework = FrameworkFactory.get_framework() assert FrameworkFactory.is_framework_running() assert framework is loader.framework assert framework.get_bundle_by_name("pelix.ipopo.core") is not None # Framework outlives the Loader del loader assert FrameworkFactory.is_framework_running() # Another instance gets back the framework loader = BundleLoader() assert framework is loader.framework
def testStopListener(self): """ Test the framework stop event """ # Set up a framework framework = FrameworkFactory.get_framework() framework.start() context = framework.get_bundle_context() # Assert initial state self.assertFalse(self.stopping, "Invalid initial state") # Register the stop listener self.assertTrue(context.add_framework_stop_listener(self), "Can't register the stop listener") log_off() self.assertFalse(context.add_framework_stop_listener(self), "Stop listener registered twice") log_on() # Assert running state self.assertFalse(self.stopping, "Invalid running state") # Stop the framework framework.stop() # Assert the listener has been called self.assertTrue(self.stopping, "Stop listener hasn't been called") # Unregister the listener self.assertTrue(context.remove_framework_stop_listener(self), "Can't unregister the stop listener") log_off() self.assertFalse(context.remove_framework_stop_listener(self), "Stop listener unregistered twice") log_on() FrameworkFactory.delete_framework()
def testStopListener(self): """ Test the framework stop event """ # Set up a framework framework = FrameworkFactory.get_framework() framework.start() context = framework.get_bundle_context() # Assert initial state self.assertFalse(self.stopping, "Invalid initial state") # Register the stop listener self.assertTrue(context.add_framework_stop_listener(self), "Can't register the stop listener") log_off() self.assertFalse(context.add_framework_stop_listener(self), "Stop listener registered twice") log_on() # Assert running state self.assertFalse(self.stopping, "Invalid running state") # Stop the framework framework.stop() # Assert the listener has been called self.assertTrue(self.stopping, "Stop listener hasn't been called") # Unregister the listener self.assertTrue(context.remove_framework_stop_listener(self), "Can't unregister the stop listener") log_off() self.assertFalse(context.remove_framework_stop_listener(self), "Stop listener unregistered twice") log_on() FrameworkFactory.delete_framework(framework)
def testFrameworkDoubleStart(self): """ Tests double calls to start and stop """ framework = FrameworkFactory.get_framework() context = framework.get_bundle_context() # Register the stop listener context.add_framework_stop_listener(self) self.assertTrue(framework.start(), "Framework couldn't be started") self.assertFalse(framework.start(), "Framework started twice") # Stop the framework self.assertTrue(framework.stop(), "Framework couldn't be stopped") self.assertTrue(self.stopping, "Stop listener not called") self.stopping = False self.assertFalse(framework.stop(), "Framework stopped twice") self.assertFalse(self.stopping, "Stop listener called twice") FrameworkFactory.delete_framework()
def testFrameworkStopRaiser(self): """ Tests framework start and stop with a bundle raising exception """ framework = FrameworkFactory.get_framework() context = framework.get_bundle_context() # Register the stop listener context.add_framework_stop_listener(self) # Install the bundle bundle = context.install_bundle(SIMPLE_BUNDLE) module_ = bundle.get_module() # Set module in non-raiser mode module_.raiser = False # Framework can start... log_off() self.assertTrue(framework.start(), "Framework should be started") self.assertEqual(framework.get_state(), Bundle.ACTIVE, "Framework should be in ACTIVE state") self.assertEqual(bundle.get_state(), Bundle.ACTIVE, "Bundle should be in ACTIVE state") log_on() # Set module in raiser mode module_.raiser = True # Bundle must raise the exception and stay active log_off() self.assertRaises(BundleException, bundle.stop) self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be in RESOLVED state") log_on() # Stop framework framework.stop() FrameworkFactory.delete_framework()
def testPropertiesWithPreset(self): """ Test framework properties """ pelix_test_name = "PELIX_TEST" pelix_test = "42" pelix_test_2 = "421" # Test with pre-set properties props = {pelix_test_name: pelix_test} framework = FrameworkFactory.get_framework(props) self.assertEqual(framework.get_property(pelix_test_name), pelix_test, "Invalid property value (preset value not set)") # Pre-set property has priority os.environ[pelix_test_name] = pelix_test_2 self.assertEqual(framework.get_property(pelix_test_name), pelix_test, "Invalid property value (preset has priority)") del os.environ[pelix_test_name] FrameworkFactory.delete_framework()
def testFrameworkStopRaiser(self): """ Tests framework start and stop with a bundle raising exception """ framework = FrameworkFactory.get_framework() context = framework.get_bundle_context() # Register the stop listener context.add_framework_stop_listener(self) # Install the bundle bundle = context.install_bundle(SIMPLE_BUNDLE) module = bundle.get_module() # Set module in non-raiser mode module.raiser = False # Framework can start... log_off() self.assertTrue(framework.start(), "Framework should be started") self.assertEqual(framework.get_state(), Bundle.ACTIVE, "Framework should be in ACTIVE state") self.assertEqual(bundle.get_state(), Bundle.ACTIVE, "Bundle should be in ACTIVE state") log_on() # Set module in raiser mode module.raiser = True # Bundle must raise the exception and stay active log_off() self.assertRaises(BundleException, bundle.stop) self.assertEqual(bundle.get_state(), Bundle.RESOLVED, "Bundle should be in RESOLVED state") log_on() # Stop framework framework.stop() FrameworkFactory.delete_framework(framework)
def testPropertiesWithPreset(self): """ Test framework properties """ pelix_test_name = "PELIX_TEST" pelix_test = "42" pelix_test_2 = "421" # Test with pre-set properties props = {pelix_test_name: pelix_test} framework = FrameworkFactory.get_framework(props) self.assertEqual(framework.get_property(pelix_test_name), pelix_test, "Invalid property value (preset value not set)") # Pre-set property has priority os.environ[pelix_test_name] = pelix_test_2 self.assertEqual(framework.get_property(pelix_test_name), pelix_test, "Invalid property value (preset has priority)") del os.environ[pelix_test_name] FrameworkFactory.delete_framework(framework)
def __run_test(self, transport_bundle, exporter_factory, importer_factory): """ Runs a remote service call test :param transport_bundle: Transport implementation bundle to use :param exporter_factory: Name of the RS exporter factory :param importer_factory: Name of the RS importer factory :raise queue.Empty: Peer took to long to answer :raise ValueError: Test failed """ # Define components components = [(exporter_factory, "rs-exporter"), (importer_factory, "rs-importer")] # Start the remote framework status_queue = Queue() peer = WrappedProcess(target=export_framework, args=(status_queue, transport_bundle, components)) peer.start() try: # Wait for the ready state state = status_queue.get(4) self.assertEqual(state, "ready") # Load the local framework (after the fork) framework = load_framework(transport_bundle, components) context = framework.get_bundle_context() # Look for the remote service for _ in range(10): svc_ref = context.get_service_reference(SVC_SPEC) if svc_ref is not None: break time.sleep(.5) else: self.fail("Remote Service not found") # Get it svc = context.get_service(svc_ref) # Dummy call result = svc.dummy() state = status_queue.get(2) self.assertEqual(state, "call-dummy") self.assertIsNone(result, "Dummy didn't returned None: {0}".format(result)) # Echo call for value in (None, "Test", 42, [1, 2, 3], {"a": "b"}): result = svc.echo(value) # Check state state = status_queue.get(2) self.assertEqual(state, "call-echo") # Check result self.assertEqual(result, value) # Exception handling try: svc.error() except: # The error has been propagated state = status_queue.get(2) self.assertEqual(state, "call-error") else: self.fail("No exception raised calling 'error'") # Call undefined method try: svc.undefined() except: # The error has been propagated: OK pass else: self.fail("No exception raised calling an undefined method") # Stop the peer svc.stop() # Wait for the peer to stop state = status_queue.get(2) self.assertEqual(state, "stopping") # Wait a bit more, to let coverage save its files time.sleep(.1) finally: # Stop everything (and delete the framework in any case FrameworkFactory.delete_framework(FrameworkFactory.get_framework()) peer.terminate() status_queue.close()
def setUp(self): """ Called before each test. Initiates a framework. """ self.framework = FrameworkFactory.get_framework() self.framework.start()