Skip to content

Commit

Permalink
Small code review of test files
Browse files Browse the repository at this point in the history
Also removed Python 2.6 specific code
  • Loading branch information
tcalmant committed Nov 3, 2017
1 parent f5152c1 commit 3329dd1
Show file tree
Hide file tree
Showing 31 changed files with 137 additions and 93 deletions.
10 changes: 5 additions & 5 deletions tests/framework/service_bundle.py
Expand Up @@ -6,12 +6,12 @@
:author: Thomas Calmant
"""

__version__ = (1, 0, 0)

from pelix.constants import BundleActivator
from pelix.framework import BundleContext
from tests.interfaces import IEchoService

__version__ = (1, 0, 0)

registered = False
unregistered = False
service = None
Expand All @@ -26,6 +26,7 @@ def __init__(self):
"""
Constructor
"""
IEchoService.__init__(self)
self.toto = 0
self.registration = None

Expand Down Expand Up @@ -63,9 +64,8 @@ def start(self, context):

# Register the service
self.svc = ServiceTest()
self.svc.registration = \
context.register_service(IEchoService, self.svc,
{"test": True, "answer": 0})
self.svc.registration = context.register_service(
IEchoService, self.svc, {"test": True, "answer": 0})

global service
service = self.svc
Expand Down
1 change: 0 additions & 1 deletion tests/framework/service_factory_bundle.py
Expand Up @@ -54,7 +54,6 @@ def unget_service(self, bundle, registration):
self.made_for.remove(client_id)



class RegistrationKeeper:
"""
Keeps track of factory registration
Expand Down
86 changes: 44 additions & 42 deletions tests/framework/test_bundles.py
Expand Up @@ -78,23 +78,23 @@ def testCompatibility(self, test_bundle_id=False):
"Not the first bundle in framework")

# Get the internal module
module = bundle.get_module()
module_ = bundle.get_module()

# Assert initial state
self.assertFalse(module.started, "Bundle should not be started yet")
self.assertFalse(module.stopped, "Bundle should not be stopped yet")
self.assertFalse(module_.started, "Bundle should not be started yet")
self.assertFalse(module_.stopped, "Bundle should not be stopped yet")

# Activator
bundle.start()

self.assertTrue(module.started, "Bundle should be started now")
self.assertFalse(module.stopped, "Bundle should not be stopped yet")
self.assertTrue(module_.started, "Bundle should be started now")
self.assertFalse(module_.stopped, "Bundle should not be stopped yet")

# De-activate
bundle.stop()

self.assertTrue(module.started, "Bundle should be changed")
self.assertTrue(module.stopped, "Bundle should be stopped now")
self.assertTrue(module_.started, "Bundle should be changed")
self.assertTrue(module_.stopped, "Bundle should be stopped now")

# Uninstall (validated in another test)
bundle.uninstall()
Expand All @@ -113,23 +113,23 @@ def testLifeCycle(self, test_bundle_id=False):
"Not the first bundle in framework")

# Get the internal module
module = bundle.get_module()
module_ = bundle.get_module()

# Assert initial state
self.assertFalse(module.started, "Bundle should not be started yet")
self.assertFalse(module.stopped, "Bundle should not be stopped yet")
self.assertFalse(module_.started, "Bundle should not be started yet")
self.assertFalse(module_.stopped, "Bundle should not be stopped yet")

# Activator
bundle.start()

self.assertTrue(module.started, "Bundle should be started now")
self.assertFalse(module.stopped, "Bundle should not be stopped yet")
self.assertTrue(module_.started, "Bundle should be started now")
self.assertFalse(module_.stopped, "Bundle should not be stopped yet")

# De-activate
bundle.stop()

self.assertTrue(module.started, "Bundle should be changed")
self.assertTrue(module.stopped, "Bundle should be stopped now")
self.assertTrue(module_.started, "Bundle should be changed")
self.assertTrue(module_.stopped, "Bundle should be stopped now")

# Uninstall (validated in another test)
bundle.uninstall()
Expand All @@ -143,42 +143,42 @@ def testLifeCycleRecalls(self):
assert isinstance(bundle, Bundle)

# Get the internal module
module = bundle.get_module()
module_ = bundle.get_module()

