Ejemplo n.º 1
0
 def test_reset_duts(self):
     bench = Bench()
     bench.logger = mock.MagicMock()
     bench.args = mock.MagicMock()
     bench._resources._args = bench.args
     type(bench.args).my_duts = mock.PropertyMock(return_value=False)
     type(bench.args).pause_when_external_dut = mock.MagicMock(
         return_value=False)
     bench._resources.init(mock.MagicMock())
     mock_dut = mock.MagicMock()
     dutconf = {"reset.return_value": True, "initCLI.return_value": True}
     mock_dut.configure_mock(**dutconf)
     mock_dutrange = range(2)
     mock_duts = [mock_dut, mock_dut]
     bench.duts = mock_duts
     # TODO: This mocking does not work somehow
     with mock.patch.object(bench.resource_configuration,
                            "get_dut_range",
                            return_value=mock_dutrange):
         with mock.patch.object(bench, "is_my_dut_index",
                                return_value=True):
             for method in ["hard", "soft", None]:
                 bench.args.reset = method
                 bench.reset_dut()
                 mock_dut.reset.assert_called_with(method)
                 self.assertEqual(mock_dut.reset.call_count, 2)
                 mock_dut.reset.reset_mock()
Ejemplo n.º 2
0
    def test_precmds_to_two_duts(self, mock_ec, mock_rp):
        # pylint: disable=no-self-use
        bench = Bench()
        bench._resource_provider = mock.Mock()
        bench.args = mock.MagicMock()
        bench.args.my_duts = mock.MagicMock(return_value=False)
        bench.execute_command = mock.MagicMock()
        mock_resconf = mock.Mock()
        mock_resconf.get_dut_configuration = mock.MagicMock(return_value=[{
            "pre_cmds": ["first", "second"]
        }, {
            "pre_cmds": ["first2", "second2"]
        }])
        bench.resource_configuration = mock_resconf
        mock_resconf.count_duts = mock.MagicMock(return_value=2)
        # Call using mangled name of __send_pre_commands method
        bench.send_pre_commands()
        mock_ec.assert_has_calls([
            mock.call(1, "first"),
            mock.call(1, "second"),
            mock.call(2, "first2"),
            mock.call(2, "second2")
        ])

        bench.execute_command.reset_mock()
        # Test again with argument cmds
        bench.send_pre_commands("somecommand")
        mock_ec.assert_has_calls([
            mock.call(1, "first"),
            mock.call(1, "second"),
            mock.call(2, "first2"),
            mock.call(2, "second2"),
            mock.call("*", "somecommand")
        ])
Ejemplo n.º 3
0
    def test_postcmds_to_two_duts(self, mock_ec, mock_rp):
        # pylint: disable=no-self-use
        bench = Bench()
        bench._resource_provider = mock.MagicMock()
        bench.execute_command = mock.MagicMock()
        bench.args = mock.MagicMock()
        bench.logger = mock.MagicMock()
        type(bench.args).my_duts = mock.PropertyMock(return_value=False)
        type(bench.args).pause_when_external_dut = mock.MagicMock(
            return_value=False)
        bench._resources.init(mock.MagicMock())
        bench._commands.init()
        mock_dut1 = mock.MagicMock()
        type(mock_dut1).index = mock.PropertyMock(return_value=1)
        mock_dut2 = mock.MagicMock()
        type(mock_dut2).index = mock.PropertyMock(return_value=2)
        bench._resources.duts = [mock_dut1, mock_dut2]
        mock_resconf = mock.Mock()
        mock_resconf.get_dut_configuration = mock.MagicMock(return_value=[{
            "post_cmds": ["first", "second"]
        }, {
            "post_cmds": ["first2", "second2"]
        }])
        bench.resource_configuration = mock_resconf
        mock_resconf.count_duts = mock.MagicMock(return_value=2)
        bench.send_post_commands()
        mock_ec.assert_has_calls([
            mock.call(1, "first"),
            mock.call(1, "second"),
            mock.call(2, "first2"),
            mock.call(2, "second2")
        ])

        mock_ec.reset_mock()
        # Test again with argument cmds
        bench.send_post_commands("somecommand")
        mock_ec.assert_has_calls([
            mock.call(1, "first"),
            mock.call(1, "second"),
            mock.call(2, "first2"),
            mock.call(2, "second2"),
            mock.call("*", "somecommand")
        ])