示例#1
0
    def test_globalize_instance(self, mr_rlock: RLockFactory):
        from multirunnable.api.manage import Running_RLock
        assert Running_RLock is None, "It should be None before we do anything."

        mr_rlock.feature_mode = FeatureMode.Concurrent
        _rlock = mr_rlock.get_instance()
        mr_rlock.globalize_instance(_rlock)

        from multirunnable.api.manage import Running_RLock
        assert Running_RLock is _rlock, "It should be the instance we instantiated."
示例#2
0
    def test_get_instance_with_concurrent_mode(self, mr_rlock: RLockFactory):
        try:
            _rlock = mr_rlock.get_instance()
        except ValueError as ve:
            assert "FeatureMode is None. Please configure it as one of 'multirunnable.mode.FeatureMode'." in str(
                ve), "It should set the FeatureMode first."

        mr_rlock.feature_mode = FeatureMode.Concurrent
        _rlock = mr_rlock.get_instance()
        from threading import RLock
        assert _rlock is not None and isinstance(_rlock, type(RLock(
        ))) is True, "This type of RLock instance should be 'threading.RLock'."
示例#3
0
    def test_get_instance_with_coroutine_mode(self, mr_rlock: RLockFactory):
        try:
            _rlock = mr_rlock.get_instance()
        except ValueError as ve:
            assert "FeatureMode is None. Please configure it as one of 'multirunnable.mode.FeatureMode'." in str(
                ve), "It should set the FeatureMode first."

        mr_rlock.feature_mode = FeatureMode.GreenThread
        _rlock = mr_rlock.get_instance()
        from gevent.lock import RLock
        assert _rlock is not None and isinstance(
            _rlock, RLock
        ) is True, "This type of RLock instance should be 'gevent.lock.RLock'."
示例#4
0
    def test_get_instance_with_parallel_mode(self, mr_rlock: RLockFactory):
        try:
            _rlock = mr_rlock.get_instance()
        except ValueError as ve:
            assert "FeatureMode is None. Please configure it as one of 'multirunnable.mode.FeatureMode'." in str(
                ve), "It should set the FeatureMode first."

        mr_rlock.feature_mode = FeatureMode.Parallel
        _rlock = mr_rlock.get_instance()
        from multiprocessing.synchronize import RLock
        assert _rlock is not None and isinstance(
            _rlock, RLock
        ) is True, "This type of RLock instance should be 'multiprocessing.synchronize.RLock'."
示例#5
0
    def test_get_instance_with_asynchronous_mode(self, mr_rlock: RLockFactory):
        from asyncio.locks import Lock
        from asyncio import new_event_loop

        try:
            _rlock = mr_rlock.get_instance()
        except ValueError as ve:
            assert "FeatureMode is None. Please configure it as one of 'multirunnable.mode.FeatureMode'." in str(
                ve), "It should set the FeatureMode first."

        mr_rlock.feature_mode = FeatureMode.Asynchronous
        _rlock = mr_rlock.get_instance(event_loop=new_event_loop())
        assert _rlock is not None and isinstance(
            _rlock, Lock
        ) is True, "This type of RLock instance should be 'asyncio.locks.Lock'."
示例#6
0
 def test__repr__(self, mr_rlock: RLockFactory):
     _testing_mode = FeatureMode.Parallel
     mr_rlock.feature_mode = _testing_mode
     _rlock_repr = repr(mr_rlock)
     _chksum = re.search(
         r"<RLock\(\) object with FeatureMode\.[a-zA-Z]{4,32} mode at \w{10,30}>",
         _rlock_repr)
     assert _chksum is not None, f"The '__repr__' format is incorrect. Please check its value. \n" \
                                 f"Its format should be like *<RLock() object with <Feature Mode> mode at <ID of instance>>*. \n" \
                                 f"But it got *{_rlock_repr}*."
示例#7
0
    def test_feature_mode(self, mr_rlock: RLockFactory):
        _testing_mode = FeatureMode.Concurrent

        assert mr_rlock.feature_mode is None, "The default value of FeatureMode of RLock instance should be None."
        try:
            mr_rlock.feature_mode = _testing_mode
        except Exception as e:
            assert False, "It should set the FeatureMode into RLock instance without any issue."
        else:
            _feature_mode = mr_rlock.feature_mode
            assert _feature_mode is _testing_mode, f"The mode we got from RLock instance should be the same as we set '{_testing_mode}'."
示例#8
0
def instantiate_rlock(_mode, **kwargs):
    _rlock = RLockFactory()
    return _initial(_rlock, _mode, **kwargs)
示例#9
0
def mr_rlock() -> RLockFactory:
    return RLockFactory()
def instantiate_rlock(_mode: Union[RunningMode, FeatureMode], **kwargs):
    _rlock = RLockFactory()
    return _initial(_rlock, _mode, **kwargs)