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
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
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
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)
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
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()
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
def _make_message(): source = Lego(None, threading.Lock()) metadata = Metadata(source) message = Message('blah', metadata) return message
def test_get_help(): lego = Lego(None, threading.Lock()) assert lego.get_help() == '' # nosec
def test_handle(self): lego = Lego(None, threading.Lock()) assert (lego.handle(self.make_message()) is None) # nosec
def test_listening_for(self): lego = Lego(None, threading.Lock()) message = self.make_message() assert not lego.listening_for(message) # nosec
def test_lock_required(self): with self.assertRaises(LegoError): lego = Lego(None, None) # noqa: F841
def test_default_init_values(): lock = threading.Lock() baseplate = Lego(None, lock) lego = Lego(baseplate, baseplate.lock) assert lego.log_file is None # nosec
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
def test_default_init_values(): source = Lego(None, threading.Lock()) metadata = Metadata(source) assert (metadata.dest is None) # nosec
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
def test_get_name(): lego = Lego(None, threading.Lock()) assert lego.get_name() == '?' # nosec
def test_default_init_values(): source = Lego(None, threading.Lock()) metadata = Metadata(source) message = Message('a message', metadata) assert (not message.should_log) # nosec
def test_on_failure(): lego = Lego(None, threading.Lock()) lego.on_failure("Exception Type", "Exception Value", "Traceback") assert True # nosec