ATLAS Offline Software
Loading...
Searching...
No Matches
python.Checks.SimpleCheck Class Reference
Inheritance diagram for python.Checks.SimpleCheck:
Collaboration diagram for python.Checks.SimpleCheck:

Public Member Functions

 __init__ (self, TestSetup setup, str name, str quantity, str unit, int field, float threshold)
bool run (self, WorkflowTest test)
Optional[Path] reference_file (self, "WorkflowTest" test, str file_name)

Public Attributes

 name = name
 quantity = quantity
 unit = unit
 field = field
 threshold = threshold
 setup = setup
 logger = setup.logger

Detailed Description

Run A Very Simple Check.

Definition at line 454 of file Checks.py.

Constructor & Destructor Documentation

◆ __init__()

python.Checks.SimpleCheck.__init__ ( self,
TestSetup setup,
str name,
str quantity,
str unit,
int field,
float threshold )

Definition at line 457 of file Checks.py.

457 def __init__(self, setup: TestSetup, name: str, quantity: str, unit: str, field: int, threshold: float):
458 super().__init__(setup)
459 self.name = name
460 self.quantity = quantity
461 self.unit = unit
462 self.field = field
463 self.threshold = threshold
464

Member Function Documentation

◆ reference_file()

Optional[Path] python.Test.WorkflowCheck.reference_file ( self,
"WorkflowTest" test,
str file_name )
inherited

Definition at line 93 of file Tools/WorkflowTestRunner/python/Test.py.

93 def reference_file(self, test: "WorkflowTest", file_name: str) -> Optional[Path]:
94 reference_path: Path = test.reference_path
95 reference_file = reference_path / file_name
96
97 # Read references from CVMFS
98 if self.setup.validation_only:
99 # Resolve the subfolder first. Results are stored like: main_folder/branch/test/version/.
100 reference_revision = references_map[f"{test.ID}"]
101 cvmfs_path = Path(references_CVMFS_path)
102 rel_path = Path(self.setup.release_ID) / test.ID / reference_revision
103 reference_path = cvmfs_path / rel_path
104 reference_file = reference_path / file_name
105
106 if not reference_path.exists():
107 self.logger.error(f"CVMFS reference location {reference_path} does not exist!")
108 return None
109
110 if references_override_url is not None:
111 import requests
112
113 url = references_override_url
114 if not url.endswith("/"): url += "/"
115 url += str(rel_path / file_name)
116 self.logger.info("Checking for reference override at %s", url)
117 if requests.head(url).ok: # file exists at url
118 reference_file = Path.cwd() / f"reference_{file_name}"
119 self.logger.info("Downloading reference from %s to %s", url, reference_file)
120 r = requests.get(url, stream=True)
121 with reference_file.open('wb') as f:
122 for chunk in r.iter_content(chunk_size=1024):
123 if chunk: # filter out keep-alive new chunks
124 f.write(chunk)
125 else:
126 self.logger.info("No reference override found")
127
128 return reference_file
129
130

◆ run()

bool python.Checks.SimpleCheck.run ( self,
WorkflowTest test )

Definition at line 465 of file Checks.py.

465 def run(self, test: WorkflowTest) -> bool:
466 self.logger.info("-----------------------------------------------------")
467 self.logger.info(f"Running {test.ID} {self.name} Check")
468
469 result = True
470 for step in test.steps:
471 log_name = f"log.{step}"
472 reference_log = test.reference_path / log_name
473 validation_log = test.validation_path / log_name
474
475 reference_value = 0
476 with reference_log.open() as file:
477 found = False
478 for line in file:
479 if self.quantity in line:
480 reference_value = float(line.split()[self.field])
481 found = True
482 break
483 if not found:
484 self.logger.error(f"No data available in {reference_log}. Job failed.")
485 return False
486
487 validation_value = 0
488 with validation_log.open() as file:
489 found = False
490 for line in file:
491 if self.quantity in line:
492 validation_value = float(line.split()[self.field])
493 found = True
494 break
495 if not found:
496 self.logger.error(f"No data available in {validation_log}. Job failed.")
497 return False
498
499 if reference_value != 0:
500 factor = validation_value / reference_value
501
502 # Error if the factor increases (very bad things)
503 # Warning if the factor decreases (should be an understood feature)
504 if factor > 1. + self.threshold:
505 self.logger.error(f"{self.quantity} in the {step} step with(out) your change is {validation_value} ({reference_value}) {self.unit}")
506 self.logger.error(f"Your change changes {self.quantity} by a factor {factor}")
507 self.logger.error("Is this an expected outcome of your change(s)?")
508 result = False
509 self.logger.error(f"{step}: {self.name}")
510 self.logger.error(f"ref {reference_value} {self.unit}")
511 self.logger.error(f"val {validation_value} {self.unit}")
512 if factor < 1. - self.threshold:
513 self.logger.warning(f"{self.quantity} in the {step} step with(out) your change is {validation_value} ({reference_value}) {self.unit}")
514 self.logger.warning(f"Your change changes {self.quantity} by a factor {factor}")
515 self.logger.warning("Is this an expected outcome of your change(s)?")
516 result = True
517 self.logger.warning(f"{step}: {self.name}")
518 self.logger.warning(f"ref {reference_value} {self.unit}")
519 self.logger.warning(f"val {validation_value} {self.unit}")
520
521 if result:
522 self.logger.info("Passed!\n")
523 else :
524 self.logger.error("Failed!\n")
525
526 return result
527
528
Definition run.py:1

Member Data Documentation

◆ field

python.Checks.SimpleCheck.field = field

Definition at line 462 of file Checks.py.

◆ logger

python.Test.WorkflowCheck.logger = setup.logger
inherited

Definition at line 91 of file Tools/WorkflowTestRunner/python/Test.py.

◆ name

python.Checks.SimpleCheck.name = name

Definition at line 459 of file Checks.py.

◆ quantity

python.Checks.SimpleCheck.quantity = quantity

Definition at line 460 of file Checks.py.

◆ setup

python.Test.WorkflowCheck.setup = setup
inherited

Definition at line 90 of file Tools/WorkflowTestRunner/python/Test.py.

◆ threshold

python.Checks.SimpleCheck.threshold = threshold

Definition at line 463 of file Checks.py.

◆ unit

python.Checks.SimpleCheck.unit = unit

Definition at line 461 of file Checks.py.


The documentation for this class was generated from the following file: