Skip to content

Commit

Permalink
tests BoboNullEventElapse
Browse files Browse the repository at this point in the history
  • Loading branch information
r3w0p committed Apr 25, 2022
1 parent fcef180 commit 4cb576e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
6 changes: 3 additions & 3 deletions bobocep/engine/decider/bobo_decider_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# The following code can be redistributed and/or modified
# under the terms of the GNU General Public License v3.0.

from bobocep.events.bobo_event import BoboEvent
from bobocep.events.bobo_history import BoboHistory
from bobocep.pattern.bobo_pattern import BoboPattern
from threading import RLock
from typing import List

from bobocep.events.bobo_event import BoboEvent
from bobocep.events.bobo_history import BoboHistory
from bobocep.pattern.bobo_pattern import BoboPattern
from bobocep.pattern.bobo_pattern_block import BoboPatternBlock
from bobocep.predicate.bobo_predicate import BoboPredicate

Expand Down
5 changes: 3 additions & 2 deletions bobocep/engine/receiver/null_event/bobo_null_event_elapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ class BoboNullEventElapse(BoboNullEvent):

def __init__(self,
milliseconds: int,
datagen=Callable,
datagen: Callable,
from_now: bool = True,
tz=None):
super().__init__()

self._milliseconds = milliseconds
self._datagen = datagen
self._tz = tz
self._last = 0
self._last = self._time_ms() if from_now else 0

def maybe_generate(self, event_id: str) -> Union[BoboEvent, None]:
now = BoboNullEventElapse._time_ms()
Expand Down
16 changes: 15 additions & 1 deletion tests/test_engine/test_decider/test_bobo_decider_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# The following code can be redistributed and/or modified
# under the terms of the GNU General Public License v3.0.

import pytest
from datetime import datetime

from bobocep.engine.decider.bobo_decider_run import BoboDeciderRun
Expand Down Expand Up @@ -71,6 +70,21 @@ def test_pattern_3_block_manual_halt_not_complete():
assert not run.is_complete()


def test_pattern_3_block_process_on_halt():
pattern = BoboPatternBuilder() \
.followed_by("group_a", BoboPredicateCallable(lambda e, h: True)) \
.followed_by("group_b", BoboPredicateCallable(lambda e, h: True)) \
.followed_by("group_c", BoboPredicateCallable(lambda e, h: True)) \
.generate("pattern")

run = BoboDeciderRun("run_id", pattern,
BoboEventPrimitive("event_a", datetime.now(), None))

run.halt()
run.process(BoboEventPrimitive("event_b", datetime.now(), None))
assert run.is_halted()


def test_pattern_3_block_halt_no_match_on_strict():
pattern = BoboPatternBuilder() \
.followed_by("group_a", BoboPredicateCallable(lambda e, h: True)) \
Expand Down
5 changes: 3 additions & 2 deletions tests/test_pattern/test_bobo_pattern_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# The following code can be redistributed and/or modified
# under the terms of the GNU General Public License v3.0.

import pytest
from dpcontracts import PreconditionError

from bobocep.pattern.bobo_pattern_block import BoboPatternBlock
from bobocep.predicate.bobo_predicate_callable import BoboPredicateCallable
from dpcontracts import PreconditionError
import pytest


def test_negated_and_optional_both_false_if_loop_true():
Expand Down

0 comments on commit 4cb576e

Please sign in to comment.