Beispiel #1
0
    def test_options_accessors(self):
        """Check that all plot config options have accessors."""
        config = PlotConfig.from_kwargs(view=False)

        for name, option in PlotConfig._option_decls.items():
            self.assertTrue(
                hasattr(PlotConfig, name),
                f"Plot config is missing an accessor for the option '{name}'")

            accessor_fn = config.__getattribute__(name)
            signature = inspect.signature(accessor_fn)

            self.assertFalse(
                option.view_default
                and "view_default" not in signature.parameters,
                f"Plot config option {name} has view_default set but "
                f"accessor does not allow overriding. Either remove "
                f"view_default or use PCOGetterV for the accessor.")
            self.assertFalse(
                not option.view_default
                and "view_default" in signature.parameters,
                f"Plot config option {name} has no view_default set but "
                f"accessor allows overriding view_default. Either add a "
                f"view_default to the option or use PCOGetter for the "
                f"accessor.")
Beispiel #2
0
    def test_get_dict(self):
        """Check that dict only contains options with set values."""
        config = PlotConfig.from_kwargs(view=False, label_size=1)
        config_dict = config.get_dict()
        self.assertIn("label_size", config_dict)
        self.assertEqual(1, config_dict["label_size"])

        self.assertNotIn("x_tick_size", config_dict)
Beispiel #3
0
def main(context: click.Context, **kwargs: tp.Any) -> None:
    """Entry point for the plot generation tool."""
    # store common options in context so they can be passed to subcommands
    common_options = CommonPlotOptions.from_kwargs(**kwargs)
    plot_config = PlotConfig.from_kwargs(**kwargs)
    context.ensure_object(dict)
    context.obj["common_options"] = common_options
    context.obj["plot_config"] = plot_config
    context.obj["save_artefact"] = kwargs["save_artefact"]

    initialize_cli_tool()
    initialize_projects()
    initialize_tables()
    initialize_plots()
Beispiel #4
0
    def test_cli_option_converter(self):
        """Test whether CLI option conversion works correctly."""
        # setup config
        vara_cfg()['paper_config']['current_config'] = "test_artefacts_driver"
        load_paper_config()
        save_config()

        plot_generator = CaseStudyOverviewGenerator(
            PlotConfig.from_kwargs(view=False),
            report_type=EmptyReport,
            case_study=get_loaded_paper_config().get_case_studies("xz")[0])
        artefact = PlotArtefact.from_generator("CS Overview", plot_generator,
                                               CommonPlotOptions.from_kwargs())
        artefact_dict = artefact.get_dict()
        self.assertEqual("xz_0", artefact_dict["case_study"])
        self.assertEqual("EmptyReport", artefact_dict["report_type"])
Beispiel #5
0
 def test_view_default_override(self):
     """Test if passed view_default is used over default in view mode."""
     config = PlotConfig.from_kwargs(view=True)
     self.assertEqual(5, config.height(default=4, view_default=5))
Beispiel #6
0
 def test_no_view_default_override(self):
     """Test if passed default is used over view_default in non-view mode."""
     config = PlotConfig.from_kwargs(view=False)
     self.assertEqual(4, config.height(default=4, view_default=5))
Beispiel #7
0
 def test_view_get_option_value_set_no_override(self):
     """Test if passed default does not override set value in view mode."""
     config = PlotConfig.from_kwargs(view=True, height=42)
     self.assertEqual(42, config.height(view_default=5))
Beispiel #8
0
 def test_view_get_option_value_not_set_override(self):
     """Test if passed default overrides global default in view mode."""
     config = PlotConfig.from_kwargs(view=True, show_legend=True)
     self.assertEqual(42, config.legend_size(view_default=42))
Beispiel #9
0
 def test_view_get_option_value_set(self):
     """Test if a set value overrides the default value in view mode."""
     config = PlotConfig.from_kwargs(view=True, fig_title="Test", width=1)
     self.assertEqual("Test", config.fig_title())
     self.assertEqual(1, config.width())
     self.assertEqual(1000, config.height())
Beispiel #10
0
 def test_view_get_option_value_not_set(self):
     """Test if default value is returned in view mode."""
     config = PlotConfig.from_kwargs(view=True)
     self.assertEqual(10, config.font_size())
Beispiel #11
0
 def test_get_option_value_set(self):
     """Test if a set value overrides the default value."""
     config = PlotConfig.from_kwargs(view=False, fig_title="Test")
     self.assertEqual("Test", config.fig_title())
     self.assertEqual(1500, config.width())