mirror of
				https://github.com/ARM-software/workload-automation.git
				synced 2025-10-31 07:04:17 +00:00 
			
		
		
		
	Initial commit of open source Workload Automation.
This commit is contained in:
		
							
								
								
									
										0
									
								
								wlauto/external/louie/test/__init__.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								wlauto/external/louie/test/__init__.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										5
									
								
								wlauto/external/louie/test/conftest.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								wlauto/external/louie/test/conftest.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| import sys | ||||
| import os | ||||
|  | ||||
| sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) | ||||
|  | ||||
							
								
								
									
										0
									
								
								wlauto/external/louie/test/fixture.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								wlauto/external/louie/test/fixture.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										154
									
								
								wlauto/external/louie/test/test_dispatcher.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										154
									
								
								wlauto/external/louie/test/test_dispatcher.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,154 @@ | ||||
| import unittest | ||||
|  | ||||
| import louie | ||||
| from louie import dispatcher | ||||
|  | ||||
|  | ||||
| def x(a): | ||||
|     return a | ||||
|  | ||||
|  | ||||
| class Dummy(object): | ||||
|     pass | ||||
|  | ||||
|  | ||||
| class Callable(object): | ||||
|  | ||||
|     def __call__(self, a): | ||||
|         return a | ||||
|  | ||||
|     def a(self, a): | ||||
|         return a | ||||
|  | ||||
|  | ||||
| class TestDispatcher(unittest.TestCase): | ||||
|  | ||||
|     def setUp(self): | ||||
|         louie.reset() | ||||
|  | ||||
|     def _isclean(self): | ||||
|         """Assert that everything has been cleaned up automatically""" | ||||
|         assert len(dispatcher.senders_back) == 0, dispatcher.senders_back | ||||
|         assert len(dispatcher.connections) == 0, dispatcher.connections | ||||
|         assert len(dispatcher.senders) == 0, dispatcher.senders | ||||
|      | ||||
|     def test_Exact(self): | ||||
|         a = Dummy() | ||||
|         signal = 'this' | ||||
|         louie.connect(x, signal, a) | ||||
|         expected = [(x, a)] | ||||
|         result = louie.send('this', a, a=a) | ||||
|         assert result == expected, ( | ||||
|             "Send didn't return expected result:\n\texpected:%s\n\tgot:%s" | ||||
|             % (expected, result)) | ||||
|         louie.disconnect(x, signal, a) | ||||
|         assert len(list(louie.get_all_receivers(a, signal))) == 0 | ||||
|         self._isclean() | ||||
|          | ||||
|     def test_AnonymousSend(self): | ||||
|         a = Dummy() | ||||
|         signal = 'this' | ||||
|         louie.connect(x, signal) | ||||
|         expected = [(x, a)] | ||||
|         result = louie.send(signal, None, a=a) | ||||
|         assert result == expected, ( | ||||
|             "Send didn't return expected result:\n\texpected:%s\n\tgot:%s" | ||||
|             % (expected, result)) | ||||
|         louie.disconnect(x, signal) | ||||
|         assert len(list(louie.get_all_receivers(None, signal))) == 0 | ||||
|         self._isclean() | ||||
|          | ||||
|     def test_AnyRegistration(self): | ||||
|         a = Dummy() | ||||
|         signal = 'this' | ||||
|         louie.connect(x, signal, louie.Any) | ||||
|         expected = [(x, a)] | ||||
|         result = louie.send('this', object(), a=a) | ||||
|         assert result == expected, ( | ||||
|             "Send didn't return expected result:\n\texpected:%s\n\tgot:%s" | ||||
|             % (expected, result)) | ||||
|         louie.disconnect(x, signal, louie.Any) | ||||
|         expected = [] | ||||
|         result = louie.send('this', object(), a=a) | ||||
|         assert result == expected, ( | ||||
|             "Send didn't return expected result:\n\texpected:%s\n\tgot:%s" | ||||
|             % (expected, result)) | ||||
|         assert len(list(louie.get_all_receivers(louie.Any, signal))) == 0 | ||||
|         self._isclean() | ||||
|          | ||||
|     def test_AllRegistration(self): | ||||
|         a = Dummy() | ||||
|         signal = 'this' | ||||
|         louie.connect(x, louie.All, a) | ||||
|         expected = [(x, a)] | ||||
|         result = louie.send('this', a, a=a) | ||||
|         assert result == expected, ( | ||||
|             "Send didn't return expected result:\n\texpected:%s\n\tgot:%s" | ||||
|             % (expected, result)) | ||||
|         louie.disconnect(x, louie.All, a) | ||||
|         assert len(list(louie.get_all_receivers(a, louie.All))) == 0 | ||||
|         self._isclean() | ||||
|          | ||||
|     def test_GarbageCollected(self): | ||||
|         a = Callable() | ||||
|         b = Dummy() | ||||
|         signal = 'this' | ||||
|         louie.connect(a.a, signal, b) | ||||
|         expected = [] | ||||
|         del a | ||||
|         result = louie.send('this', b, a=b) | ||||
|         assert result == expected, ( | ||||
|             "Send didn't return expected result:\n\texpected:%s\n\tgot:%s" | ||||
|             % (expected, result)) | ||||
|         assert len(list(louie.get_all_receivers(b, signal))) == 0, ( | ||||
|             "Remaining handlers: %s" % (louie.get_all_receivers(b, signal),)) | ||||
|         self._isclean() | ||||
|          | ||||
|     def test_GarbageCollectedObj(self): | ||||
|         class x: | ||||
|             def __call__(self, a): | ||||
|                 return a | ||||
|         a = Callable() | ||||
|         b = Dummy() | ||||
|         signal = 'this' | ||||
|         louie.connect(a, signal, b) | ||||
|         expected = [] | ||||
|         del a | ||||
|         result = louie.send('this', b, a=b) | ||||
|         assert result == expected, ( | ||||
|             "Send didn't return expected result:\n\texpected:%s\n\tgot:%s" | ||||
|             % (expected, result)) | ||||
|         assert len(list(louie.get_all_receivers(b, signal))) == 0, ( | ||||
|             "Remaining handlers: %s" % (louie.get_all_receivers(b, signal),)) | ||||
|         self._isclean() | ||||
|  | ||||
|     def test_MultipleRegistration(self): | ||||
|         a = Callable() | ||||
|         b = Dummy() | ||||
|         signal = 'this' | ||||
|         louie.connect(a, signal, b) | ||||
|         louie.connect(a, signal, b) | ||||
|         louie.connect(a, signal, b) | ||||
|         louie.connect(a, signal, b) | ||||
|         louie.connect(a, signal, b) | ||||
|         louie.connect(a, signal, b) | ||||
|         result = louie.send('this', b, a=b) | ||||
|         assert len(result) == 1, result | ||||
|         assert len(list(louie.get_all_receivers(b, signal))) == 1, ( | ||||
|             "Remaining handlers: %s" % (louie.get_all_receivers(b, signal),)) | ||||
|         del a | ||||
|         del b | ||||
|         del result | ||||
|         self._isclean() | ||||
|  | ||||
|     def test_robust(self): | ||||
|         """Test the sendRobust function.""" | ||||
|         def fails(): | ||||
|             raise ValueError('this') | ||||
|         a = object() | ||||
|         signal = 'this' | ||||
|         louie.connect(fails, louie.All, a) | ||||
|         result = louie.send_robust('this', a, a=a) | ||||
|         err = result[0][1] | ||||
|         assert isinstance(err, ValueError) | ||||
|         assert err.args == ('this', ) | ||||
							
								
								
									
										145
									
								
								wlauto/external/louie/test/test_plugin.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										145
									
								
								wlauto/external/louie/test/test_plugin.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,145 @@ | ||||
