def test_control_server_setter(self, control_server_mock, exposed_object_mock):
        # The return value (= instance of ControlServer) must be specified
        control_server_mock.return_value = Mock()
        exposed_object_mock.return_value = 'test'

        env = Simulation(device=Mock())

        assertRaisesNothing(self, setattr, env, 'control_server', '127.0.0.1:10001')
        control_server_mock.assert_called_once_with(
            {'device': 'test', 'simulation': 'test', 'interface': 'test'}, '127.0.0.1:10001')

        control_server_mock.reset_mock()

        assertRaisesNothing(self, setattr, env, 'control_server', None)
        self.assertIsNone(env.control_server)

        set_simulation_running(env)

        # Can set new control server even when simulation is running:
        assertRaisesNothing(self, setattr, env, 'control_server', '127.0.0.1:10002')

        # The server is started automatically when the simulation is running
        control_server_mock.assert_called_once_with(
            {'device': 'test', 'simulation': 'test', 'interface': 'test'}, '127.0.0.1:10002')

        # The instance must have one call to start_server
        control_server_mock.return_value.assert_has_calls([call.start_server()])

        # Can not replace control server when simulation is running
        self.assertRaises(RuntimeError, setattr, env, 'control_server', '127.0.0.1:10003')
    def test_control_server_setter(self, control_server_mock, exposed_object_mock):
        # The return value (= instance of ControlServer) must be specified
        control_server_mock.return_value = Mock()
        exposed_object_mock.return_value = 'test'
        device_mock = Mock()

        env = Simulation(device=device_mock, adapter=Mock())

        assertRaisesNothing(self, setattr, env, 'control_server', '127.0.0.1:10001')
        control_server_mock.assert_called_once_with(
            {'device': device_mock, 'simulation': 'test'}, '127.0.0.1:10001')

        control_server_mock.reset_mock()

        assertRaisesNothing(self, setattr, env, 'control_server', None)
        self.assertIsNone(env.control_server)

        set_simulation_running(env)

        # Can set new control server even when simulation is running:
        assertRaisesNothing(self, setattr, env, 'control_server', '127.0.0.1:10002')

        # The server is started automatically when the simulation is running
        control_server_mock.assert_called_once_with(
            {'device': device_mock, 'simulation': 'test'}, '127.0.0.1:10002')

        # The instance must have one call to start_server
        control_server_mock.return_value.assert_has_calls([call.start_server()])

        # Can not replace control server when simulation is running
        self.assertRaises(RuntimeError, setattr, env, 'control_server', '127.0.0.1:10003')
Exemplo n.º 3
0
    def test_start_starts_control_server(self):
        env = Simulation(device=Mock())

        control_server_mock = Mock()
        env._control_server = control_server_mock

        def process_cycle_side_effect(delta):
            env.stop()

        env._process_cycle = Mock(side_effect=process_cycle_side_effect)
        env.start()

        control_server_mock.assert_has_calls([call.start_server()])
    def test_start_starts_control_server(self):
        env = Simulation(device=Mock())

        control_server_mock = Mock()
        env._control_server = control_server_mock

        def process_cycle_side_effect(delta):
            env.stop()

        env._process_cycle = Mock(side_effect=process_cycle_side_effect)
        env.start()

        control_server_mock.assert_has_calls([call.start_server()])
Exemplo n.º 5
0
    def test_control_server_setter(self, control_server_mock,
                                   exposed_object_mock):
        # The return value (= instance of ControlServer) must be specified
        control_server_mock.return_value = Mock()
        exposed_object_mock.return_value = "test"

        env = Simulation(device=Mock())

        assertRaisesNothing(self, setattr, env, "control_server",
                            "127.0.0.1:10001")
        control_server_mock.assert_called_once_with(
            {
                "device": "test",
                "simulation": "test",
                "interface": "test"
            },
            "127.0.0.1:10001",
        )

        control_server_mock.reset_mock()

        assertRaisesNothing(self, setattr, env, "control_server", None)
        self.assertIsNone(env.control_server)

        set_simulation_running(env)

        # Can set new control server even when simulation is running:
        assertRaisesNothing(self, setattr, env, "control_server",
                            "127.0.0.1:10002")

        # The server is started automatically when the simulation is running
        control_server_mock.assert_called_once_with(
            {
                "device": "test",
                "simulation": "test",
                "interface": "test"
            },
            "127.0.0.1:10002",
        )

        # The instance must have one call to start_server
        control_server_mock.return_value.assert_has_calls(
            [call.start_server()])

        # Can not replace control server when simulation is running
        self.assertRaises(RuntimeError, setattr, env, "control_server",
                          "127.0.0.1:10003")