Skip to content

Commit 0b4631f

Browse files
authored
Merge pull request #127 from NNPDF/move-regression-test
Move regression test
2 parents baecb98 + 52096a6 commit 0b4631f

File tree

11 files changed

+42
-26
lines changed

11 files changed

+42
-26
lines changed

benchmarks/bench_configs.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import pineko
44

55

6-
def benchmark_detect(test_files):
7-
with pytest.raises(FileNotFoundError):
8-
pineko.configs.detect()
6+
def benchmark_detect(test_files, tmp_path, cd):
7+
with cd(tmp_path):
8+
with pytest.raises(FileNotFoundError):
9+
pineko.configs.detect()
910
conf_file = pineko.configs.detect(test_files)
11+
assert conf_file is not None
1012

1113

1214
def benchmark_load(test_files):
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
2-
Suite of tests that go through the entire process of creating a new fktable
3-
from a empty folder.
2+
Suite of tests that go through the entire process of creating a new fktable
3+
from a empty folder.
44
5-
The target theory is 400 and the relevant `.toml`, theory runcard and eko template
6-
are downloaded from https://github.com/NNPDF/theories during this test so this tests
7-
has the double effect of ensuring compatibility between both repositories.
5+
The target theory is 400 and the relevant `.toml`, theory runcard and eko template
6+
are downloaded from https://github.com/NNPDF/theories during this test so this tests
7+
has the double effect of ensuring compatibility between both repositories.
88
"""
99
import itertools
1010
from pathlib import Path
@@ -82,7 +82,7 @@ def _trim_template(template_card, take_points=10):
8282

8383

8484
@pytest.mark.parametrize("dataset", ["LHCBWZMU8TEV", "INTEGXT3"])
85-
def test_regression(tmp_path, dataset):
85+
def benchmark_regression(tmp_path, dataset):
8686
"""Run pineko through subprocess to ensure that the shell scripts are working exactly
8787
as intended.
8888

benchmarks/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import pathlib
23
import shutil
34
from contextlib import contextmanager
@@ -49,3 +50,18 @@ def wrapped(newdir):
4950
lhapdf.setPaths(paths)
5051

5152
return wrapped
53+
54+
55+
@pytest.fixture
56+
def cd():
57+
# thanks https://stackoverflow.com/a/24176022/8653979
58+
@contextmanager
59+
def wrapped(newdir):
60+
prevdir = os.getcwd()
61+
os.chdir(os.path.expanduser(newdir))
62+
try:
63+
yield
64+
finally:
65+
os.chdir(prevdir)
66+
67+
return wrapped
File renamed without changes.

src/pineko/cli/gen_sv.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import pathlib
44

55
import click
6-
import pineappl
76
import rich
87

98
from .. import scale_variations

src/pineko/cli/kfactor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import pathlib
44

55
import click
6-
import rich
76

87
from .. import kfactor
98
from ._base import command

src/pineko/comparator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def compare(pine, fktable, max_as, max_al, pdf, xir, xif):
3030
df : pd.DataFrame
3131
comparison table
3232
"""
33-
import lhapdf # pylint: disable=import-error
33+
import lhapdf # pylint: disable=import-error,import-outside-toplevel
3434

3535
pdfset = lhapdf.mkPDF(pdf, 0)
3636
pdgid = int(pdfset.set().get_entry("Particle"))

src/pineko/kfactor.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ def do_it(
308308
(first_nonzero_order[0] + max_as_test, min_al, 0, 0), grid_orders_filtered
309309
)
310310
if is_in and not order_exists:
311-
rich.print(f"[green] Success: Requested order already in the grid.")
311+
rich.print("[green] Success: Requested order already in the grid.")
312312
return
313-
elif not is_in and order_exists:
314-
rich.print(f"[red] Abort: order exists is True but order not in the grid.")
313+
if not is_in and order_exists:
314+
rich.print("[red] Abort: order exists is True but order not in the grid.")
315315
return
316316
construct_and_merge_grids(
317317
grid_path,
@@ -329,19 +329,19 @@ def filter_k_factors(pigrid, centrals_kfactor):
329329
"""Filter the centrals k-factors according to their lenght compared to the number of bins of the grid."""
330330
centrals_kfactor_filtered = np.array([])
331331
if pigrid.bins() == len(centrals_kfactor):
332-
rich.print(f"[orange] The number of bins match the lenght of the k-factor.")
332+
rich.print("[orange] The number of bins match the lenght of the k-factor.")
333333
centrals_kfactor_filtered = centrals_kfactor
334334
elif pigrid.bins() < len(centrals_kfactor):
335335
rich.print(
336-
f"[yellow] The number of bins is less than the lenght of the k-factor."
336+
"[yellow] The number of bins is less than the lenght of the k-factor."
337337
)
338338
if not all(elem == centrals_kfactor[0] for elem in centrals_kfactor):
339339
# This case is actually wrong.
340340
raise ValueError("KFactor contains too many different values.")
341341
centrals_kfactor_filtered = centrals_kfactor
342342
else:
343343
rich.print(
344-
f"[yellow] The number of bins is more than the lenght of the k-factor."
344+
"[yellow] The number of bins is more than the lenght of the k-factor."
345345
)
346346

347347
# This is the last case in which grid.bins() > len(centrals_kfactor)
@@ -388,7 +388,7 @@ def compute_k_factor_grid(
388388
target_folder: pathlib.Path
389389
path where store the new grid (optional)
390390
"""
391-
import lhapdf # pylint: disable=import-error
391+
import lhapdf # pylint: disable=import-error,import-outside-toplevel
392392

393393
# With respect to the usual convention here max_as is max_as-1
394394
max_as_test = max_as - 1

src/pineko/scale_variations.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import numpy as np
77
import pineappl
8-
import rich
98
from eko import beta
109

1110
from . import check
@@ -18,12 +17,12 @@
1817
class ReturnState(Enum):
1918
"""Auxiliary class to list the possible return states."""
2019

21-
ALREADY_THERE = f"[green]Renormalization scale variations are already in the grid"
20+
ALREADY_THERE = "[green]Renormalization scale variations are already in the grid"
2221
ORDER_EXISTS_FAILURE = (
2322
"Order_exists is True but the order does not appear to be in the grid"
2423
)
2524
MISSING_CENTRAL = "Central order is not high enough to compute requested sv orders"
26-
SUCCESS = f"[green]Success: scale variation orders included!"
25+
SUCCESS = "[green]Success: scale variation orders included!"
2726

2827

2928
def qcd(order: OrderTuple) -> int:
@@ -168,7 +167,7 @@ def write_grids(gridpath, grid_list):
168167

169168

170169
def merge_grids(
171-
gridpath, grid_list_path, target_path=None, nec_orders={}, order_exists=False
170+
gridpath, grid_list_path, target_path=None, nec_orders=None, order_exists=False
172171
):
173172
"""Merge the single grids in the original."""
174173
grid = pineappl.grid.Grid.read(gridpath)
@@ -177,7 +176,9 @@ def merge_grids(
177176
else:
178177
target_path = target_path / gridpath.name
179178
if order_exists:
180-
grid = construct_and_dump_order_exists_grid(grid, list(nec_orders.keys())[0])
179+
grid = construct_and_dump_order_exists_grid(
180+
grid, list(nec_orders.keys())[0] if nec_orders is not None else []
181+
)
181182
for grid_path in grid_list_path:
182183
grid.merge_from_file(grid_path)
183184
grid_path.unlink()

0 commit comments

Comments
 (0)