| """Louie plugin tests.""" | ||||
|  | ||||
| import unittest | ||||
|  | ||||
| import louie | ||||
|  | ||||
| try: | ||||
|     import qt | ||||
|     if not hasattr(qt.qApp, 'for_testing'): | ||||
|         _app = qt.QApplication([]) | ||||
|         _app.for_testing = True | ||||
|         qt.qApp = _app | ||||
| except ImportError: | ||||
|     qt = None | ||||
|  | ||||
|  | ||||
| class ReceiverBase(object): | ||||
|  | ||||
|     def __init__(self): | ||||
|         self.args = [] | ||||
|         self.live = True | ||||
|  | ||||
|     def __call__(self, arg): | ||||
|         self.args.append(arg) | ||||
|  | ||||
| class Receiver1(ReceiverBase): | ||||
|     pass | ||||
|  | ||||
| class Receiver2(ReceiverBase): | ||||
|     pass | ||||
|  | ||||
|  | ||||
| class Plugin1(louie.Plugin): | ||||
|  | ||||
|     def is_live(self, receiver): | ||||
|         """ReceiverBase instances are only live if their `live` | ||||
|         attribute is True""" | ||||
|         if isinstance(receiver, ReceiverBase): | ||||
|             return receiver.live | ||||
|         return True | ||||
|  | ||||
|  | ||||
| class Plugin2(louie.Plugin): | ||||
|  | ||||
|     def is_live(self, receiver): | ||||
|         """Pretend all Receiver2 instances are not live.""" | ||||
|         if isinstance(receiver, Receiver2): | ||||
|             return False | ||||
|         return True | ||||
|  | ||||
|  | ||||
| def test_only_one_instance(): | ||||
|     louie.reset() | ||||
|     plugin1a = Plugin1() | ||||
|     plugin1b = Plugin1() | ||||
|     louie.install_plugin(plugin1a) | ||||
|     # XXX: Move these tests into test cases so we can use unittest's | ||||
|     # 'assertRaises' method. | ||||
|     try: | ||||
|         louie.install_plugin(plugin1b) | ||||
|     except louie.error.PluginTypeError: | ||||
|         pass | ||||
|     else: | ||||
|         raise Exception('PluginTypeError not raised') | ||||
|  | ||||
|  | ||||
| def test_is_live(): | ||||
|     louie.reset() | ||||
|     # Create receivers. | ||||
|     receiver1a = Receiver1() | ||||
|     receiver1b = Receiver1() | ||||
|     receiver2a = Receiver2() | ||||
|     receiver2b = Receiver2() | ||||
|     # Connect signals. | ||||
|     louie.connect(receiver1a, 'sig') | ||||
|     louie.connect(receiver1b, 'sig') | ||||
|     louie.connect(receiver2a, 'sig') | ||||
|     louie.connect(receiver2b, 'sig') | ||||
|     # Check reception without plugins. | ||||
|     louie.send('sig', arg='foo') | ||||
|     assert receiver1a.args == ['foo'] | ||||
|     assert receiver1b.args == ['foo'] | ||||
|     assert receiver2a.args == ['foo'] | ||||
|     assert receiver2b.args == ['foo'] | ||||
|     # Install plugin 1. | ||||
|     plugin1 = Plugin1() | ||||
|     louie.install_plugin(plugin1) | ||||
|     # Make some receivers not live. | ||||
|     receiver1a.live = False | ||||
|     receiver2b.live = False | ||||
|     # Check reception. | ||||
|     louie.send('sig', arg='bar') | ||||
|     assert receiver1a.args == ['foo'] | ||||
|     assert receiver1b.args == ['foo', 'bar'] | ||||
|     assert receiver2a.args == ['foo', 'bar'] | ||||
|     assert receiver2b.args == ['foo'] | ||||
|     # Remove plugin 1, install plugin 2. | ||||
|     plugin2 = Plugin2() | ||||
|     louie.remove_plugin(plugin1) | ||||
|     louie.install_plugin(plugin2) | ||||
|     # Check reception. | ||||
|     louie.send('sig', arg='baz') | ||||
|     assert receiver1a.args == ['foo', 'baz'] | ||||
|     assert receiver1b.args == ['foo', 'bar', 'baz'] | ||||
|     assert receiver2a.args == ['foo', 'bar'] | ||||
|     assert receiver2b.args == ['foo'] | ||||
|     # Install plugin 1 alongside plugin 2. | ||||
|     louie.install_plugin(plugin1) | ||||
|     # Check reception. | ||||
|     louie.send('sig', arg='fob') | ||||
|     assert receiver1a.args == ['foo', 'baz'] | ||||
|     assert receiver1b.args == ['foo', 'bar', 'baz', 'fob'] | ||||
|     assert receiver2a.args == ['foo', 'bar'] | ||||
|     assert receiver2b.args == ['foo'] | ||||
|      | ||||
|  | ||||
| if qt is not None: | ||||
|     def test_qt_plugin(): | ||||
|         louie.reset() | ||||
|         # Create receivers. | ||||
|         class Receiver(qt.QWidget): | ||||
|             def __init__(self): | ||||
|                 qt.QObject.__init__(self) | ||||
|                 self.args = [] | ||||
|             def receive(self, arg): | ||||
|                 self.args.append(arg) | ||||
|         receiver1 = Receiver() | ||||
|         receiver2 = Receiver() | ||||
|         # Connect signals. | ||||
|         louie.connect(receiver1.receive, 'sig') | ||||
|         louie.connect(receiver2.receive, 'sig') | ||||
|         # Destroy receiver2 so only a shell is left. | ||||
|         receiver2.close(True) | ||||
|         # Check reception without plugins. | ||||
|         louie.send('sig', arg='foo') | ||||
|         assert receiver1.args == ['foo'] | ||||
|         assert receiver2.args == ['foo'] | ||||
|         # Install plugin. | ||||
|         plugin = louie.QtWidgetPlugin() | ||||
|         louie.install_plugin(plugin) | ||||
|         # Check reception with plugins. | ||||
|         louie.send('sig', arg='bar') | ||||
|         assert receiver1.args == ['foo', 'bar'] | ||||
|         assert receiver2.args == ['foo'] | ||||
|  | ||||
							
								
								
									
										41
									
								
								wlauto/external/louie/test/test_prioritydispatcher.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								wlauto/external/louie/test/test_prioritydispatcher.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| import unittest | ||||
