From 3329dd108b69475bdac567c972a96d9199d8681f Mon Sep 17 00:00:00 2001 From: Thomas Calmant Date: Fri, 3 Nov 2017 16:03:37 +0100 Subject: [PATCH] Small code review of test files Also removed Python 2.6 specific code --- tests/framework/service_bundle.py | 10 +-- tests/framework/service_factory_bundle.py | 1 - tests/framework/test_bundles.py | 86 ++++++++++--------- tests/framework/test_events.py | 5 +- tests/framework/test_framework.py | 29 ++++--- tests/framework/test_services.py | 14 +-- tests/framework/test_utils.py | 1 + tests/framework/vault/pkg_fail/__init__.py | 2 + tests/framework/vault/pkg_fail/invalid.py | 3 + .../framework/vault/pkg_fail/pkg2/__init__.py | 2 + .../framework/vault/pkg_fail/pkg2/invalid.py | 3 + tests/framework/vault/pkg_fail/pkg2/valid1.py | 2 + tests/framework/vault/pkg_fail/pkg2/valid2.py | 2 + tests/framework/vault/pkg_fail/valid1.py | 2 + tests/framework/vault/pkg_fail/valid2.py | 2 + tests/framework/vault/pkg_invalid/__init__.py | 3 + tests/framework/vault/pkg_invalid/invalid.py | 3 + tests/framework/vault/pkg_invalid/valid1.py | 2 + tests/framework/vault/pkg_ok/__init__.py | 2 + tests/framework/vault/pkg_ok/__main__.py | 3 + tests/framework/vault/pkg_ok/pkg2/__init__.py | 2 + tests/framework/vault/pkg_ok/pkg2/valid1.py | 2 + tests/framework/vault/pkg_ok/pkg2/valid2.py | 2 + tests/framework/vault/pkg_ok/valid1.py | 2 + tests/framework/vault/pkg_ok/valid2.py | 2 + tests/http/test_routing.py | 2 +- tests/misc/test_jabsorb.py | 10 +-- tests/remote/test_dispatcher.py | 2 +- tests/remote/test_edef.py | 6 +- tests/services/test_configadmin.py | 19 ++-- tests/services/test_eventadmin.py | 4 +- 31 files changed, 137 insertions(+), 93 deletions(-) diff --git a/tests/framework/service_bundle.py b/tests/framework/service_bundle.py index 870f2259..24da394d 100644 --- a/tests/framework/service_bundle.py +++ b/tests/framework/service_bundle.py @@ -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 @@ -26,6 +26,7 @@ def __init__(self): """ Constructor """ + IEchoService.__init__(self) self.toto = 0 self.registration = None @@ -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 diff --git a/tests/framework/service_factory_bundle.py b/tests/framework/service_factory_bundle.py index a4970ce9..c376bbce 100644 --- a/tests/framework/service_factory_bundle.py +++ b/tests/framework/service_factory_bundle.py @@ -54,7 +54,6 @@ def unget_service(self, bundle, registration): self.made_for.remove(client_id) - class RegistrationKeeper: """ Keeps track of factory registration diff --git a/tests/framework/test_bundles.py b/tests/framework/test_bundles.py index 1c7f2ce1..8cf2de6f 100644 --- a/tests/framework/test_bundles.py +++ b/tests/framework/test_bundles.py @@ -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() @@ -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() @@ -143,11 +143,11 @@ 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() @@ -155,16 +155,16 @@ def testLifeCycleRecalls(self): 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() @@ -172,13 +172,13 @@ def testLifeCycleRecalls(self): 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() @@ -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) @@ -211,21 +211,21 @@ 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) @@ -233,8 +233,8 @@ def testLifeCycleExceptions(self): 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() @@ -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} @@ -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, @@ -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() @@ -459,9 +461,9 @@ def testLocalBundle(self): # ------------------------------------------------------------------------------ + if __name__ == "__main__": # Set logging level import logging logging.basicConfig(level=logging.DEBUG) - unittest.main() diff --git a/tests/framework/test_events.py b/tests/framework/test_events.py index dfcd1ea7..8efcdc4f 100644 --- a/tests/framework/test_events.py +++ b/tests/framework/test_events.py @@ -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 @@ -370,6 +370,7 @@ def testServiceModified(self): # ------------------------------------------------------------------------------ + if __name__ == "__main__": # Set logging level import logging diff --git a/tests/framework/test_framework.py b/tests/framework/test_framework.py index fff3b918..56c9285b 100644 --- a/tests/framework/test_framework.py +++ b/tests/framework/test_framework.py @@ -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() @@ -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") @@ -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() @@ -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() @@ -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() @@ -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") @@ -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") @@ -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() @@ -519,6 +519,7 @@ def testWaitForStopTimeout(self): # ------------------------------------------------------------------------------ + if __name__ == "__main__": # Set logging level import logging diff --git a/tests/framework/test_services.py b/tests/framework/test_services.py index a921d9c1..9948099a 100644 --- a/tests/framework/test_services.py +++ b/tests/framework/test_services.py @@ -62,7 +62,7 @@ def testBundleRegister(self): # Install the service bundle bundle = context.install_bundle(self.test_bundle_name) bundle_context = bundle.get_bundle_context() - module = bundle.get_module() + module_ = bundle.get_module() # Assert we can't access the service ref1 = context.get_service_reference(IEchoService) @@ -129,19 +129,19 @@ def testBundleRegister(self): # services self.assertListEqual( [], context.get_service_references(IEchoService, None), - "Framework bundle shoudln't get the echo service") + "Framework bundle shouldn't get the echo service") self.assertListEqual( [], context.get_service_references(IEchoService, svc_filter), - "Framework bundle shoudln't get the filtered echo service") + "Framework bundle shouldn't get the filtered echo service") # Get the service svc = context.get_service(ref1) assert isinstance(svc, IEchoService) # Validate the reference - self.assertIs(svc, module.service, "Not the same service instance...") + self.assertIs(svc, module_.service, "Not the same service instance...") # Unget the service context.unget_service(ref1) @@ -182,12 +182,12 @@ def testBundleUninstall(self): bundle = context.install_bundle(self.test_bundle_name) assert isinstance(bundle, Bundle) - module = bundle.get_module() + module_ = bundle.get_module() # --- Start it (registers a service) --- bundle.start() - self.assertIsNotNone(module.service, "The service instance is missing") + self.assertIsNotNone(module_.service, "The service instance is missing") # Get the reference ref = context.get_service_reference(IEchoService) @@ -205,7 +205,6 @@ def testBundleUninstall(self): context.unget_service(ref) self.assertNotIn(ref, self.framework.get_services_in_use(), "Reference usage not removed") - svc = None # --- Uninstall the bundle without stopping it first --- bundle.uninstall() @@ -409,6 +408,7 @@ def testInvalidGetService(self): # ------------------------------------------------------------------------------ + if __name__ == "__main__": # Set logging level import logging diff --git a/tests/framework/test_utils.py b/tests/framework/test_utils.py index 9dcb5e71..c47560a6 100644 --- a/tests/framework/test_utils.py +++ b/tests/framework/test_utils.py @@ -102,6 +102,7 @@ def testCreateFrameworkAutoStart(self): # ------------------------------------------------------------------------------ + if __name__ == "__main__": # Set logging level import logging diff --git a/tests/framework/vault/pkg_fail/__init__.py b/tests/framework/vault/pkg_fail/__init__.py index e69de29b..1975336b 100644 --- a/tests/framework/vault/pkg_fail/__init__.py +++ b/tests/framework/vault/pkg_fail/__init__.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- diff --git a/tests/framework/vault/pkg_fail/invalid.py b/tests/framework/vault/pkg_fail/invalid.py index fe3ba1ed..cbc1e1cb 100644 --- a/tests/framework/vault/pkg_fail/invalid.py +++ b/tests/framework/vault/pkg_fail/invalid.py @@ -1 +1,4 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- + raise ImportError("Invalid bundle") diff --git a/tests/framework/vault/pkg_fail/pkg2/__init__.py b/tests/framework/vault/pkg_fail/pkg2/__init__.py index e69de29b..1975336b 100644 --- a/tests/framework/vault/pkg_fail/pkg2/__init__.py +++ b/tests/framework/vault/pkg_fail/pkg2/__init__.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- diff --git a/tests/framework/vault/pkg_fail/pkg2/invalid.py b/tests/framework/vault/pkg_fail/pkg2/invalid.py index fe3ba1ed..cbc1e1cb 100644 --- a/tests/framework/vault/pkg_fail/pkg2/invalid.py +++ b/tests/framework/vault/pkg_fail/pkg2/invalid.py @@ -1 +1,4 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- + raise ImportError("Invalid bundle") diff --git a/tests/framework/vault/pkg_fail/pkg2/valid1.py b/tests/framework/vault/pkg_fail/pkg2/valid1.py index e69de29b..1975336b 100644 --- a/tests/framework/vault/pkg_fail/pkg2/valid1.py +++ b/tests/framework/vault/pkg_fail/pkg2/valid1.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- diff --git a/tests/framework/vault/pkg_fail/pkg2/valid2.py b/tests/framework/vault/pkg_fail/pkg2/valid2.py index e69de29b..1975336b 100644 --- a/tests/framework/vault/pkg_fail/pkg2/valid2.py +++ b/tests/framework/vault/pkg_fail/pkg2/valid2.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- diff --git a/tests/framework/vault/pkg_fail/valid1.py b/tests/framework/vault/pkg_fail/valid1.py index e69de29b..1975336b 100644 --- a/tests/framework/vault/pkg_fail/valid1.py +++ b/tests/framework/vault/pkg_fail/valid1.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- diff --git a/tests/framework/vault/pkg_fail/valid2.py b/tests/framework/vault/pkg_fail/valid2.py index e69de29b..1975336b 100644 --- a/tests/framework/vault/pkg_fail/valid2.py +++ b/tests/framework/vault/pkg_fail/valid2.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- diff --git a/tests/framework/vault/pkg_invalid/__init__.py b/tests/framework/vault/pkg_invalid/__init__.py index ffc8f928..ed540969 100644 --- a/tests/framework/vault/pkg_invalid/__init__.py +++ b/tests/framework/vault/pkg_invalid/__init__.py @@ -1 +1,4 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- + raise ImportError("Invalid package") diff --git a/tests/framework/vault/pkg_invalid/invalid.py b/tests/framework/vault/pkg_invalid/invalid.py index fe3ba1ed..cbc1e1cb 100644 --- a/tests/framework/vault/pkg_invalid/invalid.py +++ b/tests/framework/vault/pkg_invalid/invalid.py @@ -1 +1,4 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- + raise ImportError("Invalid bundle") diff --git a/tests/framework/vault/pkg_invalid/valid1.py b/tests/framework/vault/pkg_invalid/valid1.py index e69de29b..1975336b 100644 --- a/tests/framework/vault/pkg_invalid/valid1.py +++ b/tests/framework/vault/pkg_invalid/valid1.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- diff --git a/tests/framework/vault/pkg_ok/__init__.py b/tests/framework/vault/pkg_ok/__init__.py index e69de29b..1975336b 100644 --- a/tests/framework/vault/pkg_ok/__init__.py +++ b/tests/framework/vault/pkg_ok/__init__.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- diff --git a/tests/framework/vault/pkg_ok/__main__.py b/tests/framework/vault/pkg_ok/__main__.py index 30844645..5617f4c2 100644 --- a/tests/framework/vault/pkg_ok/__main__.py +++ b/tests/framework/vault/pkg_ok/__main__.py @@ -1 +1,4 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- + raise ImportError("I shouldn't be imported") diff --git a/tests/framework/vault/pkg_ok/pkg2/__init__.py b/tests/framework/vault/pkg_ok/pkg2/__init__.py index e69de29b..1975336b 100644 --- a/tests/framework/vault/pkg_ok/pkg2/__init__.py +++ b/tests/framework/vault/pkg_ok/pkg2/__init__.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- diff --git a/tests/framework/vault/pkg_ok/pkg2/valid1.py b/tests/framework/vault/pkg_ok/pkg2/valid1.py index e69de29b..1975336b 100644 --- a/tests/framework/vault/pkg_ok/pkg2/valid1.py +++ b/tests/framework/vault/pkg_ok/pkg2/valid1.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- diff --git a/tests/framework/vault/pkg_ok/pkg2/valid2.py b/tests/framework/vault/pkg_ok/pkg2/valid2.py index e69de29b..1975336b 100644 --- a/tests/framework/vault/pkg_ok/pkg2/valid2.py +++ b/tests/framework/vault/pkg_ok/pkg2/valid2.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- diff --git a/tests/framework/vault/pkg_ok/valid1.py b/tests/framework/vault/pkg_ok/valid1.py index e69de29b..1975336b 100644 --- a/tests/framework/vault/pkg_ok/valid1.py +++ b/tests/framework/vault/pkg_ok/valid1.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- diff --git a/tests/framework/vault/pkg_ok/valid2.py b/tests/framework/vault/pkg_ok/valid2.py index e69de29b..1975336b 100644 --- a/tests/framework/vault/pkg_ok/valid2.py +++ b/tests/framework/vault/pkg_ok/valid2.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +# -- Content-Encoding: UTF-8 -- diff --git a/tests/http/test_routing.py b/tests/http/test_routing.py index 496740ac..44eba745 100644 --- a/tests/http/test_routing.py +++ b/tests/http/test_routing.py @@ -108,7 +108,7 @@ def dummy(): pass for valid in (None, ("POST",), ["GET"], - ("GET", "HEAD"), ["GET, HEAD"], set(("HEAD", "GET")), + ("GET", "HEAD"), ["GET, HEAD"], {"HEAD", "GET"}, frozenset(("GET", "HEAD"))): self.assertIs(routing.Http("/", valid)(dummy), dummy) diff --git a/tests/misc/test_jabsorb.py b/tests/misc/test_jabsorb.py index 3723932a..d8c07bd2 100644 --- a/tests/misc/test_jabsorb.py +++ b/tests/misc/test_jabsorb.py @@ -32,7 +32,7 @@ def testIsBuiltin(self): Tests the _is_builtin() method """ for item in (int, 42, str, "toto", bool, True, float, 3.14, - dict, {"a": "b"}, set, set([12]), tuple, (1, 2, 3), + dict, {"a": "b"}, set, {12}, tuple, (1, 2, 3), list, [4, 5, 6]): self.assertTrue(jabsorb._is_builtin(item), "Item {0} should be built-in".format(item)) @@ -47,7 +47,7 @@ def testMirror(self): """ value = {"list": [1, 2, 3], "tuple": (1, 2, 3), - "set": set((1, 2, 3)), + "set": {1, 2, 3}, "dict": {"a": "b", "c": "d"}, "int": 42, "float": 3.14, @@ -120,7 +120,7 @@ def __eq__(self, other): self.assertIs(revert, bean) self.assertEqual(revert.list, [1, 2, 3]) self.assertEqual(revert.tuple, (1, 2, 3)) - self.assertEqual(revert.set, set((1, 2, 3))) + self.assertEqual(revert.set, {1, 2, 3}) def testHashableType(self): """ @@ -151,7 +151,7 @@ def testDoubleConvert(self): """ value = {"list": [1, 2, 3], "tuple": (1, 2, 3), - "set": set((1, 2, 3)), + "set": {1, 2, 3}, "dict": {"a": "b", "c": "d"}, "int": 42, "float": 3.14, @@ -184,7 +184,7 @@ def testJsonAndJavaClass(self): # Prepare a fake bean value = {"list": [1, 2, 3], "tuple": (1, 2, 3), - "set": set((1, 2, 3)), + "set": {1, 2, 3}, "dict": {"a": "b", "c": "d"}, "int": 42, "float": 3.14, diff --git a/tests/remote/test_dispatcher.py b/tests/remote/test_dispatcher.py index f2b34727..49488d8a 100644 --- a/tests/remote/test_dispatcher.py +++ b/tests/remote/test_dispatcher.py @@ -580,7 +580,7 @@ def testExportReject(self): # Compute exported interfaces exported = ['python:/' + spec for spec - in set([spec_1, spec_2, spec_3]).difference(reject)] + in {spec_1, spec_2, spec_3}.difference(reject)] # Check it endpoint = self.service.get_endpoints()[0] diff --git a/tests/remote/test_edef.py b/tests/remote/test_edef.py index 8e03b884..efbf13c5 100644 --- a/tests/remote/test_edef.py +++ b/tests/remote/test_edef.py @@ -111,9 +111,9 @@ def testEdefIOTypes(self): "list_str": ["a", "b", "c"], "list_int": [1, 2, 3], "list_float": [1.0, 2.0, 3.0], - "set_str": set(["a", "b", "c"]), - "set_int": set([1, 2, 3]), - "set_float": set([1.0, 2.0, 3.0])} + "set_str": {"a", "b", "c"}, + "set_int": {1, 2, 3}, + "set_float": {1.0, 2.0, 3.0}} all_props = properties.copy() all_props[pelix.remote.PROP_ENDPOINT_ID] = 'toto' diff --git a/tests/services/test_configadmin.py b/tests/services/test_configadmin.py index 14e2bce8..02b9d772 100644 --- a/tests/services/test_configadmin.py +++ b/tests/services/test_configadmin.py @@ -174,7 +174,7 @@ def testListConfiguration(self): self.assertFalse(config.is_valid(), "Fresh configuration is valid") # It must be visible, but must not match filters - self.assertSetEqual(self.config.list_configurations(), set([config]), + self.assertSetEqual(self.config.list_configurations(), {config}, "Incorrect result set") ldap_filter = "({0}={1})".format(services.CONFIG_PROP_PID, pid) @@ -185,7 +185,7 @@ def testListConfiguration(self): config.update({'arthur': 'dent'}) # It must be visible, even with filters - self.assertSetEqual(self.config.list_configurations(), set([config]), + self.assertSetEqual(self.config.list_configurations(), {config}, "Incorrect result set") filters = [ # PID @@ -198,20 +198,19 @@ def testListConfiguration(self): ] for ldap_filter in filters: - self.assertSetEqual(self.config.list_configurations(ldap_filter), - set([config]), - "Configuration doesn't match filter {0}" - .format(ldap_filter)) + self.assertSetEqual( + self.config.list_configurations(ldap_filter), {config}, + "Configuration doesn't match filter {0}".format(ldap_filter)) # Add a new configuration config2 = self.config.get_configuration(pid + "-bis") - self.assertSetEqual(self.config.list_configurations(), - set([config, config2]), - "Incorrect result set") + self.assertSetEqual( + self.config.list_configurations(), {config, config2}, + "Incorrect result set") # Delete it config2.delete() - self.assertSetEqual(self.config.list_configurations(), set([config]), + self.assertSetEqual(self.config.list_configurations(), {config}, "Incorrect result set") # Delete the first one diff --git a/tests/services/test_eventadmin.py b/tests/services/test_eventadmin.py index a2ce8acf..68a85c15 100644 --- a/tests/services/test_eventadmin.py +++ b/tests/services/test_eventadmin.py @@ -162,7 +162,7 @@ def testFilters(self): # Send event, with matching properties for topic in ('/titi/toto', '/toto/', '/titi/42', '/titi/toto/tata'): - for value in (42, '42', [1, 2, 42, 20], set((42, 10)), + for value in (42, '42', [1, 2, 42, 20], {42, 10}, (10, 21, 42)): evt_props = {'answer': value} self.eventadmin.send(topic, evt_props) @@ -175,7 +175,7 @@ def testFilters(self): self.assertEqual(handler.pop_event(), topic) # Send events, with a non-matching properties - for value in (' 42 ', 21, [1, 2, 3], (4, 5, 6), set((7, 8, 9))): + for value in (' 42 ', 21, [1, 2, 3], (4, 5, 6), {7, 8, 9}): self.eventadmin.send(topic, {'answer': value}) self.assertEqual(handler.pop_event(), None)