示例#1
0
    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."
示例#2
0
    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."
示例#3
0
 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."
示例#4
0
def saving_mediator() -> SavingMediator:
    return SavingMediator()
示例#5
0
    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'."
示例#6
0
    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'."
示例#7
0
 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)."
示例#8
0
 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."
示例#9
0
def saving_mediator(request) -> SavingMediator:
    set_mode(mode=request.param)
    return SavingMediator()