|  | ||||
| import louie | ||||
| from louie import dispatcher | ||||
|  | ||||
| class Callable(object): | ||||
|  | ||||
|     def __init__(self, val): | ||||
|         self.val = val | ||||
|  | ||||
|     def __call__(self): | ||||
|         return self.val | ||||
|  | ||||
|  | ||||
| one = Callable(1) | ||||
| two = Callable(2) | ||||
| three = Callable(3) | ||||
|  | ||||
| class TestPriorityDispatcher(unittest.TestCase): | ||||
|  | ||||
|     def test_ConnectNotify(self): | ||||
|         louie.connect( | ||||
|             two, | ||||
|             'one', | ||||
|             priority=200 | ||||
|             ) | ||||
|         louie.connect( | ||||
|             one, | ||||
|             'one', | ||||
|             priority=100 | ||||
|             ) | ||||
|         louie.connect( | ||||
|             three, | ||||
|             'one', | ||||
|             priority=300 | ||||
|             ) | ||||
|         result = [ i[1] for i in louie.send('one')] | ||||
|         if not result == [1, 2, 3]: | ||||
|             print result | ||||
|             assert(False) | ||||
|  | ||||
							
								
								
									
										62
									
								
								wlauto/external/louie/test/test_prioritylist.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								wlauto/external/louie/test/test_prioritylist.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,62 @@ | ||||
