def test_worker_id(self, saving_mediator: SavingMediator): assert saving_mediator.worker_id is None, "The default value of SavingMediator.worker_id should be 'None'." _test_val = "Thread-1" saving_mediator.worker_id = _test_val assert saving_mediator.worker_id == "Thread-1", f"The value of SavingMediator.worker_id should be '{_test_val}'." del saving_mediator.worker_id assert saving_mediator.worker_id is None, "The value of SavingMediator.worker_id should be deleted."
def test_worker_id(self, saving_mediator: SavingMediator): assert saving_mediator.worker_id is None, "The default value of SavingMediator.worker_id should be 'None'." _test_worker_id = adapter_context.get_current_worker_ident() # _test_val = "Thread-1" saving_mediator.worker_id = _test_worker_id assert saving_mediator.worker_id == _test_worker_id, f"The value of SavingMediator.worker_id should be '{_test_worker_id}'." del saving_mediator.worker_id assert saving_mediator.worker_id is None, "The value of SavingMediator.worker_id should be deleted."
def test_instantiate_without_running_mode(self): try: set_mode(mode=None) SavingMediator() except ValueError as ve: assert "The RunningMode in context cannot be None object if option *context* is None" in str( ve ), "It should raise an exception about RunningMode cannot be None if its option *context* is None." else: assert False, "It should raise an exception about RunningMode cannot be None if its option *context* is None."
def saving_mediator() -> SavingMediator: return SavingMediator()
def test_enable_compress(self, saving_mediator: SavingMediator): assert saving_mediator.enable_compress is False, "The default value of SavingMediator.enable_compress should be 'False'." saving_mediator.enable_compress = True assert saving_mediator.enable_compress is True, "The value of SavingMediator.enable_compress should be 'True'."
def test_child_worker_running(self, saving_mediator: SavingMediator): assert saving_mediator.child_worker_running is False, "The default value of SavingMediator.child_worker_running should be 'False'." saving_mediator.child_worker_running = True assert saving_mediator.child_worker_running is True, "The value of SavingMediator.child_worker_running should be 'True'."
def test_is_super_worker(self, saving_mediator: SavingMediator): assert saving_mediator.is_super_worker( ) is True, "It should be true because it's main thread right now (only one thread currently)."
def test_instantiate_with_customized_mediator(self): _tm = _TestingMediator() _sm = SavingMediator(context=_tm) assert _sm.is_super_worker() == _tm.current_worker_is_parent( ), "The checksum between context and mediator should be the same."
def saving_mediator(request) -> SavingMediator: set_mode(mode=request.param) return SavingMediator()