Esempio n. 1
0
    def test_get_instance_with_coroutine_mode(
            self, mr_bounded_semaphore: BoundedSemaphoreFactory):
        try:
            _bounded_semaphore = mr_bounded_semaphore.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_bounded_semaphore.feature_mode = FeatureMode.GreenThread
        _bounded_semaphore = mr_bounded_semaphore.get_instance()
        from gevent.lock import BoundedSemaphore
        assert _bounded_semaphore is not None and isinstance(
            _bounded_semaphore, BoundedSemaphore
        ) is True, "This type of Semaphore instance should be 'gevent.lock.BoundedSemaphore'."
Esempio n. 2
0
    def test_get_instance_with_parallel_mode(
            self, mr_bounded_semaphore: BoundedSemaphoreFactory):
        try:
            _bounded_semaphore = mr_bounded_semaphore.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_bounded_semaphore.feature_mode = FeatureMode.Parallel
        _bounded_semaphore = mr_bounded_semaphore.get_instance()
        from multiprocessing.synchronize import BoundedSemaphore
        assert _bounded_semaphore is not None and isinstance(
            _bounded_semaphore, BoundedSemaphore
        ) is True, "This type of BoundedSemaphore instance should be 'multiprocessing.synchronize.BoundedSemaphore'."
Esempio n. 3
0
    def test_get_instance_with_asynchronous_mode(
            self, mr_bounded_semaphore: BoundedSemaphoreFactory):
        from asyncio.locks import BoundedSemaphore
        from asyncio import new_event_loop

        try:
            _bounded_semaphore = mr_bounded_semaphore.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_bounded_semaphore.feature_mode = FeatureMode.Asynchronous
        _bounded_semaphore = mr_bounded_semaphore.get_instance(
            event_loop=new_event_loop())
        assert _bounded_semaphore is not None and isinstance(
            _bounded_semaphore, BoundedSemaphore
        ) is True, "This type of BoundedSemaphore instance should be 'asyncio.locks.BoundedSemaphore'."
Esempio n. 4
0
    def test_globalize_instance(self,
                                mr_bounded_semaphore: BoundedSemaphoreFactory):
        from multirunnable.api.manage import Running_Bounded_Semaphore
        assert Running_Bounded_Semaphore is None, "It should be None before we do anything."

        mr_bounded_semaphore.feature_mode = FeatureMode.Parallel
        _bounded_semaphore = mr_bounded_semaphore.get_instance()
        mr_bounded_semaphore.globalize_instance(_bounded_semaphore)

        from multirunnable.api.manage import Running_Bounded_Semaphore
        assert Running_Bounded_Semaphore is _bounded_semaphore, "It should be the instance we instantiated."