| import unittest | ||||
|  | ||||
| import louie.prioritylist | ||||
| from louie.prioritylist import PriorityList | ||||
|  | ||||
| #def populate_list(plist): | ||||
|  | ||||
| class TestPriorityList(unittest.TestCase): | ||||
|  | ||||
|     def test_Insert(self): | ||||
|         pl = PriorityList() | ||||
|         elements = {3: "element 3", | ||||
|                     2: "element 2", | ||||
|                     1: "element 1", | ||||
|                     5: "element 5", | ||||
|                     4: "element 4" | ||||
|                     } | ||||
|         for key in elements: | ||||
|             pl.add(elements[key], priority=key) | ||||
|  | ||||
|         match = zip(sorted(elements.values()), pl[:]) | ||||
|         for pair in match: | ||||
|             assert(pair[0]==pair[1]) | ||||
|  | ||||
|     def test_Delete(self): | ||||
|         pl = PriorityList() | ||||
|         elements = {2: "element 3", | ||||
|                     1: "element 2", | ||||
|                     0: "element 1", | ||||
|                     4: "element 5", | ||||
|                     3: "element 4" | ||||
|                     } | ||||
|         for key in elements: | ||||
|             pl.add(elements[key], priority=key) | ||||
|         del elements[2] | ||||
|         del pl[2] | ||||
|         match = zip(sorted(elements.values()) , pl[:]) | ||||
|         for pair in match: | ||||
|             assert(pair[0]==pair[1]) | ||||
|  | ||||
|     def test_Multiple(self): | ||||
|         pl = PriorityList() | ||||
|         pl.add('1', 1) | ||||
|         pl.add('2.1', 2) | ||||
|         pl.add('3', 3) | ||||
|         pl.add('2.2', 2) | ||||
|         it = iter(pl) | ||||
|         assert(it.next() == '1') | ||||
|         assert(it.next() == '2.1') | ||||
|         assert(it.next() == '2.2') | ||||
|         assert(it.next() == '3') | ||||
|  | ||||
|     def test_IteratorBreak(self): | ||||
|         pl = PriorityList() | ||||
|         pl.add('1', 1) | ||||
|         pl.add('2.1', 2) | ||||
|         pl.add('3', 3) | ||||
|         pl.add('2.2', 2) | ||||
|         for i in pl: | ||||
|             if i == '2.1': | ||||
|                 break | ||||
|         assert(pl.index('3') == 3) | ||||
							
								
								
									
										34
									
								
								wlauto/external/louie/test/test_robustapply.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								wlauto/external/louie/test/test_robustapply.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| import unittest | ||||
