Example #1
0
    def test_engine_error(self):
        """ Test an engine can raises a non-StopIteration error.
        """
        s = Simulator(max_iterations=5)
        s.network = Network("Iteration test network")

        s.add_engine(TypeErrorEngine(None, error_on_iteration=1))
        s.add_engine(CountEngine(None))
        s.timesteps = [0, ]

        with self.assertRaises(TypeError):
            s.start()
Example #2
0
    def test_engine_iteration(self):
        """ Test setting the global number of iterations in a simulator. """
        s = Simulator(max_iterations=5)
        s.network = Network("Iteration test network")
        engine = CountEngine(None)
        s.add_engine(engine)

        s.timesteps = [0, ]
        s.start()

        assert engine.iteration == 5
        assert engine.run_count == 5
Example #3
0
    def test_default_iteration(self):
        """ Test that the default simulation `max_iterations` is one. """
        s = Simulator()
        s.network = Network("Iteration test network")
        engine = CountEngine(None)
        s.add_engine(engine)

        s.timesteps = [0, ]
        s.start()

        assert engine.iteration == 1
        assert engine.run_count == 1
Example #4
0
    def test_engine_error(self):
        """ Test an engine can raises a non-StopIteration error.
        """
        s = Simulator(max_iterations=5)
        s.network = Network("Iteration test network")

        s.add_engine(TypeErrorEngine(None, error_on_iteration=1))
        s.add_engine(CountEngine(None))
        s.timesteps = [
            0,
        ]

        with self.assertRaises(TypeError):
            s.start()
Example #5
0
    def test_engine_iteration(self):
        """ Test setting the global number of iterations in a simulator. """
        s = Simulator(max_iterations=5)
        s.network = Network("Iteration test network")
        engine = CountEngine(None)
        s.add_engine(engine)

        s.timesteps = [
            0,
        ]
        s.start()

        assert engine.iteration == 5
        assert engine.run_count == 5
Example #6
0
    def test_default_iteration(self):
        """ Test that the default simulation `max_iterations` is one. """
        s = Simulator()
        s.network = Network("Iteration test network")
        engine = CountEngine(None)
        s.add_engine(engine)

        s.timesteps = [
            0,
        ]
        s.start()

        assert engine.iteration == 1
        assert engine.run_count == 1
Example #7
0
    def test_dict_overwrite(self):
        """
            Test to ensure that dictionaries and other objects contained in history
            are not overwritten by maintaining references to the same objects.
        """
        print("Testing...")
        network = Network("History Test Network")
        network.add_node(HistoryTestNode(x=0, y=0, name="Test Node"))

        s = Simulator()
        s.network = network
        s.timesteps = ['a', 'b', 'c']


        s.start()
        
        assert s.network.nodes[0]._history['property_dict'] == [{'test': 'a'}, {'test': 'b'}, {'test': 'c'}]
Example #8
0
    def test_engine_stopping_iteration(self):
        """ Test an engine terminating iteration

        The engine must raise a `StopIteration` exception.
        """
        s = Simulator(max_iterations=5)
        s.network = Network("Iteration test network")

        stopper_engine = StopperEngine(None, stop_on_iteration=2)
        s.add_engine(stopper_engine)
        engine = CountEngine(None)
        s.add_engine(engine)

        s.timesteps = [0, ]
        s.start()

        assert engine.iteration == 1
        assert engine.run_count == 1
        assert stopper_engine.iteration == 2
Example #9
0
    def test_engine_stopping_iteration(self):
        """ Test an engine terminating iteration

        The engine must raise a `StopIteration` exception.
        """
        s = Simulator(max_iterations=5)
        s.network = Network("Iteration test network")

        stopper_engine = StopperEngine(None, stop_on_iteration=2)
        s.add_engine(stopper_engine)
        engine = CountEngine(None)
        s.add_engine(engine)

        s.timesteps = [
            0,
        ]
        s.start()

        assert engine.iteration == 1
        assert engine.run_count == 1
        assert stopper_engine.iteration == 2
Example #10
0
    def test_dict_overwrite(self):
        """
            Test to ensure that dictionaries and other objects contained in history
            are not overwritten by maintaining references to the same objects.
        """
        print("Testing...")
        network = Network("History Test Network")
        network.add_node(HistoryTestNode(x=0, y=0, name="Test Node"))

        s = Simulator()
        s.network = network
        s.timesteps = ['a', 'b', 'c']

        s.start()

        assert s.network.nodes[0]._history['property_dict'] == [{
            'test': 'a'
        }, {
            'test': 'b'
        }, {
            'test': 'c'
        }]