Commit e48f13bf authored by Philipp Gadow's avatar Philipp Gadow
Browse files

more changes to integration test

parent e7fe9ab4
......@@ -30,3 +30,4 @@ isort==5.8.0
flake8==3.9.2
black==21.5b1
pre-commit==2.12.1
pytest-order==0.11.0
......@@ -19,8 +19,8 @@ test_umami:
preprocessing_config: 'examples/PFlow-Preprocessing.yaml'
plotting_config: 'examples/plotting_umami_config_Umami.yaml'
testdir: '/tmp/umami/umami'
files:
- PFlow-hybrid_70-test-preprocessed_shuffled.h5
- PFlow-scale_dict.json
- MC16d_hybrid_odd_100_PFlow-no_pTcuts-file_0.h5
- MC16d_hybrid-ext_odd_0_PFlow-no_pTcuts-file_0.h5
# files:
# - PFlow-hybrid_70-test-preprocessed_shuffled.h5
# - PFlow-scale_dict.json
# - MC16d_hybrid_odd_100_PFlow-no_pTcuts-file_0.h5
# - MC16d_hybrid-ext_odd_0_PFlow-no_pTcuts-file_0.h5
import logging
import os
import unittest
from subprocess import CalledProcessError, run
import yaml
......@@ -112,11 +113,17 @@ class TestPreprocessing(unittest.TestCase):
self.data = getConfiguration()
test_dir = os.path.join(self.data["test_preprocessing"]["testdir"])
test_dir_dl1r = os.path.join(self.data["test_preprocessing"]["testdir"])
test_dir_dips = os.path.join(self.data["test_preprocessing"]["testdir"])
test_dir_umami = os.path.join(self.data["test_preprocessing"]["testdir"])
logging.info(f"Creating test directory in {test_dir}")
# clean up, hopefully this causes no "uh oh...""
if test_dir.startswith("/tmp"):
run(["rm", "-rf", test_dir])
run(["mkdir", "-p", test_dir])
run(["mkdir", "-p", test_dir_dl1r])
run(["mkdir", "-p", test_dir_dips])
run(["mkdir", "-p", test_dir_umami])
# inputs for test will be located in test_dir
config_source = os.path.join(
......@@ -135,14 +142,20 @@ class TestPreprocessing(unittest.TestCase):
self.var_dict_dl1r = os.path.join(
test_dir, os.path.basename(var_dict_dl1r_source)
)
self.scale_dict_dl1r = os.path.join(test_dir_dl1r, "PFlow-scale_dict.json")
self.output_dl1r = os.path.join(test_dir_dl1r, "PFlow-hybrid_70-test.h5")
self.var_dict_dips = os.path.join(
test_dir, os.path.basename(var_dict_dips_source)
)
self.scale_dict_dips = os.path.join(test_dir_dips, "PFlow-scale_dict.json")
self.output_dips = os.path.join(test_dir_dips, "PFlow-hybrid_70-test.h5")
self.var_dict_umami = os.path.join(
test_dir, os.path.basename(var_dict_umami_source)
)
self.scale_dict = os.path.join(test_dir, "PFlow-scale_dict.json")
self.output = os.path.join(test_dir, "PFlow-hybrid_70-test.h5")
self.scale_dict_umami = os.path.join(test_dir_umami, "PFlow-scale_dict.json")
self.output_umami = os.path.join(test_dir_umami, "PFlow-hybrid_70-test.h5")
logging.info(
f"Preparing config file based on {config_source} in {self.config}..."
......
import logging
import os
import unittest
import pytest
from subprocess import CalledProcessError, run
import yaml
from umami.tools import replaceLineInFile, replaceFirstLineInFile, yaml_loader
from umami.tools import replaceLineInFile, yaml_loader
def getConfiguration():
......@@ -153,30 +154,33 @@ class TestUmami(unittest.TestCase):
self.config, "var_dict:", f"var_dict: {self.var_dict_umami}"
)
replaceLineInFile(self.config, "batch_size:", " batch_size: 10")
replaceFirstLineInFile(
self.config, "train_file:", f"train_file: {self.train_file}"
replaceLineInFile(
self.config, "train_file:", f"train_file: {self.train_file}", onlyFirstOccurence=True
)
replaceFirstLineInFile(
self.config, "validation_file:", f"validation_file: {self.test_file_ttbar}"
replaceLineInFile(
self.config, "validation_file:", f"validation_file: {self.test_file_ttbar}", onlyFirstOccurence=True
)
replaceFirstLineInFile(
self.config, "add_validation_file:", f"add_validation_file: {self.test_file_zprime}"
replaceLineInFile(
self.config, "add_validation_file:", f"add_validation_file: {self.test_file_zprime}", onlyFirstOccurence=True
)
replaceFirstLineInFile(
self.config, "test_file:", f"test_file: {self.test_file_ttbar}"
replaceLineInFile(
self.config, "test_file:", f"test_file: {self.test_file_ttbar}", onlyFirstOccurence=True
)
replaceFirstLineInFile(
self.config, "add_test_file:", f"add_test_file: {self.test_file_zprime}"
replaceLineInFile(
self.config, "add_test_file:", f"add_test_file: {self.test_file_zprime}", onlyFirstOccurence=True
)
# evaluation parameters
replaceFirstLineInFile(
self.config, "n_jets:", " n_jets: 2500"
replaceLineInFile(
self.config, "n_jets:", " n_jets: 2500", onlyFirstOccurence=True
)
replaceFirstLineInFile(
self.config, "fc_value:", " fc_value: 0.018"
replaceLineInFile(
self.config, "fc_value:", " fc_value: 0.018", onlyFirstOccurence=True
)
replaceFirstLineInFile(
self.config, "WP_b:", " WP_b: 0.77"
replaceLineInFile(
self.config, "WP_b:", " WP_b: 0.77", onlyFirstOccurence=True
)
replaceLineInFile(
self.config, "Path:", f" Path: {self.test_file_ttbar}"
)
logging.info("Downloading test data...")
......@@ -189,6 +193,7 @@ class TestUmami(unittest.TestCase):
logging.info(f"Retrieving file from path {path}")
run(["wget", path, "--directory-prefix", test_dir])
@pytest.mark.order(after="test_preprocessing_umami")
def test_umami(self):
"""Integration test of train_umami.py script."""
self.assertTrue(
......
# flake8: noqa
from umami.tools.PyATLASstyle.PyATLASstyle import applyATLASstyle, makeATLAStag
from umami.tools.tools import replaceLineInFile, replaceFirstLineInFile, yaml_loader
from umami.tools.tools import replaceLineInFile, yaml_loader
......@@ -21,24 +21,12 @@ yaml_loader.add_implicit_resolver(
)
def replaceLineInFile(file, key, newLine):
filedata = ""
with open(file, "r") as f:
for line in f:
if key in line:
line = newLine + "\n"
filedata += line
with open(file, "w") as f:
f.write(filedata)
def replaceFirstLineInFile(file, key, newLine):
def replaceLineInFile(file, key, newLine, onlyFirstOccurence=False):
filedata = ""
replacedLine = False
with open(file, "r") as f:
for line in f:
if key in line and not replacedLine:
if key in line and not (onlyFirstOccurence and replacedLine):
line = newLine + "\n"
replacedLine = True
filedata += line
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment