Explorar el Código

update tests for code evolution (config, logger)

Bastien Sevajol hace 7 años
padre
commit
09be8fa91d
Se han modificado 3 ficheros con 45 adiciones y 23 borrados
  1. 12 4
      tests/test_life_game.py
  2. 15 5
      tests/test_terminals.py
  3. 18 14
      tests/test_xyz.py

+ 12 - 4
tests/test_life_game.py Ver fichero

@@ -3,9 +3,11 @@ import collections
3 3
 from sandbox.life_game.simulation import Cell
4 4
 from sandbox.life_game.simulation import Empty
5 5
 from sandbox.life_game.utils import get_subjects_from_str_representation
6
+from synergine2.config import Config
6 7
 from synergine2.cycle import CycleManager
7
-from synergine2.simulation import Simulation
8
+from synergine2.log import SynergineLogger
8 9
 from synergine2.xyz import XYZSubjects
10
+from synergine2.xyz import XYZSimulation
9 11
 from synergine2.xyz_utils import get_str_representation_from_positions
10 12
 from tests import BaseTest
11 13
 from tests import str_kwargs
@@ -30,11 +32,13 @@ class LifeGameBaseTest(BaseTest):
30 32
 
31 33
 class TestSimpleSimulation(LifeGameBaseTest):
32 34
     def test_cycles_evolution(self):
33
-        simulation = Simulation()
35
+        simulation = XYZSimulation(Config())
34 36
         subjects = self._get_subjects(simulation)
35 37
         simulation.subjects = subjects
36 38
 
37 39
         cycle_manager = CycleManager(
40
+            Config(),
41
+            SynergineLogger('test'),
38 42
             simulation=simulation,
39 43
         )
40 44
 
@@ -70,7 +74,7 @@ class TestSimpleSimulation(LifeGameBaseTest):
70 74
             subjects,
71 75
         )
72 76
 
73
-    def _get_subjects(self, simulation: Simulation):
77
+    def _get_subjects(self, simulation: XYZSimulation):
74 78
         cells = XYZSubjects(simulation=simulation)
75 79
 
76 80
         for position in [
@@ -79,6 +83,7 @@ class TestSimpleSimulation(LifeGameBaseTest):
79 83
             (1, 0, 0),
80 84
         ]:
81 85
             cells.append(Cell(
86
+                Config(),
82 87
                 simulation=simulation,
83 88
                 position=position,
84 89
             ))
@@ -98,6 +103,7 @@ class TestSimpleSimulation(LifeGameBaseTest):
98 103
             (2, 1, 0),
99 104
         ]:
100 105
             cells.append(Empty(
106
+                Config(),
101 107
                 simulation=simulation,
102 108
                 position=position,
103 109
             ))