# Assert initial state
self.assertFalse(module.started, "Bundle should not be started yet")
self.assertFalse(module.stopped, "Bundle should not be stopped yet")
self.assertFalse(module_.started, "Bundle should not be started yet")
self.assertFalse(module_.stopped, "Bundle should not be stopped yet")

# Activator
bundle.start()

self.assertEqual(bundle.get_state(), Bundle.ACTIVE,
"Bundle should be considered active")

self.assertTrue(module.started, "Bundle should be started now")
self.assertFalse(module.stopped, "Bundle should not be stopped yet")
self.assertTrue(module_.started, "Bundle should be started now")
self.assertFalse(module_.stopped, "Bundle should not be stopped yet")

# Recall activator
module.started = False
module_.started = False
bundle.start()
self.assertFalse(module.started, "Bundle shouldn't be started twice")
self.assertFalse(module_.started, "Bundle shouldn't be started twice")

# Reset to previous state
module.started = True
module_.started = True

# De-activate
bundle.stop()

self.assertNotEqual(bundle.get_state(), Bundle.ACTIVE,
"Bundle shouldn't be considered active")

self.assertTrue(module.started, "Bundle should be changed")
self.assertTrue(module.stopped, "Bundle should be stopped now")
self.assertTrue(module_.started, "Bundle should be changed")
self.assertTrue(module_.stopped, "Bundle should be stopped now")

# Recall activator
module.stopped = False
module_.stopped = False
bundle.stop()
self.assertFalse(module.stopped, "Bundle shouldn't be stopped twice")
self.assertFalse(module_.stopped, "Bundle shouldn't be stopped twice")

# Uninstall (validated in another test)
bundle.uninstall()
Expand All @@ -195,14 +195,14 @@ def testLifeCycleExceptions(self):
assert isinstance(bundle, Bundle)

# Get the internal module
module = bundle.get_module()
module_ = bundle.get_module()

# Assert initial state
self.assertFalse(module.started, "Bundle should not be started yet")
self.assertFalse(module.stopped, "Bundle should not be stopped yet")
self.assertFalse(module_.started, "Bundle should not be started yet")
self.assertFalse(module_.stopped, "Bundle should not be stopped yet")

# Activator with exception
module.raiser = True
module_.raiser = True

log_off()
self.assertRaises(BundleException, bundle.start)
Expand All @@ -211,30 +211,30 @@ def testLifeCycleExceptions(self):
# Assert post-exception state
self.assertNotEqual(bundle.get_state(), Bundle.ACTIVE,
"Bundle shouldn't be considered active")
self.assertFalse(module.started, "Bundle should not be started yet")
self.assertFalse(module.stopped, "Bundle should not be stopped yet")
self.assertFalse(module_.started, "Bundle should not be started yet")
self.assertFalse(module_.stopped, "Bundle should not be stopped yet")

# Activator, without exception
module.raiser = False
module_.raiser = False
bundle.start()

self.assertEqual(bundle.get_state(), Bundle.ACTIVE,
"Bundle should be considered active")

self.assertTrue(module.started, "Bundle should be started now")
self.assertFalse(module.stopped, "Bundle should not be stopped yet")
self.assertTrue(module_.started, "Bundle should be started now")
self.assertFalse(module_.stopped, "Bundle should not be stopped yet")

# De-activate with exception
module.raiser = True
module_.raiser = True

log_off()
self.assertRaises(BundleException, bundle.stop)
log_on()

self.assertNotEqual(bundle.get_state(), Bundle.ACTIVE,
"Bundle shouldn't be considered active")
self.assertTrue(module.started, "Bundle should be changed")
self.assertFalse(module.stopped, "Bundle should be stopped now")
self.assertTrue(module_.started, "Bundle should be changed")
self.assertFalse(module_.stopped, "Bundle should be stopped now")

# Uninstall (validated in another test)
bundle.uninstall()
Expand Down Expand Up @@ -305,6 +305,8 @@ def testUpdate(self):
Tests a bundle update
"""
bundle_content = """#!/usr/bin/python
# -- Content-Encoding: UTF-8 --
# Auto-generated bundle, for Pelix tests
__version__ = "{version}"
test_var = {test}
Expand Down Expand Up @@ -376,7 +378,7 @@ def testVersion(self):
self.assertEqual(bid, 1, "Invalid first bundle ID '{0:d}'".format(bid))

