Exemplo n.º 1
0
    def test_raises_if_schema_version_is_different_than_1(self):
        specification = copy.deepcopy(self.CORRECT_SPECIFICATION)
        specification["schema_version"] = 2

        with pytest.raises(ValueError) as error_info:
            plugin_from_specification(specification)

        assert str(error_info.value) == "Unknown schema version: 2"
Exemplo n.º 2
0
    def test_gives_plugin_with_descriptions_taken_from_the_specification(
            self, mocker):
        loader = mocker.create_autospec(importlib.import_module)
        plugin = plugin_from_specification(self.CORRECT_SPECIFICATION,
                                           loader=loader)

        assert plugin.description == "A purely random solver"
Exemplo n.º 3
0
    def test_gives_plugin_with_sample_args_set_to_all_names_present_in_specification_sample_args(
            self, mocker):
        loader = mocker.create_autospec(importlib.import_module)
        plugin = plugin_from_specification(self.CORRECT_SPECIFICATION,
                                           loader=loader)

        assert plugin.sample_args == ["num_reads"]
Exemplo n.º 4
0
    def test_gives_plugin_with_solver_factory_equal_to_solver_class_from_specification(
            self, mocker):
        loader = mocker.create_autospec(importlib.import_module)
        plugin = plugin_from_specification(self.CORRECT_SPECIFICATION,
                                           loader=loader)

        loader.assert_called_once_with("omnisolver.random.sampler")
        assert plugin.create_sampler == loader.return_value.RandomSampler
Exemplo n.º 5
0
    def test_gives_plugin_with_populate_parser_that_adds_all_arguments_from_specification(
            self, mocker):
        loader = mocker.create_autospec(importlib.import_module)
        parser = mocker.create_autospec(argparse.ArgumentParser)
        plugin = plugin_from_specification(self.CORRECT_SPECIFICATION,
                                           loader=loader)

        plugin.populate_parser(parser)

        parser.add_argument.assert_has_calls(
            [
                mocker.call(
                    "--prob",
                    help="probability of choosing 1 (default 0.5)",
                    type=float,
                    default=0.5,
                ),
                mocker.call("--num_reads",
                            help="number of samples to draw",
                            type=int,
                            default=1),
            ],
            any_order=False,
        )
Exemplo n.º 6
0
def get_plugin() -> Plugin:
    """Get package name and resource path."""
    specification = safe_load(
        resource_stream("omnisolver.random", "random.yml"))
    return plugin_from_specification(specification)
Exemplo n.º 7
0
    def test_gives_plugin_with_name_taken_from_specification(self, mocker):
        loader = mocker.create_autospec(importlib.import_module)
        plugin = plugin_from_specification(self.CORRECT_SPECIFICATION,
                                           loader=loader)

        assert plugin.name == "random"