@@ -164,7 +170,7 @@ class TestMultipleSimulations(LifeGameBaseTest):
164 170
         """,
165 171
         ]
166 172
 
167
-        simulation = Simulation()
173
+        simulation = XYZSimulation(Config())
168 174
         subjects = get_subjects_from_str_representation(
169 175
             str_representations[0],
170 176
             simulation,
@@ -172,6 +178,8 @@ class TestMultipleSimulations(LifeGameBaseTest):
172 178
         simulation.subjects = subjects
173 179
 
174 180
         cycle_manager = CycleManager(
181
+            config=Config(),
182
+            logger=SynergineLogger('test'),
175 183
             simulation=simulation,
176 184
         )
177 185
 

+ 15 - 5
tests/test_terminals.py Ver fichero

@@ -1,6 +1,8 @@
1 1
 # coding: utf-8
2 2
 import time
3 3
 
4
+from synergine2.config import Config
5
+from synergine2.log import SynergineLogger
4 6
 from synergine2.simulation import Event
5 7
 from synergine2.terminals import Terminal
6 8
 from synergine2.terminals import TerminalPackage
@@ -42,8 +44,10 @@ class SendBackTerminal(Terminal):
42 44
 class TestTerminals(BaseTest):
43 45
     def test_terminal_communications(self):
44 46
         terminals_manager = TerminalManager(
47
+            Config(),
48
+            SynergineLogger('test'),
45 49
             terminals=[
46
-                MultiplyTerminal(),
50
+                MultiplyTerminal(Config(), SynergineLogger('test')),
47 51
             ]
48 52
         )
49 53
         terminals_manager.start()
@@ -67,9 +71,11 @@ class TestTerminals(BaseTest):
67 71
 
68 72
     def test_terminals_communications(self):
69 73
         terminals_manager = TerminalManager(
74
+            Config(),
75
+            SynergineLogger('test'),
70 76
             terminals=[
71
-                MultiplyTerminal(),
72
-                DivideTerminal(),
77
+                MultiplyTerminal(Config(), SynergineLogger('test')),
78
+                DivideTerminal(Config(), SynergineLogger('test')),
73 79
             ]
74 80
         )
75 81
         terminals_manager.start()
@@ -98,7 +104,9 @@ class TestTerminals(BaseTest):
98 104
             pass
99 105
 
100 106
         terminals_manager = TerminalManager(
101
-            terminals=[ListenEverythingTerminal()]
107
+            Config(),
108
+            SynergineLogger('test'),
109
+            terminals=[ListenEverythingTerminal(Config(), SynergineLogger('test'))]
102 110
         )
103 111
         terminals_manager.start()
104 112
         terminals_manager.send(ValueTerminalPackage(value=42))
@@ -125,7 +133,9 @@ class TestTerminals(BaseTest):
125 133
             subscribed_events = [AnOtherEvent]
126 134
 
127 135
         terminals_manager = TerminalManager(
128
-            terminals=[ListenAnEventTerminal()]
136
+            Config(),
137
+            SynergineLogger('test'),
138
+            terminals=[ListenAnEventTerminal(Config(), SynergineLogger('test'))]
129 139
         )
130 140
         terminals_manager.start()
131 141
         terminals_manager.send(ValueTerminalPackage(value=42))

+ 18 - 14
tests/test_xyz.py Ver fichero

@@ -1,9 +1,10 @@
1 1
 # coding: utf-8
2 2
 # -*- coding: utf-8 -*-
3
+from synergine2.config import Config
3 4
 from synergine2.simulation import Subject
4
-from synergine2.simulation import Subjects
5
-from synergine2.simulation import Simulation
6 5
 from synergine2.xyz import ProximitySubjectMechanism
6
+from synergine2.xyz import XYZSubjects
7
+from synergine2.xyz import XYZSimulation
7 8
 from synergine2.xyz import XYZSubjectMixin
8 9
 from synergine2.xyz_utils import get_positions_from_str_representation
9 10
 from synergine2.xyz_utils import get_str_representation_from_positions
@@ -21,16 +22,17 @@ class MyProximityMechanism(ProximitySubjectMechanism):
21 22
 
22 23
 class TestXYZ(BaseTest):
23 24
     def test_proximity_mechanism_with_one(self):
24
-        simulation = Simulation()
25
-        subject = MySubject(simulation, position=(0, 0, 0))
26
-        other_subject = MySubject(simulation, position=(5, 0, 0))
25
+        simulation = XYZSimulation(Config())
26
+        subject = MySubject(Config(), simulation, position=(0, 0, 0))
27
+        other_subject = MySubject(Config(), simulation, position=(5, 0, 0))
27 28
 
28
-        simulation.subjects = Subjects(
29
+        simulation.subjects = XYZSubjects(
29 30
             [subject, other_subject],
30 31
             simulation=simulation,
31 32
         )
32 33
 
33 34
         proximity_mechanism = MyProximityMechanism(
35
+            config=Config(),
34 36
             simulation=simulation,
35 37
             subject=subject,
36 38
         )
@@ -46,16 +48,17 @@ class TestXYZ(BaseTest):
46 48
         }] == proximity_mechanism.run()
47 49
 
48 50
     def test_proximity_mechanism_excluding(self):
49
-        simulation = Simulation()
50
-        subject = MySubject(simulation, position=(0, 0, 0))
51
-        other_subject = MySubject(simulation, position=(11, 0, 0))
51
+        simulation = XYZSimulation(Config())
52
+        subject = MySubject(Config(), simulation, position=(0, 0, 0))
53
+        other_subject = MySubject(Config(), simulation, position=(11, 0, 0))
52 54
 
53
-        simulation.subjects = Subjects(
55
+        simulation.subjects = XYZSubjects(
54 56
             [subject, other_subject],
55 57
             simulation=simulation,
56 58
         )
57 59
 
58 60
         proximity_mechanism = MyProximityMechanism(
61
+            config=Config(),
59 62
             simulation=simulation,
60 63
             subject=subject,
61 64
         )
@@ -68,17 +71,18 @@ class TestXYZ(BaseTest):
68 71
         assert [] == proximity_mechanism.run()
69 72
 
70 73
     def test_proximity_mechanism_with_multiple(self):
71
-        simulation = Simulation()
72
-        subject = MySubject(simulation, position=(0, 0, 0))
74
+        simulation = XYZSimulation(Config())
75
+        subject = MySubject(Config(), simulation, position=(0, 0, 0))
73 76
         other_subjects = []
74 77
 
75 78
         for i in range(3):
76
-            other_subjects.append(MySubject(simulation, position=(i, i, 0)))
79
+            other_subjects.append(MySubject(Config(), simulation, position=(i, i, 0)))
77 80
 
78
-        simulation.subjects = Subjects([subject], simulation=simulation)
81
+        simulation.subjects = XYZSubjects([subject], simulation=simulation)
79 82
         simulation.subjects.extend(other_subjects)
80 83
 
81 84
         proximity_mechanism = MyProximityMechanism(
85
+            config=Config(),
82 86
             simulation=simulation,
83 87
             subject=subject,
84 88
         )