Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 33 additions & 26 deletions patterns/other/blackboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,37 @@ def contribute(self):
self.blackboard.common_state['progress'] += random.randint(10, 100)


def main():
"""
>>> blackboard = Blackboard()
>>> blackboard.add_expert(Student(blackboard))
>>> blackboard.add_expert(Scientist(blackboard))
>>> blackboard.add_expert(Professor(blackboard))

>>> c = Controller(blackboard)
>>> contributions = c.run_loop()

>>> from pprint import pprint
>>> pprint(contributions)
['Student',
'Student',
'Student',
'Student',
'Scientist',
'Student',
'Student',
'Student',
'Scientist',
'Student',
'Scientist',
'Student',
'Student',
'Scientist',
'Professor']
"""


if __name__ == '__main__':
blackboard = Blackboard()

blackboard.add_expert(Student(blackboard))
blackboard.add_expert(Scientist(blackboard))
blackboard.add_expert(Professor(blackboard))

c = Controller(blackboard)
contributions = c.run_loop()

from pprint import pprint

pprint(contributions)

### OUTPUT ###
# ['Student',
# 'Student',
# 'Scientist',
# 'Student',
# 'Scientist',
# 'Student',
# 'Scientist',
# 'Student',
# 'Scientist',
# 'Student',
# 'Scientist',
# 'Professor']
random.seed(1234) # for deterministic doctest outputs
import doctest
doctest.testmod()
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
pytest~=4.3.0
pytest-cov~=2.6.0
flake8~=3.7.0
pytest-randomly~=3.1.0
6 changes: 4 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ deps =
-r requirements-dev.txt
commands =
flake8 patterns/
pytest --doctest-modules patterns/
pytest -s -vv --cov={envsitepackagesdir}/patterns --log-level=INFO tests/
; `randomly-seed` option from `pytest-randomly` helps with deterministic outputs for examples like `other/blackboard.py`
pytest --randomly-seed=1234 --doctest-modules patterns/
; `-p no:randomly` turns off `randomly` plugin for unit tests
pytest -s -vv --cov={envsitepackagesdir}/patterns --log-level=INFO -p no:randomly tests/


[testenv:cov-report]
Expand Down