Example #1
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")
        ])
Example #2
0
    def test_postcmds_to_two_duts(self, mock_ec, mock_rp):
        tc = Bench()
        tc._resource_provider = mock.Mock()
        tc.execute_command = mock.MagicMock()
        mock_resconf = mock.Mock()
        mock_resconf.get_dut_configuration = mock.MagicMock(return_value=[{
            "post_cmds": ["first", "second"]
        }, {
            "post_cmds": ["first2", "second2"]
        }])
        tc.resource_configuration = mock_resconf
        # Call using mangled name of __send_pre_commands method
        tc._Bench__send_post_commands()
        tc.execute_command.assert_has_calls([
            mock.call(1, "first"),
            mock.call(1, "second"),
            mock.call(2, "first2"),
            mock.call(2, "second2")
        ])

        tc.execute_command.reset_mock()
        # Test again with argument cmds
        tc._Bench__send_post_commands("somecommand")
        tc.execute_command.assert_has_calls([
            mock.call(1, "first"),
            mock.call(1, "second"),
            mock.call(2, "first2"),
            mock.call(2, "second2"),
            mock.call("*", "somecommand")
        ])
Example #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")
        ])