Esempio n. 1
0
    def test_globalize_instance(self, mr_event: EventFactory):
        from multirunnable.api.manage import Running_Event
        assert Running_Event is None, "It should be None before we do anything."

        mr_event.feature_mode = FeatureMode.Parallel
        _event = mr_event.get_instance()
        mr_event.globalize_instance(_event)

        from multirunnable.api.manage import Running_Event
        assert Running_Event is _event, "It should be the instance we instantiated."
Esempio n. 2
0
    def test_get_instance_with_concurrent_mode(self, mr_event: EventFactory):
        try:
            _event = mr_event.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_event.feature_mode = FeatureMode.Concurrent
        _event = mr_event.get_instance()
        from threading import Event
        assert _event is not None and isinstance(
            _event, Event
        ) is True, "This type of Event instance should be 'threading.Event'."
Esempio n. 3
0
    def test_get_instance_with_parallel_mode(self, mr_event: EventFactory):
        try:
            _event = mr_event.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_event.feature_mode = FeatureMode.Parallel
        _event = mr_event.get_instance()
        from multiprocessing.synchronize import Event
        assert _event is not None and isinstance(
            _event, Event
        ) is True, "This type of Lock instance should be 'multiprocessing.synchronize.Event'."
Esempio n. 4
0
    def test_get_instance_with_coroutine_mode(self, mr_event: EventFactory):
        try:
            _event = mr_event.get_instance()
        except ValueError as ve:
            assert "FeatureMode is None. Please configure it as one of 'multirunnable.mode.FeatureMode'." in str(
                ve), f"It should set the FeatureMode first."

        mr_event.feature_mode = FeatureMode.GreenThread
        _event = mr_event.get_instance()
        from gevent.event import Event
        assert _event is not None and isinstance(
            _event, Event
        ) is True, f"This type of Lock instance should be 'gevent.threading.Lock'."
Esempio n. 5
0
    def test_get_instance_with_asynchronous_mode(self, mr_event: EventFactory):
        from asyncio.locks import Event
        from asyncio import new_event_loop

        try:
            _event = mr_event.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_event.feature_mode = FeatureMode.Asynchronous
        _event = mr_event.get_instance(event_loop=new_event_loop())
        assert _event is not None and isinstance(
            _event, Event
        ) is True, "This type of Event instance should be 'asyncio.locks.Event'."
Esempio n. 6
0
 def test__repr__(self, mr_event: EventFactory):
     _testing_mode = FeatureMode.Parallel
     mr_event.feature_mode = _testing_mode
     _lock_repr = repr(mr_event)
     _chksum = re.search(
         r"<Event\(\) object with FeatureMode.[a-zA-Z]{4,32} mode at \w{10,30}>",
         _lock_repr)
     assert _chksum is not None, f"The '__repr__' format is incorrect. Please check its value. \n" \
                                 f"Its format should be like *<Event() object with <Feature Mode> mode at <ID of instance>>*. \n" \
                                 f"But it got *{_lock_repr}*."
Esempio n. 7
0
    def test_feature_mode(self, mr_event: EventFactory):
        _testing_mode = FeatureMode.Parallel

        assert mr_event.feature_mode is None, "The default value of FeatureMode of Event instance should be None."
        try:
            mr_event.feature_mode = _testing_mode
        except Exception as e:
            assert False, "It should set the FeatureMode into Event instance without any issue."
        else:
            _feature_mode = mr_event.feature_mode
            assert _feature_mode is _testing_mode, f"The mode we got from Event instance should be the same as we set '{_testing_mode}'."
Esempio n. 8
0
def mr_event() -> EventFactory:
    return EventFactory()
Esempio n. 9
0
def instantiate_event(_mode, **kwargs):
    _event = EventFactory()
    return _initial(_event, _mode, **kwargs)
Esempio n. 10
0
 def test_feature_in_asynchronous_tasks(self):
     _event_opt = EventAsyncOperator()
     EventTestSpec._async_feature_testing(
         _lock=_event_opt,
         running_function=MapByStrategy.CoroutineWithAsynchronous,
         factory=EventFactory())
def instantiate_event(_mode: Union[RunningMode, FeatureMode], **kwargs):
    _event = EventFactory()
    return _initial(_event, _mode, **kwargs)