def meta(self, config="", extra_prepare=None):
        with hp.a_temp_file() as fle:
            fle.write(dedent(config).encode())
            fle.close()

            original = Collector.extra_prepare_after_activation

            class Prepare:
                def __enter__(s):
                    if extra_prepare:

                        def extra(*args, **kwargs):
                            extra_prepare(*args, **kwargs)
                            return original(*args, **kwargs)

                        s.patch = mock.patch.object(
                            Collector, "extra_prepare_after_activation", extra
                        )
                        s.patch.start()

                def __exit__(s, exc_type, exc, tb):
                    if hasattr(s, "patch"):
                        s.patch.stop()

            with Prepare(), open(fle.name) as realfile:
                args_dict = {"photons_app": {"config": realfile}}

                app = App()
                logging_handler = mock.Mock(name="logging_handler")
                collector = app.setup_collector(args_dict, logging_handler, None)
                return Meta({"collector": collector}, [])
Exemple #2
0
        def from_config(self, config):
            with hp.a_temp_file() as fle:
                fle.write(dedent(config).encode())
                fle.close()

                with open(fle.name) as realfile:
                    args_dict = {"photons_app": {"config": realfile}}

                    app = App()
                    logging_handler = mock.Mock(name="logging_handler")
                    collector = app.setup_collector(args_dict, logging_handler, None)
                return fle.name, args_dict, logging_handler, collector
Exemple #3
0
        def run_with(self, argv):
            original_mainline = mock.Mock(name="original_mainline")

            with mock.patch.object(DelfickApp, "mainline", original_mainline):
                App().mainline(argv)

            original_mainline.assert_called_once_with(mock.ANY, mock.ANY)
            call_list = original_mainline.mock_calls[0].call_list()[0][1]
            return call_list[0]
Exemple #4
0
    def run(self):
        app = App()
        cli_parser = app.make_cli_parser()
        _, _, defaults = cli_parser.split_args([])
        parser = cli_parser.make_parser(defaults)

        template = [".. code-block:: text", ""]
        for line in parser.format_help().split("\n"):
            template.append("    {0}".format(line))

        source = self.state_machine.input_lines.source(
            self.lineno - self.state_machine.input_offset - 1)
        tab_width = self.options.get('tab-width',
                                     self.state.document.settings.tab_width)
        lines = statemachine.string2lines('\n'.join(template),
                                          tab_width,
                                          convert_whitespace=True)
        self.state_machine.insert_input(lines, source)
        return []