|  | @@ -153,19 +153,15 @@ class TestBehaviours(BaseTest):
 | 
	
		
			
			| 153 | 153 |              process_manager=do_nothing_process_manager,
 | 
	
		
			
			| 154 | 154 |          )
 | 
	
		
			
			| 155 | 155 |  
 | 
	
		
			
			| 156 |  | -        # Cycle 0: behaviour NOT executed
 | 
	
		
			
			|  | 156 | +        # Cycle 0: behaviour IS executed
 | 
	
		
			
			| 157 | 157 |          cycle_manager.current_cycle = 0
 | 
	
		
			
			| 158 | 158 |          results_by_subjects = cycle_manager._job_subjects(worker_id=0, process_count=1)
 | 
	
		
			
			| 159 | 159 |          assert results_by_subjects
 | 
	
		
			
			| 160 |  | -        assert id(my_subject) in results_by_subjects
 | 
	
		
			
			| 161 |  | -        assert not results_by_subjects[id(my_subject)]
 | 
	
		
			
			| 162 | 160 |  
 | 
	
		
			
			| 163 |  | -        # Cycle 1: behaviour executed
 | 
	
		
			
			|  | 161 | +        # Cycle 1: behaviour IS NOT executed
 | 
	
		
			
			| 164 | 162 |          cycle_manager.current_cycle = 1
 | 
	
		
			
			| 165 | 163 |          results_by_subjects = cycle_manager._job_subjects(worker_id=0, process_count=1)
 | 
	
		
			
			| 166 |  | -        assert results_by_subjects
 | 
	
		
			
			| 167 |  | -        assert id(my_subject) in results_by_subjects
 | 
	
		
			
			| 168 |  | -        assert results_by_subjects[id(my_subject)]
 | 
	
		
			
			|  | 164 | +        assert not results_by_subjects
 | 
	
		
			
			| 169 | 165 |  
 | 
	
		
			
			| 170 | 166 |      def test_subject_behaviour_seconds_frequency(
 | 
	
		
			
			| 171 | 167 |          self,
 | 
	
	
		
			
			|  | @@ -199,23 +195,17 @@ class TestBehaviours(BaseTest):
 | 
	
		
			
			| 199 | 195 |          # Less second after: NOT executed
 | 
	
		
			
			| 200 | 196 |          with freeze_time(datetime.datetime(2000, 12, 1, 0, 0, 0, 500000)):
 | 
	
		
			
			| 201 | 197 |              data = cycle_manager._job_subjects(worker_id=0, process_count=1)
 | 
	
		
			
			| 202 |  | -            assert data
 | 
	
		
			
			| 203 |  | -            assert id(my_subject) in data
 | 
	
		
			
			| 204 |  | -            assert not data[id(my_subject)]
 | 
	
		
			
			|  | 198 | +            assert not data
 | 
	
		
			
			| 205 | 199 |  
 | 
	
		
			
			| 206 | 200 |          # Less second after: NOT executed
 | 
	
		
			
			| 207 | 201 |          with freeze_time(datetime.datetime(2000, 12, 1, 0, 0, 0, 700000)):
 | 
	
		
			
			| 208 | 202 |              data = cycle_manager._job_subjects(worker_id=0, process_count=1)
 | 
	
		
			
			| 209 |  | -            assert data
 | 
	
		
			
			| 210 |  | -            assert id(my_subject) in data
 | 
	
		
			
			| 211 |  | -            assert not data[id(my_subject)]
 | 
	
		
			
			|  | 203 | +            assert not data
 | 
	
		
			
			| 212 | 204 |  
 | 
	
		
			
			| 213 |  | -        # Less second after: NOT executed
 | 
	
		
			
			|  | 205 | +        # Less second after: IS executed
 | 
	
		
			
			| 214 | 206 |          with freeze_time(datetime.datetime(2000, 12, 1, 0, 0, 1, 500000)):
 | 
	
		
			
			| 215 | 207 |              data = cycle_manager._job_subjects(worker_id=0, process_count=1)
 | 
	
		
			
			| 216 | 208 |              assert data
 | 
	
		
			
			| 217 |  | -            assert id(my_subject) in data
 | 
	
		
			
			| 218 |  | -            assert data[id(my_subject)]
 | 
	
		
			
			| 219 | 209 |  
 | 
	
		
			
			| 220 | 210 |      def test_simulation_behaviour_cycle_frequency(
 | 
	
		
			
			| 221 | 211 |          self,
 | 
	
	
		
			
			|  | @@ -237,15 +227,15 @@ class TestBehaviours(BaseTest):
 | 
	
		
			
			| 237 | 227 |              process_manager=do_nothing_process_manager,
 | 
	
		
			
			| 238 | 228 |          )
 | 
	
		
			
			| 239 | 229 |  
 | 
	
		
			
			| 240 |  | -        # Cycle 0: behaviour NOT executed
 | 
	
		
			
			|  | 230 | +        # Cycle 0: behaviour IS executed
 | 
	
		
			
			| 241 | 231 |          cycle_manager.current_cycle = 0
 | 
	
		
			
			| 242 | 232 |          data = cycle_manager._job_simulation(worker_id=0, process_count=1)
 | 
	
		
			
			| 243 |  | -        assert not data
 | 
	
		
			
			|  | 233 | +        assert data
 | 
	
		
			
			| 244 | 234 |  
 | 
	
		
			
			| 245 |  | -        # Cycle 1: behaviour executed
 | 
	
		
			
			|  | 235 | +        # Cycle 1: behaviour IS NOT executed
 | 
	
		
			
			| 246 | 236 |          cycle_manager.current_cycle = 1
 | 
	
		
			
			| 247 | 237 |          data = cycle_manager._job_simulation(worker_id=0, process_count=1)
 | 
	
		
			
			| 248 |  | -        assert data
 | 
	
		
			
			|  | 238 | +        assert not data
 | 
	
		
			
			| 249 | 239 |  
 | 
	
		
			
			| 250 | 240 |      def test_simulation_behaviour_seconds_frequency(
 | 
	
		
			
			| 251 | 241 |          self,
 | 
	
	
		
			
			|  | @@ -468,12 +458,82 @@ class TestMechanisms(BaseTest):
 | 
	
		
			
			| 468 | 458 |          cycle_manager._job_simulation(worker_id=0, process_count=1)
 | 
	
		
			
			| 469 | 459 |          assert called == 0
 | 
	
		
			
			| 470 | 460 |  
 | 
	
		
			
			| 471 |  | -    def test_mechanism_not_called_if_subject_behavior_timebase_not_active_yet(self):
 | 
	
		
			
			|  | 461 | +    def test_mechanism_not_called_if_subject_behavior_cycled_not_active_yet(
 | 
	
		
			
			|  | 462 | +        self,
 | 
	
		
			
			|  | 463 | +        do_nothing_process_manager: ProcessManager,
 | 
	
		
			
			|  | 464 | +    ):
 | 
	
		
			
			|  | 465 | +        shared.reset()
 | 
	
		
			
			|  | 466 | +        called = 0
 | 
	
		
			
			|  | 467 | +        global called
 | 
	
		
			
			|  | 468 | +
 | 
	
		
			
			|  | 469 | +        class MySubjectMechanism(SubjectMechanism):
 | 
	
		
			
			|  | 470 | +            def run(self):
 | 
	
		
			
			|  | 471 | +                global called
 | 
	
		
			
			|  | 472 | +                called += 1
 | 
	
		
			
			|  | 473 | +                return {'foo': 42}
 | 
	
		
			
			|  | 474 | +
 | 
	
		
			
			|  | 475 | +        class MySubjectBehaviour1(SubjectBehaviour):
 | 
	
		
			
			|  | 476 | +            use = [MySubjectMechanism]
 | 
	
		
			
			|  | 477 | +
 | 
	
		
			
			|  | 478 | +            @property
 | 
	
		
			
			|  | 479 | +            def cycle_frequency(self):
 | 
	
		
			
			|  | 480 | +                return 2
 | 
	
		
			
			|  | 481 | +
 | 
	
		
			
			|  | 482 | +            def run(self, data):
 | 
	
		
			
			|  | 483 | +                return {'bar': data[MySubjectMechanism]['foo'] + 100}
 | 
	
		
			
			|  | 484 | +
 | 
	
		
			
			|  | 485 | +        class MySubject(Subject):
 | 
	
		
			
			|  | 486 | +            behaviours_classes = [MySubjectBehaviour1]
 | 
	
		
			
			|  | 487 | +
 | 
	
		
			
			|  | 488 | +        simulation = Simulation(config)
 | 
	
		
			
			|  | 489 | +        my_subject = MySubject(config, simulation)
 | 
	
		
			
			|  | 490 | +        subjects = Subjects(simulation=simulation)
 | 
	
		
			
			|  | 491 | +        subjects.append(my_subject)
 | 
	
		
			
			|  | 492 | +        simulation.subjects = subjects
 | 
	
		
			
			|  | 493 | +
 | 
	
		
			
			|  | 494 | +        cycle_manager = CycleManager(
 | 
	
		
			
			|  | 495 | +            config,
 | 
	
		
			
			|  | 496 | +            logger,
 | 
	
		
			
			|  | 497 | +            simulation=simulation,
 | 
	
		
			
			|  | 498 | +            process_manager=do_nothing_process_manager,
 | 
	
		
			
			|  | 499 | +        )
 | 
	
		
			
			|  | 500 | +
 | 
	
		
			
			|  | 501 | +        cycle_manager.current_cycle = 0
 | 
	
		
			
			|  | 502 | +        cycle_manager._job_subjects(worker_id=0, process_count=1)
 | 
	
		
			
			|  | 503 | +        assert called == 1
 | 
	
		
			
			|  | 504 | +
 | 
	
		
			
			|  | 505 | +        cycle_manager.current_cycle = 1
 | 
	
		
			
			|  | 506 | +        cycle_manager._job_subjects(worker_id=0, process_count=1)
 | 
	
		
			
			|  | 507 | +        assert called == 1
 | 
	
		
			
			|  | 508 | +
 | 
	
		
			
			|  | 509 | +        cycle_manager.current_cycle = 2
 | 
	
		
			
			|  | 510 | +        cycle_manager._job_subjects(worker_id=0, process_count=1)
 | 
	
		
			
			|  | 511 | +        assert called == 2
 | 
	
		
			
			|  | 512 | +
 | 
	
		
			
			|  | 513 | +        cycle_manager.current_cycle = 3
 | 
	
		
			
			|  | 514 | +        cycle_manager._job_subjects(worker_id=0, process_count=1)
 | 
	
		
			
			|  | 515 | +        assert called == 2
 | 
	
		
			
			|  | 516 | +
 | 
	
		
			
			|  | 517 | +    def test_mechanism_not_called_if_simulation_behavior_cycled_not_active_yet(
 | 
	
		
			
			|  | 518 | +        self,
 | 
	
		
			
			|  | 519 | +        do_nothing_process_manager: ProcessManager,
 | 
	
		
			
			|  | 520 | +    ):
 | 
	
		
			
			| 472 | 521 |          shared.reset()
 | 
	
		
			
			| 473 | 522 |  
 | 
	
		
			
			| 474 | 523 |          pass
 | 
	
		
			
			| 475 | 524 |  
 | 
	
		
			
			| 476 |  | -    def test_mechanism_not_called_if_simulation_behavior_timebase_not_active_yet(self):
 | 
	
		
			
			|  | 525 | +    def test_mechanism_not_called_if_subject_behavior_timebase_not_active_yet(
 | 
	
		
			
			|  | 526 | +        self,
 | 
	
		
			
			|  | 527 | +        do_nothing_process_manager: ProcessManager,
 | 
	
		
			
			|  | 528 | +    ):
 | 
	
		
			
			|  | 529 | +        shared.reset()
 | 
	
		
			
			|  | 530 | +
 | 
	
		
			
			|  | 531 | +        pass
 | 
	
		
			
			|  | 532 | +
 | 
	
		
			
			|  | 533 | +    def test_mechanism_not_called_if_simulation_behavior_timebase_not_active_yet(
 | 
	
		
			
			|  | 534 | +        self,
 | 
	
		
			
			|  | 535 | +        do_nothing_process_manager: ProcessManager,
 | 
	
		
			
			|  | 536 | +    ):
 | 
	
		
			
			| 477 | 537 |          shared.reset()
 | 
	
		
			
			| 478 | 538 |  
 | 
	
		
			
			| 479 | 539 |          pass
 |