Skip to content

Unit test template #21

@vroulet

Description

@vroulet

Hello!

Thanks for developping benchopt!

Would it be possible to add a unit test in the template?
Why:

  • ease debugging base functions (typically this would ease interactive debugging),
  • give a good idea of the flow directly in the template.

For example one could add a file 'test_pipeline.py' with something like.

from datasets.simulated import Dataset
from objective import Objective
from solvers.python-gd import Solver

# This test requires having installed the dependencies before
def test_pipeline():
    # We add manually attributes of dataset, objective, solver for the test

    dataset = Dataset()
    dataset.n_samples = 1000
    dataset.n_features = 500
    dataset.random_state = 27
    dataset_params = dataset.get_data()

    objective = Objective()
    objective.whiten_y = True
    objective.set_data(**dataset_params)
    objective_params = objective.get_objective()

    solver = Solver()
    solver.scale_step = 1.
    solver.set_objective(**objective_params)
    solver.run(n_iter=10)
    results = solver.get_result()

    metrics = objective.compute(*results)
    assert 'value' in metrics.keys()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions