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 460 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 463 of file Checks.py.

463 def __init__(self, setup: TestSetup, name: str, quantity: str, unit: str, field: int, threshold: float):
464 super().__init__(setup)
465 self.name = name
466 self.quantity = quantity
467 self.unit = unit
468 self.field = field
469 self.threshold = threshold
470

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 471 of file Checks.py.

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

Member Data Documentation

◆ field

python.Checks.SimpleCheck.field = field

Definition at line 468 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 465 of file Checks.py.

◆ quantity

python.Checks.SimpleCheck.quantity = quantity

Definition at line 466 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 469 of file Checks.py.

◆ unit

python.Checks.SimpleCheck.unit = unit

Definition at line 467 of file Checks.py.


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