Пример #1
0
 def instance_fixture(self):
     self.mock_input_stream = mock.Mock()
     self.mock_output_stream = mock.Mock()
     self.instance = self.INSTANCE_CLS(
         input_stream=self.mock_input_stream,
         output_stream=self.mock_output_stream,
     )
Пример #2
0
    def test_ack(self):
        tup = mock.Mock(id=1234)

        with mock.patch.object(self.instance, 'send_command') as \
                mock_send_command:
            self.instance.ack(tup)

        mock_send_command.assert_called_once_with('ack', {'id': tup.id})
Пример #3
0
    def test_fail(self):
        tup = mock.Mock(id=1234)

        with mock.patch.object(self.instance, 'send_command', autospec=True) as \
                mock_send_command:
            self.instance.fail(tup)

        mock_send_command.assert_called_once_with('fail', {'id': tup.id})
Пример #4
0
    def test__ensure_storm_path_in_configs_path_not_found(self, mock_search):
        mock_configs = mock.Mock(specs=['storm_cmd_path'])
        mock_configs.storm_cmd_path = None
        mock_search.return_value = None

        with pytest.raises(ConfigurationError):
            subcommand._ensure_storm_path_in_configs(mock_configs)

            mock_search.assert_called_with()
Пример #5
0
    def test__ensure_storm_path_in_configs_path_defined(
            self, mock_update, mock_search):
        mock_configs = mock.Mock(specs=['storm_cmd_path'])

        configs = subcommand._ensure_storm_path_in_configs(mock_configs)

        assert mock_search.called == 0
        assert mock_update.called == 0
        assert configs == mock_configs
Пример #6
0
    def test_no_emit_on_none(self):
        line = "{}"
        mock_tup = mock.Mock(values=(line, ))

        with mock.patch.object(self.instance,
                               'extract_fields',
                               side_effect=[None]):
            self.instance.process_tuple(mock_tup)

        assert not self.instance.emit.called
Пример #7
0
    def test_emit_with_anchors(self):
        expected_command_dict = {
            'anchors': [4, 5, 6],
            'tuple': (1, 2, 3),
        }

        anchors = [mock.Mock(id=i) for i in (4, 5, 6)]

        with self._test_emit_helper(expected_command_dict):
            self.instance.emit((1, 2, 3), anchors=anchors)
Пример #8
0
    def test__ensure_storm_path_in_configs_path_not_defined(
            self, mock_update, mock_search):
        mock_configs = mock.Mock(specs=['storm_cmd_path'])
        mock_configs.storm_cmd_path = None

        configs = subcommand._ensure_storm_path_in_configs(mock_configs)

        mock_search.assert_called_with()
        mock_update.assert_called_with(
            mock_configs, {'storm_cmd_path': mock_search.return_value})
        assert configs == mock_update.return_value
Пример #9
0
 def test__zip_dir(self, mock_walk):
     mock_arc = mock.Mock(autospec=True)
     mock_walk.return_value = [("foo", ["bar"], ["baz"]),
                               ("foo/bar", [], ["qux"])]
     build._zip_dir("foo", mock_arc)
     mock_walk.assert_any_call("foo")
     expected = [
         mock.call("foo/baz", "baz", zipfile.ZIP_DEFLATED),
         mock.call("foo/bar/qux", "bar/qux", zipfile.ZIP_DEFLATED),
     ]
     mock_arc.write.assert_has_calls(expected)
Пример #10
0
    def test_run_subcommand(self, mock_run, mock_vars, mock_update,
                            mock_ensure, mock_load, mock_expand):
        mock_args = mock.Mock(config_file="foo")
        mock_expand.return_value = "bar"

        self.subcmd.run_subcommand(mock_args)

        mock_expand.assert_called_once_with("foo")
        mock_load.assert_called_once_with("bar")
        mock_ensure.assert_called_once_with(mock_load.return_value)
        mock_update.assert_called_once_with(mock_ensure.return_value,
                                            mock_vars(mock_args))
        mock_run.assert_called_once_with(mock_update.return_value)
Пример #11
0
    def test_process_tuple(self):
        line = """{"a": 1, "b": 2, "c": 3}"""

        def mock_extract_fields(d):
            return d['a'], d['b'], d['c']

        expected_values = (1, 2, 3)

        mock_tup = mock.Mock(values=(line, ))

        with mock.patch.object(self.instance, 'extract_fields',
                               mock_extract_fields):
            self.instance.process_tuple(mock_tup)

        self.instance.emit.assert_called_once_with(expected_values,
                                                   anchors=[mock_tup])
Пример #12
0
    def test__remove_pyleus_base_jar_no_remove(self):
        """Do not remove the base jar if it is outside the virtualenv"""
        mock_venv_path = "/path/to/venv"

        def mock_execute_module(module, cwd):
            return "/foo/bar/outside.jar"

        mock_venv = mock.Mock(
            path=mock_venv_path,
            execute_module=mock_execute_module,
        )

        with mock.patch.object(os, 'remove') as mock_remove:
            build._remove_pyleus_base_jar(mock_venv)

        assert not mock_remove.called
Пример #13
0
    def test__remove_pyleus_base_jar(self):
        """Remove the base jar if it is inside the virtualenv"""
        mock_venv_path = "/path/to/venv"

        def mock_execute_module(module, cwd):
            return "/path/to/venv/inside.jar"

        mock_venv = mock.Mock(
            path=mock_venv_path,
            execute_module=mock_execute_module,
        )

        with mock.patch.object(os, 'remove') as mock_remove:
            build._remove_pyleus_base_jar(mock_venv)

        mock_remove.assert_called_once_with("/path/to/venv/inside.jar")
Пример #14
0
def test_list_topologies(configs):
    mock_storm_cluster = mock.Mock()

    with mock.patch.object(pyleus.cli.topologies,
                           'StormCluster',
                           return_value=mock_storm_cluster) as mock_ctr:
        list_topologies(configs)

    mock_ctr.assert_called_once_with(
        configs.storm_cmd_path,
        configs.nimbus_host,
        configs.nimbus_port,
        configs.verbose,
        configs.jvm_opts,
    )

    mock_storm_cluster.list.assert_called_once_with()
Пример #15
0
    def test__exec_bash_cmd(self, mock_popen):
        mock_proc = mock.Mock()
        mock_popen.return_value = mock_proc
        mock_proc.communicate.return_value = ["baz", "qux"]
        mock_proc.returncode = 1
        with pytest.raises(exception.VirtualenvError) as exc_info:
            virtualenv_proxy._exec_shell_cmd(
                "bash_ninja",
                stdout=42,
                stderr=666,
                err_msg="bar",
            )

        assert "bar" in str(exc_info.value)
        mock_popen.assert_called_once_with(
            "bash_ninja", stdout=42, stderr=666)
        mock_proc.communicate.assert_called_once_with()
Пример #16
0
 def test_run(self):
     mock_configs = mock.Mock()
     with pytest.raises(NotImplementedError):
         self.subcmd.run(mock_configs)
Пример #17
0
 def test_add_arguments(self):
     mock_parser = mock.Mock()
     with pytest.raises(NotImplementedError):
         self.subcmd.add_arguments(mock_parser)
Пример #18
0
 def mock_emit(self):
     self.instance.emit = mock.Mock()