コード例 #1
0
 def test_initialization():
     lock = threading.Lock()
     baseplate = Lego(None, lock)
     lego = Lego(baseplate, baseplate.lock)
     lego = Lego(baseplate, baseplate.lock, 'lego.log')
     assert (baseplate.lock == lock)  # nosec
     assert (lego.lock == lock)  # nosec
     assert (baseplate.baseplate is None)  # nosec
     assert (lego.baseplate is baseplate)  # nosec
     assert (lego.children == [])  # nosec
     assert (lego.log_file == 'lego.log')  # nosec
コード例 #2
0
 def test_cleanup():
     baseplate = Lego(None, threading.Lock())
     baseplate.add_child(Lego)
     child = baseplate.children[0]
     child.stop()
     baseplate.cleanup()
     assert (len(baseplate.children) == 0)  # nosec
コード例 #3
0
 def _make_testing_connector(temp_file=None):
     lock = threading.Lock()
     baseplate = Lego(None, lock)
     if temp_file is None:
         testing_connector = TestingConnector(baseplate, lock)
     else:
         testing_connector = TestingConnector(baseplate, lock, temp_file)
     return testing_connector  # nosec
コード例 #4
0
 def test_receive_logs():
     log_file_name = 'test_logging.log'
     lego = Lego(None, threading.Lock(), log_file_name)
     message = Message('Test Message 1',
                       Metadata(None).__dict__, True).__dict__
     lego.on_receive(message)
     with open(log_file_name, mode='r') as f:
         log = json.loads(f.read())
     assert log == message  # nosec
     os.remove(log_file_name)
コード例 #5
0
 def test_initialization():
     source = Lego(None, threading.Lock())
     metadata = Metadata(source)
     message = Message('a message', metadata)
     assert (message.text == 'a message')  # nosec
     assert (message.metadata == metadata)  # nosec
     message = Message('a message', metadata, True)
     assert (message.text == 'a message')  # nosec
     assert (message.metadata == metadata)  # nosec
     assert (message.should_log)  # nosec
コード例 #6
0
 def test_add_child():
     baseplate = Lego(None, threading.Lock())
     baseplate.add_child(Lego)
     child = baseplate.children[0]
     assert (isinstance(child, pykka.ActorRef))  # nosec
     child_proxy = child.proxy()
     child_proxy.add_child(Lego)
     child_children = child_proxy.children.get()
     assert (isinstance(child_children[0], pykka.ActorRef))  # nosec
     child_children[0].stop()
     child.stop()
コード例 #7
0
 def test_on_receive_informs_children():
     log_file_name = 'test_child_informed.log'
     baseplate = Lego(None, threading.Lock())
     child = Lego.start(baseplate, threading.Lock(), log_file_name)
     baseplate.children.append(child)
     message = Message('Test Message 1',
                       Metadata(None).__dict__, True).__dict__
     baseplate.on_receive(message)
     child.stop()
     with open(log_file_name, mode='r') as f:
         log = json.loads(f.read())
     os.remove(log_file_name)
     assert log == message  # nosec
コード例 #8
0
 def _make_message():
     source = Lego(None, threading.Lock())
     metadata = Metadata(source)
     message = Message('blah', metadata)
     return message
コード例 #9
0
 def test_get_help():
     lego = Lego(None, threading.Lock())
     assert lego.get_help() == ''  # nosec
コード例 #10
0
 def test_handle(self):
     lego = Lego(None, threading.Lock())
     assert (lego.handle(self.make_message()) is None)  # nosec
コード例 #11
0
 def test_listening_for(self):
     lego = Lego(None, threading.Lock())
     message = self.make_message()
     assert not lego.listening_for(message)  # nosec
コード例 #12
0
 def test_lock_required(self):
     with self.assertRaises(LegoError):
         lego = Lego(None, None)  # noqa: F841
コード例 #13
0
 def test_default_init_values():
     lock = threading.Lock()
     baseplate = Lego(None, lock)
     lego = Lego(baseplate, baseplate.lock)
     assert lego.log_file is None  # nosec
コード例 #14
0
 def test_initialization():
     lego = Lego(None, threading.Lock())
     message = Message('Test Message', Metadata(lego))
     thread = Lego.HandlerThread(lego.handle, message)
     assert thread.handler == lego.handle  # nosec
     assert thread.message == message  # nosec
コード例 #15
0
 def test_default_init_values():
     source = Lego(None, threading.Lock())
     metadata = Metadata(source)
     assert (metadata.dest is None)  # nosec
コード例 #16
0
 def test_initialization():
     source = Lego(None, threading.Lock())
     dest = Lego(None, threading.Lock())
     metadata = Metadata(source, dest)
     assert (metadata.source == source)  # nosec
     assert (metadata.dest == dest)  # nosec
コード例 #17
0
 def test_get_name():
     lego = Lego(None, threading.Lock())
     assert lego.get_name() == '?'  # nosec
コード例 #18
0
 def test_default_init_values():
     source = Lego(None, threading.Lock())
     metadata = Metadata(source)
     message = Message('a message', metadata)
     assert (not message.should_log)  # nosec
コード例 #19
0
 def test_on_failure():
     lego = Lego(None, threading.Lock())
     lego.on_failure("Exception Type", "Exception Value", "Traceback")
     assert True  # nosec