Source code for schrodinger.test.performance.api
"""
Base class for performance tests. Stores build_id and buildtype, automatically
reports when complete
"""
import unittest
from typing import Optional
from schrodinger.test.performance import reporter
[docs]class PerformanceTest:
"""
Pytest test class that reports results during tear down class. Note that
the class name must start with "Test" to be picked up. This class must be
used instead of `PerformanceTestClass` when using pytest features that
aren't supported in TestCase subclasses, such as parametrization.
"""
# Subclasses must define these:
NAME = None
PRODUCT = None
DESCRIPTION = None
# The test loader sets these. They are used in reporting
build_id = None
buildtype = None
report = None
[docs] @classmethod
def setup_class(cls):
if not all((cls.NAME, cls.PRODUCT, cls.DESCRIPTION)):
msg = ("NAME, PRODUCT, and DESCRIPTION are required for "
"ReporterTestCase subclasses.")
raise NotImplementedError(msg)
if cls.report:
cls.reporter = reporter.create_performance_test_reporter(
name=cls.NAME,
product=cls.PRODUCT,
description=cls.DESCRIPTION,
scival=False,
upload=True)
[docs] def addResult(self, name: str, value: float, units: Optional[str] = None):
"""
Log a result to be reported to the performance database.
"""
if self.report:
return self.reporter.addResult(name, value, units)
elif units is not None:
print(f" Would have recorded {name}: {value} {units}")
else:
print(f" Would have recorded {name}: {value}")
[docs] @classmethod
def teardown_class(cls):
"""Report all results to the performance database."""
if cls.report:
cls.reporter.report(build_id=cls.build_id, buildtype=cls.buildtype)
[docs]class PerformanceTestCase(PerformanceTest, unittest.TestCase):
"""Unittest TestCase that reports results during tearDownClass"""
# This class intentionally left blank