Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse_benchmark_definition(self, content):
with tempfile.NamedTemporaryFile(
prefix="BenchExec_test_benchmark_definition_", suffix=".xml", mode="w+"
) as temp:
temp.write(content)
temp.flush()
# Because we mocked everything that accesses the file system,
# we can parse the benchmark definition although task files do not exist.
return Benchmark(temp.name, DummyConfig, util.read_local_time())
def test_read_local_time(self):
"""Test on Python 3.6+ that the fallback for older Pythons does the same."""
try:
time = datetime.datetime.now().astimezone() # desired code
except (ValueError, TypeError):
self.skipTest("datetime.datetime.now().astimezone() not supported")
time2 = util.read_local_time() # contains backwards-compatible code
self.assertLess(time2 - time, datetime.timedelta(seconds=1))
def test_starttime(self):
if not os.path.exists("/bin/echo"):
self.skipTest("missing /bin/echo")
before = util.read_local_time()
(result, _) = self.execute_run("/bin/echo")
after = util.read_local_time()
self.check_result_keys(result)
run_starttime = result["starttime"]
self.assertIsNotNone(run_starttime.tzinfo, "start time is not a local time")
self.assertLessEqual(before, run_starttime)
self.assertLessEqual(run_starttime, after)
def execute_benchmark(self, benchmark_file):
"""
Execute a single benchmark as defined in a file.
If called directly, ensure that config and executor attributes are set up.
@param benchmark_file: the name of a benchmark-definition XML file
@return: a result value from the executor module
"""
benchmark = Benchmark(
benchmark_file,
self.config,
self.config.start_time or util.read_local_time(),
)
self.check_existing_results(benchmark)
self.executor.init(self.config, benchmark)
output_handler = OutputHandler(
benchmark, self.executor.get_system_info(), self.config.compress_results
)
logging.debug(
"I'm benchmarking %r consisting of %s run sets using %s %s.",
benchmark_file,
len(benchmark.run_sets),
benchmark.tool_name,
benchmark.tool_version or "(unknown version)",
)
def preParent():
"""Setup that is executed in the parent process immediately before the actual tool is started."""
# start measurements
if self._energy_measurement is not None and packages:
self._energy_measurement.start()
starttime = util.read_local_time()
walltime_before = time.monotonic()
return starttime, walltime_before