Skip to content

Commit

Permalink
bobo decider run development - need tests for decider material...
Browse files Browse the repository at this point in the history
  • Loading branch information
r3w0p committed Apr 24, 2022
1 parent 789c70a commit e4f0fe9
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 42 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ jobs:
GITHUB_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
run: |
coveralls
- name: Delete old workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: 1
keep_minimum_runs: 10
20 changes: 0 additions & 20 deletions .github/workflows/runs.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ jobs:

- name: CodeQL analysis
uses: github/codeql-action/analyze@v1

- name: Delete old workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: 1
keep_minimum_runs: 10
53 changes: 42 additions & 11 deletions bobocep/engine/decider/bobo_decider_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,54 @@ def process(self, event: BoboEvent) -> bool:
return False

block: BoboPatternBlock = self.pattern.blocks[self._block_index]
# match = self._is_match(event, block.predicates)

if block.loop:
self._process_loop()
self._process_loop(event, block)
else:
self._process_not_loop()
self._process_not_loop(event, block)

def _process_loop(self) -> None:
# a looping block cannot be negated or optional
# i.e. negated and optional are False if loop is True
pass
def _process_loop(self,
event: BoboEvent,
block: BoboPatternBlock) -> None:
# a looping block can neither be negated nor optional
match = self._is_match(event, block.predicates)

def _process_not_loop(self) -> None:
if not match:
if block.strict:
self._halted = True

elif self._block_index + 1 < len(self.pattern.blocks):
block = self.pattern.blocks[self._block_index + 1]
if block.loop:
self._process_loop(event, block)
else:
self._process_not_loop(event, block)

def _process_not_loop(self,
event: BoboEvent,
block: BoboPatternBlock) -> None:
# a non-looping block cannot be both negated and optional
# i.e. negated and optional are not both True if loop is False
pass
# a strict block cannot be optional
match = self._is_match(event, block.predicates)

if block.negated:
if match and block.strict:
self._halted = True

elif block.optional:
if not match and self._block_index + 1 < len(self.pattern.blocks):
block = self.pattern.blocks[self._block_index + 1]
if block.loop:
self._process_loop(event, block)
else:
self._process_not_loop(event, block)

else:
if (not match) and block.strict:
self._halted = True

def _is_match(self, event: BoboEvent, predicates: List[BoboPredicate]):
def _is_match(self,
event: BoboEvent,
predicates: List[BoboPredicate]) -> bool:
return any(predicate.evaluate(event=event, history=self.history)
for predicate in predicates)
4 changes: 4 additions & 0 deletions bobocep/pattern/bobo_pattern_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class BoboPatternBlock:
:type optional: bool
"""

# todo cannot be strict and optional?

@require("'group' must be of type str",
lambda args: isinstance(args.group, str))
@require("'group' must have a length greater than 0",
Expand All @@ -50,6 +52,8 @@ class BoboPatternBlock:
lambda args: isinstance(args.negated, bool))
@require("'optional' must be of type bool",
lambda args: isinstance(args.optional, bool))
@require("'strict' and 'optional' must not both be True",
lambda args: not (args.strict and args.optional))
@require("'negated' and 'optional' must both be False if 'loop' is True",
lambda args: (not args.negated and
not args.optional) if args.loop else True)
Expand Down
5 changes: 2 additions & 3 deletions bobocep/pattern/bobo_pattern_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def next(self,
group: str,
predicate: BoboPredicate,
times: int = 1,
loop: bool = False,
optional: bool = False) -> 'BoboPatternBuilder':
loop: bool = False) -> 'BoboPatternBuilder':

for _ in range(max(times, 1)):
self._blocks.append(BoboPatternBlock(
Expand All @@ -41,7 +40,7 @@ def next(self,
strict=True,
loop=loop,
negated=False,
optional=optional))
optional=False))
return self

def not_next(self,
Expand Down
12 changes: 4 additions & 8 deletions tests/test_pattern/test_bobo_pattern_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def test_1_block_1_pre_1_halt():
.next(group=group_a,
predicate=predicate_block_a,
times=1,
loop=False,
optional=False) \
loop=False) \
.precondition(predicate=predicate_pre_a) \
.haltcondition(predicate=predicate_halt_a)

Expand Down Expand Up @@ -64,18 +63,15 @@ def test_3_blocks_3_pres_3_halts():
.next(group=group_a,
predicate=predicate_block_a,
times=1,
loop=False,
optional=False) \
loop=False) \
.next(group=group_b,
predicate=predicate_block_b,
times=1,
loop=False,
optional=False) \
loop=False) \
.next(group=group_c,
predicate=predicate_block_c,
times=1,
loop=False,
optional=False) \
loop=False) \
.precondition(predicate=predicate_pre_a) \
.precondition(predicate=predicate_pre_b) \
.precondition(predicate=predicate_pre_c) \
Expand Down

0 comments on commit e4f0fe9

Please sign in to comment.