|  | ||||
| from louie.robustapply import robust_apply | ||||
|  | ||||
|  | ||||
| def no_argument(): | ||||
|     pass | ||||
|  | ||||
|  | ||||
| def one_argument(blah): | ||||
|     pass | ||||
|  | ||||
|  | ||||
| def two_arguments(blah, other): | ||||
|     pass | ||||
|  | ||||
|  | ||||
| class TestRobustApply(unittest.TestCase): | ||||
|      | ||||
|     def test_01(self): | ||||
|         robust_apply(no_argument, no_argument) | ||||
|          | ||||
|     def test_02(self): | ||||
|         self.assertRaises(TypeError, robust_apply, no_argument, no_argument, | ||||
|                           'this' ) | ||||
|          | ||||
|     def test_03(self): | ||||
|         self.assertRaises(TypeError, robust_apply, one_argument, one_argument) | ||||
|          | ||||
|     def test_04(self): | ||||
|         """Raise error on duplication of a particular argument""" | ||||
|         self.assertRaises(TypeError, robust_apply, one_argument, one_argument, | ||||
|                           'this', blah='that') | ||||
|  | ||||
							
								
								
									
										83
									
								
								wlauto/external/louie/test/test_saferef.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								wlauto/external/louie/test/test_saferef.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,83 @@ | ||||
| import unittest | ||||
|  | ||||
| from louie.saferef import safe_ref | ||||
|  | ||||
|  | ||||
| class _Sample1(object): | ||||
|     def x(self): | ||||
|         pass | ||||
|  | ||||
|      | ||||
| def _sample2(obj): | ||||
|     pass | ||||
|  | ||||
|  | ||||
| class _Sample3(object): | ||||
|     def __call__(self, obj): | ||||
|         pass | ||||
|  | ||||
|      | ||||
| class TestSaferef(unittest.TestCase): | ||||
|  | ||||
|     # XXX: The original tests had a test for closure, and it had an | ||||
|     # off-by-one problem, perhaps due to scope issues.  It has been | ||||
|     # removed from this test suite. | ||||
|      | ||||
|     def setUp(self): | ||||
|         ts = [] | ||||
|         ss = [] | ||||
|         for x in xrange(5000): | ||||
|             t = _Sample1() | ||||
|             ts.append(t) | ||||
|             s = safe_ref(t.x, self._closure) | ||||
|             ss.append(s) | ||||
|         ts.append(_sample2) | ||||
|         ss.append(safe_ref(_sample2, self._closure)) | ||||
|         for x in xrange(30): | ||||
|             t = _Sample3() | ||||
|             ts.append(t) | ||||
|             s = safe_ref(t, self._closure) | ||||
|             ss.append(s) | ||||
|         self.ts = ts | ||||
|         self.ss = ss | ||||
|         self.closure_count = 0 | ||||
|          | ||||
|     def tearDown(self): | ||||
|         if hasattr(self, 'ts'): | ||||
|             del self.ts | ||||
|         if hasattr(self, 'ss'): | ||||
|             del self.ss | ||||
|          | ||||
|     def test_In(self): | ||||
|         """Test the `in` operator for safe references (cmp)""" | ||||
|         for t in self.ts[:50]: | ||||
|             assert safe_ref(t.x) in self.ss | ||||
|              | ||||
|     def test_Valid(self): | ||||
|         """Test that the references are valid (return instance methods)""" | ||||
|         for s in self.ss: | ||||
|             assert s() | ||||
|              | ||||
|     def test_ShortCircuit(self): | ||||
|         """Test that creation short-circuits to reuse existing references""" | ||||
|         sd = {} | ||||
|         for s in self.ss: | ||||
|             sd[s] = 1 | ||||
|         for t in self.ts: | ||||
|             if hasattr(t, 'x'): | ||||
|                 assert sd.has_key(safe_ref(t.x)) | ||||
|             else: | ||||
|                 assert sd.has_key(safe_ref(t)) | ||||
|                  | ||||
|     def test_Representation(self): | ||||
|         """Test that the reference object's representation works | ||||
|  | ||||
|         XXX Doesn't currently check the results, just that no error | ||||
|             is raised | ||||
|         """ | ||||
|         repr(self.ss[-1]) | ||||
|          | ||||
|     def _closure(self, ref): | ||||
|         """Dumb utility mechanism to increment deletion counter""" | ||||
|         self.closure_count += 1 | ||||
|  | ||||
		Reference in New Issue
	
	Block a user