Engine for LaTeX songbooks http://www.patacrep.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

21 lines
834 B

"""Dynamic creation of test methods."""
class DynamicTest(type):
"""Metaclass that creates on-the-fly test methods.
Each class implementing this metaclass must define two class methods:
- `_iter_testmethods`, which iterate over `(methodname, args)`, where
`methodname` is the name of a test method to create, and `args` is a list
of arguments to pass to `_create_test`;
- `_create_test`, a method returning a test method.
"""
def __init__(cls, name, bases, nmspc):
super().__init__(name, bases, nmspc)
for methodname, testmethod in cls._iter_testmethods(): #pylint: disable=no-value-for-parameter
setattr(cls, methodname, testmethod)
def _iter_testmethods(cls):
"""Iterate over dynamically generated test methods."""
raise NotImplementedError()