File tree Expand file tree Collapse file tree 3 files changed +38
-28
lines changed
Expand file tree Collapse file tree 3 files changed +38
-28
lines changed Original file line number Diff line number Diff line change @@ -90,30 +90,37 @@ def contribute(self):
9090 self .blackboard .common_state ['progress' ] += random .randint (10 , 100 )
9191
9292
93+ def main ():
94+ """
95+ >>> blackboard = Blackboard()
96+ >>> blackboard.add_expert(Student(blackboard))
97+ >>> blackboard.add_expert(Scientist(blackboard))
98+ >>> blackboard.add_expert(Professor(blackboard))
99+
100+ >>> c = Controller(blackboard)
101+ >>> contributions = c.run_loop()
102+
103+ >>> from pprint import pprint
104+ >>> pprint(contributions)
105+ ['Student',
106+ 'Student',
107+ 'Student',
108+ 'Student',
109+ 'Scientist',
110+ 'Student',
111+ 'Student',
112+ 'Student',
113+ 'Scientist',
114+ 'Student',
115+ 'Scientist',
116+ 'Student',
117+ 'Student',
118+ 'Scientist',
119+ 'Professor']
120+ """
121+
122+
93123if __name__ == '__main__' :
94- blackboard = Blackboard ()
95-
96- blackboard .add_expert (Student (blackboard ))
97- blackboard .add_expert (Scientist (blackboard ))
98- blackboard .add_expert (Professor (blackboard ))
99-
100- c = Controller (blackboard )
101- contributions = c .run_loop ()
102-
103- from pprint import pprint
104-
105- pprint (contributions )
106-
107- ### OUTPUT ###
108- # ['Student',
109- # 'Student',
110- # 'Scientist',
111- # 'Student',
112- # 'Scientist',
113- # 'Student',
114- # 'Scientist',
115- # 'Student',
116- # 'Scientist',
117- # 'Student',
118- # 'Scientist',
119- # 'Professor']
124+ random .seed (1234 ) # for deterministic doctest outputs
125+ import doctest
126+ doctest .testmod ()
Original file line number Diff line number Diff line change 33pytest ~= 4.3.0
44pytest-cov ~= 2.6.0
55flake8 ~= 3.7.0
6+ pytest-randomly ~= 3.1.0
Original file line number Diff line number Diff line change 99 -r requirements-dev.txt
1010commands =
1111 flake8 patterns/
12- pytest --doctest-modules patterns/
13- pytest -s -vv --cov ={envsitepackagesdir}/patterns --log-level =INFO tests/
12+ ; `randomly-seed` option from `pytest-randomly` helps with deterministic outputs for examples like `other/blackboard.py`
13+ pytest --randomly-seed =1234 --doctest-modules patterns/
14+ ; `-p no:randomly` turns off `randomly` plugin for unit tests
15+ pytest -s -vv --cov ={envsitepackagesdir}/patterns --log-level =INFO -p no:randomly tests/
1416
1517
1618[testenv:cov-report]
You can’t perform that action at this time.
0 commit comments