# Get the internal module
module = bundle.get_module()
module_ = bundle.get_module()

# Validate the bundle name
self.assertEqual(bundle.get_symbolic_name(), self.test_bundle_name,
Expand All @@ -391,9 +393,9 @@ def testVersion(self):
(bundle_without_ext, full_bundle_path))

# Validate the version number
self.assertEqual(bundle.get_version(), module.__version__,
self.assertEqual(bundle.get_version(), module_.__version__,
"Different versions found ({0} / {1})"
.format(bundle.get_version(), module.__version__))
.format(bundle.get_version(), module_.__version__))

# Remove the bundle
bundle.uninstall()
Expand Down Expand Up @@ -459,9 +461,9 @@ def testLocalBundle(self):

# ------------------------------------------------------------------------------


if __name__ == "__main__":
# Set logging level
import logging
logging.basicConfig(level=logging.DEBUG)

unittest.main()
5 changes: 3 additions & 2 deletions tests/framework/test_events.py
Expand Up @@ -288,8 +288,8 @@ def testServiceEventsNoStop(self):
self.reset_state()

# Uninstall the bundle, without unregistering the service
module = bundle.get_module()
module.unregister = False
module_ = bundle.get_module()
module_.unregister = False
bundle.uninstall()

# Assert the events have been received
Expand Down Expand Up @@ -370,6 +370,7 @@ def testServiceModified(self):

# ------------------------------------------------------------------------------


if __name__ == "__main__":
# Set logging level
import logging
Expand Down
29 changes: 15 additions & 14 deletions tests/framework/test_framework.py
Expand Up @@ -180,10 +180,10 @@ def testFrameworkStartRaiser(self):

# Install the bundle
bundle = context.install_bundle(SIMPLE_BUNDLE)
module = bundle.get_module()
module_ = bundle.get_module()

# Set module in raiser mode
module.raiser = True
module_.raiser = True

# Framework can start...
log_off()
Expand All @@ -200,7 +200,7 @@ def testFrameworkStartRaiser(self):
self.assertTrue(framework.stop(), "Framework should be stopped")

# Remove raiser mode
module.raiser = False
module_.raiser = False

# Framework can start
self.assertTrue(framework.start(), "Framework couldn't be started")
Expand All @@ -210,7 +210,7 @@ def testFrameworkStartRaiser(self):
"Bundle should be in ACTIVE state")

# Set module in raiser mode
module.raiser = True
module_.raiser = True

# Stop the framework
log_off()
Expand All @@ -233,10 +233,10 @@ def testFrameworkStopRaiser(self):

# Install the bundle
bundle = context.install_bundle(SIMPLE_BUNDLE)
module = bundle.get_module()
module_ = bundle.get_module()

# Set module in non-raiser mode
module.raiser = False
module_.raiser = False

# Framework can start...
log_off()
Expand All @@ -248,7 +248,7 @@ def testFrameworkStopRaiser(self):
log_on()

# Set module in raiser mode
module.raiser = True
module_.raiser = True

# Bundle must raise the exception and stay active
log_off()
Expand All @@ -270,11 +270,11 @@ def testFrameworkStopper(self):

# Install the bundle
bundle = context.install_bundle(SIMPLE_BUNDLE)
module = bundle.get_module()
module_ = bundle.get_module()

# Set module in raiser stop mode
module.fw_raiser = True
module.fw_raiser_stop = True
module_.fw_raiser = True
module_.fw_raiser_stop = True

log_off()
self.assertFalse(framework.start(), "Framework should be stopped")
Expand All @@ -285,7 +285,7 @@ def testFrameworkStopper(self):
log_on()

# Set module in raiser non-stop mode
module.fw_raiser_stop = False
module_.fw_raiser_stop = False

log_off()
self.assertTrue(framework.start(), "Framework should be stopped")
Expand All @@ -296,14 +296,14 @@ def testFrameworkStopper(self):
log_on()

# Start the module
module.fw_raiser = False
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
module_.fw_raiser = True
module_.fw_raiser_stop = True

# Stop the framework
log_off()
Expand Down Expand Up @@ -519,6 +519,7 @@ def testWaitForStopTimeout(self):

# ------------------------------------------------------------------------------


if __name__ == "__main__":
# Set logging level
import logging
Expand Down

0 comments on commit 3329dd1

Please sign in to comment.