qsprpred.utils package
Subpackages
- qsprpred.utils.interfaces package
- qsprpred.utils.testing package
- Submodules
- qsprpred.utils.testing.base module
QSPRTestCase
QSPRTestCase.addClassCleanup()
QSPRTestCase.addCleanup()
QSPRTestCase.addTypeEqualityFunc()
QSPRTestCase.assertAlmostEqual()
QSPRTestCase.assertCountEqual()
QSPRTestCase.assertDictEqual()
QSPRTestCase.assertEqual()
QSPRTestCase.assertFalse()
QSPRTestCase.assertGreater()
QSPRTestCase.assertGreaterEqual()
QSPRTestCase.assertIn()
QSPRTestCase.assertIs()
QSPRTestCase.assertIsInstance()
QSPRTestCase.assertIsNone()
QSPRTestCase.assertIsNot()
QSPRTestCase.assertIsNotNone()
QSPRTestCase.assertLess()
QSPRTestCase.assertLessEqual()
QSPRTestCase.assertListEqual()
QSPRTestCase.assertLogs()
QSPRTestCase.assertMultiLineEqual()
QSPRTestCase.assertNoLogs()
QSPRTestCase.assertNotAlmostEqual()
QSPRTestCase.assertNotEqual()
QSPRTestCase.assertNotIn()
QSPRTestCase.assertNotIsInstance()
QSPRTestCase.assertNotRegex()
QSPRTestCase.assertRaises()
QSPRTestCase.assertRaisesRegex()
QSPRTestCase.assertRegex()
QSPRTestCase.assertSequenceEqual()
QSPRTestCase.assertSetEqual()
QSPRTestCase.assertTrue()
QSPRTestCase.assertTupleEqual()
QSPRTestCase.assertWarns()
QSPRTestCase.assertWarnsRegex()
QSPRTestCase.countTestCases()
QSPRTestCase.debug()
QSPRTestCase.defaultTestResult()
QSPRTestCase.doClassCleanups()
QSPRTestCase.doCleanups()
QSPRTestCase.enterClassContext()
QSPRTestCase.enterContext()
QSPRTestCase.fail()
QSPRTestCase.failureException
QSPRTestCase.id()
QSPRTestCase.longMessage
QSPRTestCase.maxDiff
QSPRTestCase.run()
QSPRTestCase.setUp()
QSPRTestCase.setUpClass()
QSPRTestCase.shortDescription()
QSPRTestCase.skipTest()
QSPRTestCase.subTest()
QSPRTestCase.tearDown()
QSPRTestCase.tearDownClass()
- qsprpred.utils.testing.check_mixins module
DataPrepCheckMixIn
DescriptorCheckMixIn
DescriptorInDataCheckMixIn
ModelCheckMixIn
MonitorsCheckMixIn
MonitorsCheckMixIn.baseMonitorTest()
MonitorsCheckMixIn.checkOptimization()
MonitorsCheckMixIn.clearGenerated()
MonitorsCheckMixIn.createLargeMultitaskDataSet()
MonitorsCheckMixIn.createLargeTestDataSet()
MonitorsCheckMixIn.createSmallTestDataSet()
MonitorsCheckMixIn.createTestDataSetFromFrame()
MonitorsCheckMixIn.fileMonitorTest()
MonitorsCheckMixIn.fitTest()
MonitorsCheckMixIn.getAllDescriptors()
MonitorsCheckMixIn.getBigDF()
MonitorsCheckMixIn.getDataPrepGrid()
MonitorsCheckMixIn.getDefaultCalculatorCombo()
MonitorsCheckMixIn.getDefaultPrep()
MonitorsCheckMixIn.getParamGrid()
MonitorsCheckMixIn.getPrepCombos()
MonitorsCheckMixIn.getSmallDF()
MonitorsCheckMixIn.gridFile
MonitorsCheckMixIn.listMonitorTest()
MonitorsCheckMixIn.predictorTest()
MonitorsCheckMixIn.runMonitorTest()
MonitorsCheckMixIn.setUpPaths()
MonitorsCheckMixIn.tearDown()
MonitorsCheckMixIn.trainModelWithMonitoring()
MonitorsCheckMixIn.validate_split()
- qsprpred.utils.testing.path_mixins module
DataSetsPathMixIn
DataSetsPathMixIn.clearGenerated()
DataSetsPathMixIn.createLargeMultitaskDataSet()
DataSetsPathMixIn.createLargeTestDataSet()
DataSetsPathMixIn.createSmallTestDataSet()
DataSetsPathMixIn.createTestDataSetFromFrame()
DataSetsPathMixIn.getAllDescriptors()
DataSetsPathMixIn.getBigDF()
DataSetsPathMixIn.getDataPrepGrid()
DataSetsPathMixIn.getDefaultCalculatorCombo()
DataSetsPathMixIn.getDefaultPrep()
DataSetsPathMixIn.getPrepCombos()
DataSetsPathMixIn.getSmallDF()
DataSetsPathMixIn.setUpPaths()
DataSetsPathMixIn.tearDown()
DataSetsPathMixIn.validate_split()
ModelDataSetsPathMixIn
ModelDataSetsPathMixIn.clearGenerated()
ModelDataSetsPathMixIn.createLargeMultitaskDataSet()
ModelDataSetsPathMixIn.createLargeTestDataSet()
ModelDataSetsPathMixIn.createSmallTestDataSet()
ModelDataSetsPathMixIn.createTestDataSetFromFrame()
ModelDataSetsPathMixIn.getAllDescriptors()
ModelDataSetsPathMixIn.getBigDF()
ModelDataSetsPathMixIn.getDataPrepGrid()
ModelDataSetsPathMixIn.getDefaultCalculatorCombo()
ModelDataSetsPathMixIn.getDefaultPrep()
ModelDataSetsPathMixIn.getPrepCombos()
ModelDataSetsPathMixIn.getSmallDF()
ModelDataSetsPathMixIn.setUpPaths()
ModelDataSetsPathMixIn.tearDown()
ModelDataSetsPathMixIn.validate_split()
PathMixIn
- Module contents
Submodules
qsprpred.utils.inspect module
qsprpred.utils.parallel module
- class qsprpred.utils.parallel.JITParallelGenerator(n_workers: int | None = None, worker_type: Literal['cpu', 'gpu'] = 'cpu', use_gpus: list[int] | None = None, jobs_per_gpu: int = 1)[source]
Bases:
ParallelGenerator
,ABC
An abstract class to facilitate JIT (Just In Time) parallel processing of an arbitrary generator. This is meant for situations where the result of the generator is too large to fit into memory or not yet known. Parallelization can be done over a pool of CPU or GPU workers. The generator will yield the results of the function applied in parallel to each item of a supplied generator.
Configures the multiprocessing pool generator.
- Parameters:
n_workers (int) – Number of workers to use.
worker_type (Literal["cpu", "gpu"]) – The type of worker to use.
use_gpus (list[int] | None) – A list of GPU indices to use. Only applicable if
worker_type
is ‘gpu’. If None, all available GPUs will be used.jobs_per_gpu (int) – Number of jobs to run on each GPU.
- abstract checkProcess(process: Any)[source]
A simple check of a process or future before a result is attempted to be retrieved.
- abstract checkResultAvailable(process: Any) bool [source]
Check if the result of a process is available.
- abstract createJob(pool: Any, process_func: Callable, *args, **kwargs) Any [source]
Submit a job to the pool that applies the function to a generator item.
- Parameters:
pool (Any) – The pool object to submit the job to.
process_func (Callable) – The function to apply to the input arguments.
args (tuple) – Positional arguments to pass to the function. The first argument should be the item from the generator.
kwargs (dict) – Additional keyword arguments to pass to the function.
- Returns:
The process object or future that was submitted to the pool.
- abstract getPool() Any [source]
Create the pool of workers consuming the generator.
- Returns:
A pool object that can be used to apply the function to the generator items in parallel.
- abstract getResult(process: Any) Any [source]
Get the result of a process.
- Parameters:
process (Any) – The process object or a future to get the result from.
- Returns:
The result of the process.
- abstract handleException(process: Any, exception: Exception) Any [source]
Handle an exception raised by a process. This is executed when the process raises an unexpected exception or the
checkProcess
method raises an exception.- Parameters:
process (Any) – The process object or a future that raised the exception.
exception (Exception) – The exception raised by the process.
- Returns:
The result to yield instead of the result of the process.
- make(generator: Generator, process_func: Callable, *args, **kwargs) Generator [source]
A parallel “JIT (Just In Time)” generator that yields the results of a function applied in parallel to each item of a supplied generator. The advantage of this JIT implementation is that it only evaluates the next item in the input generator as soon as it is needed for the calculation. This means that only one item from the iterable is loaded into memory at a time.
The generator also supports timeout for each job. The “pebble” pool_type can be used to support this feature. In all other cases, the “multiprocessing” pool_type is sufficient.
- Parameters:
generator (SupportsNext) – An iterable object to apply the function to.
process_func (Callable) – The function to apply to each item in the iterable.
args (tuple | None) – Additional positional arguments to pass to the function.
kwargs (dict | None) – Additional keyword arguments to pass to the function.
- Returns:
A generator that yields the results of the function applied to each item in the iterable. If a timeout is specified, a
TimeoutError
will be returned instead.
- class qsprpred.utils.parallel.MultiprocessingJITGenerator(n_workers: int | None = None, worker_type: Literal['cpu', 'gpu'] = 'cpu', use_gpus: list[int] | None = None, jobs_per_gpu: int = 1)[source]
Bases:
JITParallelGenerator
A parallel generator that uses the
multiprocessing
module to parallelize the processing of an input generator. This is useful when the input generator is too large to fit into memory and needs to be processed in parallel over a pool of workers.Configures the multiprocessing pool generator.
- Parameters:
n_workers (int) – Number of workers to use.
worker_type (Literal["cpu", "gpu"]) – The type of worker to use.
use_gpus (list[int] | None) – A list of GPU indices to use. Only applicable if
worker_type
is ‘gpu’. If None, all available GPUs will be used.jobs_per_gpu (int) – Number of jobs to run on each GPU.
- checkProcess(process)[source]
A simple check of a process or future before a result is attempted to be retrieved.
- createJob(pool, process_func, *args, **kwargs)[source]
Submit a job to the pool that applies the function to a generator item.
- Parameters:
pool (Any) – The pool object to submit the job to.
process_func (Callable) – The function to apply to the input arguments.
args (tuple) – Positional arguments to pass to the function. The first argument should be the item from the generator.
kwargs (dict) – Additional keyword arguments to pass to the function.
- Returns:
The process object or future that was submitted to the pool.
- getPool()[source]
Create the pool of workers consuming the generator.
- Returns:
A pool object that can be used to apply the function to the generator items in parallel.
- getResult(process)[source]
Get the result of a process.
- Parameters:
process (Any) – The process object or a future to get the result from.
- Returns:
The result of the process.
- handleException(process, exception)[source]
Handle an exception raised by a process. This is executed when the process raises an unexpected exception or the
checkProcess
method raises an exception.- Parameters:
process (Any) – The process object or a future that raised the exception.
exception (Exception) – The exception raised by the process.
- Returns:
The result to yield instead of the result of the process.
- make(generator: Generator, process_func: Callable, *args, **kwargs) Generator
A parallel “JIT (Just In Time)” generator that yields the results of a function applied in parallel to each item of a supplied generator. The advantage of this JIT implementation is that it only evaluates the next item in the input generator as soon as it is needed for the calculation. This means that only one item from the iterable is loaded into memory at a time.
The generator also supports timeout for each job. The “pebble” pool_type can be used to support this feature. In all other cases, the “multiprocessing” pool_type is sufficient.
- Parameters:
generator (SupportsNext) – An iterable object to apply the function to.
process_func (Callable) – The function to apply to each item in the iterable.
args (tuple | None) – Additional positional arguments to pass to the function.
kwargs (dict | None) – Additional keyword arguments to pass to the function.
- Returns:
A generator that yields the results of the function applied to each item in the iterable. If a timeout is specified, a
TimeoutError
will be returned instead.
- class qsprpred.utils.parallel.ParallelGenerator[source]
Bases:
ABC
An abstract class to facilitate parallel processing of an arbitrary generator.
- abstract make(generator: Generator, process_func: Callable, *args, **kwargs) Generator [source]
This method is used to wrap an input generator or an iterable (needs to support
next()
). The method should evaluate one item of the generator at a time and apply theprocess_func
to it. This is done in parallel over a pool of workers. The method should return a generator that yields the results of the function applied in parallel as soon as the results are available. Therefore, the user can simply iterate over the generator to get the results.- Parameters:
generator – An iterable object to apply the function to.
process_func – The function to apply to each item in the iterable.
- Returns:
A generator that yields the results of the function applied to each item in the iterable in parallel.
- class qsprpred.utils.parallel.PebbleJITGenerator(n_workers: int | None = None, worker_type: Literal['cpu', 'gpu'] = 'cpu', use_gpus: list[int] | None = None, jobs_per_gpu: int = 1, timeout: int | None = None)[source]
Bases:
JITParallelGenerator
Uses the
pebble
library to parallelize the processing of an input generator. The main benefit of usingpebble
is that it supports timeouts for each job, which makes it easy to handle jobs that take too long to process.Configures the multiprocessing pool generator.
- Parameters:
n_workers (int) – Number of workers to use.
worker_type (Literal["cpu", "gpu"]) – The type of worker to use.
use_gpus (list[int] | None) – A list of GPU indices to use. Only applicable if
worker_type
is ‘gpu’. If None, all available GPUs will be used.jobs_per_gpu (int) – Number of jobs to run on each GPU.
timeout (int | None) – A timeout threshold in seconds. Processes that exceed this threshold will be terminated and a
TimeoutError
will be returned.
- checkProcess(process: Any)[source]
A simple check of a process or future before a result is attempted to be retrieved.
- checkResultAvailable(process: ProcessFuture)[source]
Check if the result of a process is available.
- createJob(pool: Any, process_func: Callable, *args, **kwargs) Any [source]
Submit a job to the pool that applies the function to a generator item.
- Parameters:
pool (Any) – The pool object to submit the job to.
process_func (Callable) – The function to apply to the input arguments.
args (tuple) – Positional arguments to pass to the function. The first argument should be the item from the generator.
kwargs (dict) – Additional keyword arguments to pass to the function.
- Returns:
The process object or future that was submitted to the pool.
- getPool() Any [source]
Create the pool of workers consuming the generator.
- Returns:
A pool object that can be used to apply the function to the generator items in parallel.
- getResult(process: Any)[source]
Get the result of a process.
- Parameters:
process (Any) – The process object or a future to get the result from.
- Returns:
The result of the process.
- handleException(process: Any, exception: Exception) Any [source]
Handle an exception raised by a process. This is executed when the process raises an unexpected exception or the
checkProcess
method raises an exception.- Parameters:
process (Any) – The process object or a future that raised the exception.
exception (Exception) – The exception raised by the process.
- Returns:
The result to yield instead of the result of the process.
- make(generator: Generator, process_func: Callable, *args, **kwargs) Generator
A parallel “JIT (Just In Time)” generator that yields the results of a function applied in parallel to each item of a supplied generator. The advantage of this JIT implementation is that it only evaluates the next item in the input generator as soon as it is needed for the calculation. This means that only one item from the iterable is loaded into memory at a time.
The generator also supports timeout for each job. The “pebble” pool_type can be used to support this feature. In all other cases, the “multiprocessing” pool_type is sufficient.
- Parameters:
generator (SupportsNext) – An iterable object to apply the function to.
process_func (Callable) – The function to apply to each item in the iterable.
args (tuple | None) – Additional positional arguments to pass to the function.
kwargs (dict | None) – Additional keyword arguments to pass to the function.
- Returns:
A generator that yields the results of the function applied to each item in the iterable. If a timeout is specified, a
TimeoutError
will be returned instead.
- class qsprpred.utils.parallel.ThreadsJITGenerator(n_workers: int | None = None, worker_type: Literal['cpu', 'gpu'] = 'cpu', use_gpus: list[int] | None = None, jobs_per_gpu: int = 1)[source]
Bases:
JITParallelGenerator
This class uses the
concurrent.futures.ThreadPoolExecutor
to parallelize the processing of an input generator. Note that threads in Python are not truly parallel due to the Global Interpreter Lock (GIL). However, this can still be useful for I/O-bound tasks or tasks that are not CPU-bound downstream.Configures the multiprocessing pool generator.
- Parameters:
n_workers (int) – Number of workers to use.
worker_type (Literal["cpu", "gpu"]) – The type of worker to use.
use_gpus (list[int] | None) – A list of GPU indices to use. Only applicable if
worker_type
is ‘gpu’. If None, all available GPUs will be used.jobs_per_gpu (int) – Number of jobs to run on each GPU.
- checkProcess(process: Any)[source]
A simple check of a process or future before a result is attempted to be retrieved.
- createJob(pool: Any, process_func: Callable, *args, **kwargs) Any [source]
Submit a job to the pool that applies the function to a generator item.
- Parameters:
pool (Any) – The pool object to submit the job to.
process_func (Callable) – The function to apply to the input arguments.
args (tuple) – Positional arguments to pass to the function. The first argument should be the item from the generator.
kwargs (dict) – Additional keyword arguments to pass to the function.
- Returns:
The process object or future that was submitted to the pool.
- getPool() Any [source]
Create the pool of workers consuming the generator.
- Returns:
A pool object that can be used to apply the function to the generator items in parallel.
- getResult(process: Any)[source]
Get the result of a process.
- Parameters:
process (Any) – The process object or a future to get the result from.
- Returns:
The result of the process.
- handleException(process: Any, exception: Exception) Any [source]
Handle an exception raised by a process. This is executed when the process raises an unexpected exception or the
checkProcess
method raises an exception.- Parameters:
process (Any) – The process object or a future that raised the exception.
exception (Exception) – The exception raised by the process.
- Returns:
The result to yield instead of the result of the process.
- make(generator: Generator, process_func: Callable, *args, **kwargs) Generator
A parallel “JIT (Just In Time)” generator that yields the results of a function applied in parallel to each item of a supplied generator. The advantage of this JIT implementation is that it only evaluates the next item in the input generator as soon as it is needed for the calculation. This means that only one item from the iterable is loaded into memory at a time.
The generator also supports timeout for each job. The “pebble” pool_type can be used to support this feature. In all other cases, the “multiprocessing” pool_type is sufficient.
- Parameters:
generator (SupportsNext) – An iterable object to apply the function to.
process_func (Callable) – The function to apply to each item in the iterable.
args (tuple | None) – Additional positional arguments to pass to the function.
kwargs (dict | None) – Additional keyword arguments to pass to the function.
- Returns:
A generator that yields the results of the function applied to each item in the iterable. If a timeout is specified, a
TimeoutError
will be returned instead.
- qsprpred.utils.parallel.batched_generator(iterable: Iterable, batch_size: int) Generator [source]
A simple helper generator that batches inputs from a supplied
Iterable
.- Parameters:
iterable – An iterable object to batch with the generator.
batch_size – Number of items to include in each batch.
- Returns:
A generator that yields batches of the input generator one at a time.
qsprpred.utils.serialization module
- class qsprpred.utils.serialization.FileSerializable[source]
Bases:
ABC
A class that can be serialized to a file and reconstructed from a file.
- class qsprpred.utils.serialization.JSONSerializable[source]
Bases:
FileSerializable
A class that can be serialized to JSON and reconstructed from JSON.
- Variables:
_notJSON (list) – list of attributes that should not be serialized to JSON explicitly
- qsprpred.utils.serialization.function_as_string(func: Callable) str [source]
Convert a function to a string.
- Parameters:
func (Callable) – function to convert
- qsprpred.utils.serialization.function_from_string(func_str: str) Callable [source]
Convert a function from a string. Conversion from encoded bytecode is attempted first. If that fails, the string is assumed to be a fully qualified name of the function.
- Parameters:
func_str (str) – string representation of the function
- Returns:
function
- Return type:
processor (Callable)
qsprpred.utils.stopwatch module
qsprpred.utils.stringops module
Enumerating a list of items with leading zeros.
qsprpred.utils.tests module
- class qsprpred.utils.tests.TestMultiProcGenerators(methodName='runTest')[source]
Bases:
QSPRTestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
- classmethod addClassCleanup(function, /, *args, **kwargs)
Same as addCleanup, except the cleanup items are called even if setUpClass fails (unlike tearDownClass).
- addCleanup(function, /, *args, **kwargs)
Add a function, with arguments, to be called when the test is completed. Functions added are called on a LIFO basis and are called after tearDown on test failure or success.
Cleanup items are called even if setUp fails (unlike tearDown).
- addTypeEqualityFunc(typeobj, function)
Add a type specific assertEqual style function to compare a type.
This method is for use by TestCase subclasses that need to register their own type equality functions to provide nicer error messages.
- Parameters:
typeobj – The data type to call this function on when both values are of the same type in assertEqual().
function – The callable taking two arguments and an optional msg= argument that raises self.failureException with a useful error message when the two arguments are not equal.
- assertAlmostEqual(first, second, places=None, msg=None, delta=None)
Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is more than the given delta.
Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).
If the two objects compare equal then they will automatically compare almost equal.
- assertCountEqual(first, second, msg=None)
Asserts that two iterables have the same elements, the same number of times, without regard to order.
- self.assertEqual(Counter(list(first)),
Counter(list(second)))
- Example:
[0, 1, 1] and [1, 0, 1] compare equal.
[0, 0, 1] and [0, 1] compare unequal.
- assertDictEqual(d1, d2, msg=None)
- assertEqual(first, second, msg=None)
Fail if the two objects are unequal as determined by the ‘==’ operator.
- assertFalse(expr, msg=None)
Check that the expression is false.
- assertGreater(a, b, msg=None)
Just like self.assertTrue(a > b), but with a nicer default message.
- assertGreaterEqual(a, b, msg=None)
Just like self.assertTrue(a >= b), but with a nicer default message.
- assertIn(member, container, msg=None)
Just like self.assertTrue(a in b), but with a nicer default message.
- assertIs(expr1, expr2, msg=None)
Just like self.assertTrue(a is b), but with a nicer default message.
- assertIsInstance(obj, cls, msg=None)
Same as self.assertTrue(isinstance(obj, cls)), with a nicer default message.
- assertIsNone(obj, msg=None)
Same as self.assertTrue(obj is None), with a nicer default message.
- assertIsNot(expr1, expr2, msg=None)
Just like self.assertTrue(a is not b), but with a nicer default message.
- assertIsNotNone(obj, msg=None)
Included for symmetry with assertIsNone.
- assertLess(a, b, msg=None)
Just like self.assertTrue(a < b), but with a nicer default message.
- assertLessEqual(a, b, msg=None)
Just like self.assertTrue(a <= b), but with a nicer default message.
- assertListEqual(list1, list2, msg=None)
A list-specific equality assertion.
- Parameters:
list1 – The first list to compare.
list2 – The second list to compare.
msg – Optional message to use on failure instead of a list of differences.
- assertLogs(logger=None, level=None)
Fail unless a log message of level level or higher is emitted on logger_name or its children. If omitted, level defaults to INFO and logger defaults to the root logger.
This method must be used as a context manager, and will yield a recording object with two attributes:
output
andrecords
. At the end of the context manager, theoutput
attribute will be a list of the matching formatted log messages and therecords
attribute will be a list of the corresponding LogRecord objects.Example:
with self.assertLogs('foo', level='INFO') as cm: logging.getLogger('foo').info('first message') logging.getLogger('foo.bar').error('second message') self.assertEqual(cm.output, ['INFO:foo:first message', 'ERROR:foo.bar:second message'])
- assertMultiLineEqual(first, second, msg=None)
Assert that two multi-line strings are equal.
- assertNoLogs(logger=None, level=None)
Fail unless no log messages of level level or higher are emitted on logger_name or its children.
This method must be used as a context manager.
- assertNotAlmostEqual(first, second, places=None, msg=None, delta=None)
Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is less than the given delta.
Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).
Objects that are equal automatically fail.
- assertNotEqual(first, second, msg=None)
Fail if the two objects are equal as determined by the ‘!=’ operator.
- assertNotIn(member, container, msg=None)
Just like self.assertTrue(a not in b), but with a nicer default message.
- assertNotIsInstance(obj, cls, msg=None)
Included for symmetry with assertIsInstance.
- assertNotRegex(text, unexpected_regex, msg=None)
Fail the test if the text matches the regular expression.
- assertRaises(expected_exception, *args, **kwargs)
Fail unless an exception of class expected_exception is raised by the callable when invoked with specified positional and keyword arguments. If a different type of exception is raised, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an unexpected exception.
If called with the callable and arguments omitted, will return a context object used like this:
with self.assertRaises(SomeException): do_something()
An optional keyword argument ‘msg’ can be provided when assertRaises is used as a context object.
The context manager keeps a reference to the exception as the ‘exception’ attribute. This allows you to inspect the exception after the assertion:
with self.assertRaises(SomeException) as cm: do_something() the_exception = cm.exception self.assertEqual(the_exception.error_code, 3)
- assertRaisesRegex(expected_exception, expected_regex, *args, **kwargs)
Asserts that the message in a raised exception matches a regex.
- Parameters:
expected_exception – Exception class expected to be raised.
expected_regex – Regex (re.Pattern object or string) expected to be found in error message.
args – Function to be called and extra positional args.
kwargs – Extra kwargs.
msg – Optional message used in case of failure. Can only be used when assertRaisesRegex is used as a context manager.
- assertRegex(text, expected_regex, msg=None)
Fail the test unless the text matches the regular expression.
- assertSequenceEqual(seq1, seq2, msg=None, seq_type=None)
An equality assertion for ordered sequences (like lists and tuples).
For the purposes of this function, a valid ordered sequence type is one which can be indexed, has a length, and has an equality operator.
- Parameters:
seq1 – The first sequence to compare.
seq2 – The second sequence to compare.
seq_type – The expected datatype of the sequences, or None if no datatype should be enforced.
msg – Optional message to use on failure instead of a list of differences.
- assertSetEqual(set1, set2, msg=None)
A set-specific equality assertion.
- Parameters:
set1 – The first set to compare.
set2 – The second set to compare.
msg – Optional message to use on failure instead of a list of differences.
assertSetEqual uses ducktyping to support different types of sets, and is optimized for sets specifically (parameters must support a difference method).
- assertTrue(expr, msg=None)
Check that the expression is true.
- assertTupleEqual(tuple1, tuple2, msg=None)
A tuple-specific equality assertion.
- Parameters:
tuple1 – The first tuple to compare.
tuple2 – The second tuple to compare.
msg – Optional message to use on failure instead of a list of differences.
- assertWarns(expected_warning, *args, **kwargs)
Fail unless a warning of class warnClass is triggered by the callable when invoked with specified positional and keyword arguments. If a different type of warning is triggered, it will not be handled: depending on the other warning filtering rules in effect, it might be silenced, printed out, or raised as an exception.
If called with the callable and arguments omitted, will return a context object used like this:
with self.assertWarns(SomeWarning): do_something()
An optional keyword argument ‘msg’ can be provided when assertWarns is used as a context object.
The context manager keeps a reference to the first matching warning as the ‘warning’ attribute; similarly, the ‘filename’ and ‘lineno’ attributes give you information about the line of Python code from which the warning was triggered. This allows you to inspect the warning after the assertion:
with self.assertWarns(SomeWarning) as cm: do_something() the_warning = cm.warning self.assertEqual(the_warning.some_attribute, 147)
- assertWarnsRegex(expected_warning, expected_regex, *args, **kwargs)
Asserts that the message in a triggered warning matches a regexp. Basic functioning is similar to assertWarns() with the addition that only warnings whose messages also match the regular expression are considered successful matches.
- Parameters:
expected_warning – Warning class expected to be triggered.
expected_regex – Regex (re.Pattern object or string) expected to be found in error message.
args – Function to be called and extra positional args.
kwargs – Extra kwargs.
msg – Optional message used in case of failure. Can only be used when assertWarnsRegex is used as a context manager.
- countTestCases()
- debug()
Run the test without collecting errors in a TestResult
- defaultTestResult()
- classmethod doClassCleanups()
Execute all class cleanup functions. Normally called for you after tearDownClass.
- doCleanups()
Execute all cleanup functions. Normally called for you after tearDown.
- classmethod enterClassContext(cm)
Same as enterContext, but class-wide.
- enterContext(cm)
Enters the supplied context manager.
If successful, also adds its __exit__ method as a cleanup function and returns the result of the __enter__ method.
- fail(msg=None)
Fail immediately, with the given message.
- failureException
alias of
AssertionError
- id()
- longMessage = True
- maxDiff = 640
- run(result=None)
- setUp()
Hook method for setting up the test fixture before exercising it.
- classmethod setUpClass()
Hook method for setting up class fixture before running tests in the class.
- shortDescription()
Returns a one-line description of the test, or None if no description has been provided.
The default implementation of this method returns the first line of the specified test method’s docstring.
- skipTest(reason)
Skip this test.
- subTest(msg=<object object>, **params)
Return a context manager that will return the enclosed block of code in a subtest identified by the optional message and keyword parameters. A failure in the subtest marks the test case as failed but resumes execution at the end of the enclosed block, allowing further test code to be executed.
- tearDown()
Hook method for deconstructing the test fixture after testing it.
- classmethod tearDownClass()
Hook method for deconstructing the class fixture after running all tests in the class.
- testArgs = None
- testArgs_0(**kw)
- testArgs_1(**kw)
- testArgs_2(**kw)
- testBatched = None
- testBatched_0(**kw)
- testBatched_1(**kw)
- testBatched_2(**kw)
- testSimple = None
- testSimple_0(**kw)
- testSimple_1(**kw)
- testSimple_2(**kw)
- class qsprpred.utils.tests.TestThreadedGenerators(methodName='runTest')[source]
Bases:
QSPRTestCase
Test processing using a pool of threads.
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
- classmethod addClassCleanup(function, /, *args, **kwargs)
Same as addCleanup, except the cleanup items are called even if setUpClass fails (unlike tearDownClass).
- addCleanup(function, /, *args, **kwargs)
Add a function, with arguments, to be called when the test is completed. Functions added are called on a LIFO basis and are called after tearDown on test failure or success.
Cleanup items are called even if setUp fails (unlike tearDown).
- addTypeEqualityFunc(typeobj, function)
Add a type specific assertEqual style function to compare a type.
This method is for use by TestCase subclasses that need to register their own type equality functions to provide nicer error messages.
- Parameters:
typeobj – The data type to call this function on when both values are of the same type in assertEqual().
function – The callable taking two arguments and an optional msg= argument that raises self.failureException with a useful error message when the two arguments are not equal.
- assertAlmostEqual(first, second, places=None, msg=None, delta=None)
Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is more than the given delta.
Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).
If the two objects compare equal then they will automatically compare almost equal.
- assertCountEqual(first, second, msg=None)
Asserts that two iterables have the same elements, the same number of times, without regard to order.
- self.assertEqual(Counter(list(first)),
Counter(list(second)))
- Example:
[0, 1, 1] and [1, 0, 1] compare equal.
[0, 0, 1] and [0, 1] compare unequal.
- assertDictEqual(d1, d2, msg=None)
- assertEqual(first, second, msg=None)
Fail if the two objects are unequal as determined by the ‘==’ operator.
- assertFalse(expr, msg=None)
Check that the expression is false.
- assertGreater(a, b, msg=None)
Just like self.assertTrue(a > b), but with a nicer default message.
- assertGreaterEqual(a, b, msg=None)
Just like self.assertTrue(a >= b), but with a nicer default message.
- assertIn(member, container, msg=None)
Just like self.assertTrue(a in b), but with a nicer default message.
- assertIs(expr1, expr2, msg=None)
Just like self.assertTrue(a is b), but with a nicer default message.
- assertIsInstance(obj, cls, msg=None)
Same as self.assertTrue(isinstance(obj, cls)), with a nicer default message.
- assertIsNone(obj, msg=None)
Same as self.assertTrue(obj is None), with a nicer default message.
- assertIsNot(expr1, expr2, msg=None)
Just like self.assertTrue(a is not b), but with a nicer default message.
- assertIsNotNone(obj, msg=None)
Included for symmetry with assertIsNone.
- assertLess(a, b, msg=None)
Just like self.assertTrue(a < b), but with a nicer default message.
- assertLessEqual(a, b, msg=None)
Just like self.assertTrue(a <= b), but with a nicer default message.
- assertListEqual(list1, list2, msg=None)
A list-specific equality assertion.
- Parameters:
list1 – The first list to compare.
list2 – The second list to compare.
msg – Optional message to use on failure instead of a list of differences.
- assertLogs(logger=None, level=None)
Fail unless a log message of level level or higher is emitted on logger_name or its children. If omitted, level defaults to INFO and logger defaults to the root logger.
This method must be used as a context manager, and will yield a recording object with two attributes:
output
andrecords
. At the end of the context manager, theoutput
attribute will be a list of the matching formatted log messages and therecords
attribute will be a list of the corresponding LogRecord objects.Example:
with self.assertLogs('foo', level='INFO') as cm: logging.getLogger('foo').info('first message') logging.getLogger('foo.bar').error('second message') self.assertEqual(cm.output, ['INFO:foo:first message', 'ERROR:foo.bar:second message'])
- assertMultiLineEqual(first, second, msg=None)
Assert that two multi-line strings are equal.
- assertNoLogs(logger=None, level=None)
Fail unless no log messages of level level or higher are emitted on logger_name or its children.
This method must be used as a context manager.
- assertNotAlmostEqual(first, second, places=None, msg=None, delta=None)
Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is less than the given delta.
Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).
Objects that are equal automatically fail.
- assertNotEqual(first, second, msg=None)
Fail if the two objects are equal as determined by the ‘!=’ operator.
- assertNotIn(member, container, msg=None)
Just like self.assertTrue(a not in b), but with a nicer default message.
- assertNotIsInstance(obj, cls, msg=None)
Included for symmetry with assertIsInstance.
- assertNotRegex(text, unexpected_regex, msg=None)
Fail the test if the text matches the regular expression.
- assertRaises(expected_exception, *args, **kwargs)
Fail unless an exception of class expected_exception is raised by the callable when invoked with specified positional and keyword arguments. If a different type of exception is raised, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an unexpected exception.
If called with the callable and arguments omitted, will return a context object used like this:
with self.assertRaises(SomeException): do_something()
An optional keyword argument ‘msg’ can be provided when assertRaises is used as a context object.
The context manager keeps a reference to the exception as the ‘exception’ attribute. This allows you to inspect the exception after the assertion:
with self.assertRaises(SomeException) as cm: do_something() the_exception = cm.exception self.assertEqual(the_exception.error_code, 3)
- assertRaisesRegex(expected_exception, expected_regex, *args, **kwargs)
Asserts that the message in a raised exception matches a regex.
- Parameters:
expected_exception – Exception class expected to be raised.
expected_regex – Regex (re.Pattern object or string) expected to be found in error message.
args – Function to be called and extra positional args.
kwargs – Extra kwargs.
msg – Optional message used in case of failure. Can only be used when assertRaisesRegex is used as a context manager.
- assertRegex(text, expected_regex, msg=None)
Fail the test unless the text matches the regular expression.
- assertSequenceEqual(seq1, seq2, msg=None, seq_type=None)
An equality assertion for ordered sequences (like lists and tuples).
For the purposes of this function, a valid ordered sequence type is one which can be indexed, has a length, and has an equality operator.
- Parameters:
seq1 – The first sequence to compare.
seq2 – The second sequence to compare.
seq_type – The expected datatype of the sequences, or None if no datatype should be enforced.
msg – Optional message to use on failure instead of a list of differences.
- assertSetEqual(set1, set2, msg=None)
A set-specific equality assertion.
- Parameters:
set1 – The first set to compare.
set2 – The second set to compare.
msg – Optional message to use on failure instead of a list of differences.
assertSetEqual uses ducktyping to support different types of sets, and is optimized for sets specifically (parameters must support a difference method).
- assertTrue(expr, msg=None)
Check that the expression is true.
- assertTupleEqual(tuple1, tuple2, msg=None)
A tuple-specific equality assertion.
- Parameters:
tuple1 – The first tuple to compare.
tuple2 – The second tuple to compare.
msg – Optional message to use on failure instead of a list of differences.
- assertWarns(expected_warning, *args, **kwargs)
Fail unless a warning of class warnClass is triggered by the callable when invoked with specified positional and keyword arguments. If a different type of warning is triggered, it will not be handled: depending on the other warning filtering rules in effect, it might be silenced, printed out, or raised as an exception.
If called with the callable and arguments omitted, will return a context object used like this:
with self.assertWarns(SomeWarning): do_something()
An optional keyword argument ‘msg’ can be provided when assertWarns is used as a context object.
The context manager keeps a reference to the first matching warning as the ‘warning’ attribute; similarly, the ‘filename’ and ‘lineno’ attributes give you information about the line of Python code from which the warning was triggered. This allows you to inspect the warning after the assertion:
with self.assertWarns(SomeWarning) as cm: do_something() the_warning = cm.warning self.assertEqual(the_warning.some_attribute, 147)
- assertWarnsRegex(expected_warning, expected_regex, *args, **kwargs)
Asserts that the message in a triggered warning matches a regexp. Basic functioning is similar to assertWarns() with the addition that only warnings whose messages also match the regular expression are considered successful matches.
- Parameters:
expected_warning – Warning class expected to be triggered.
expected_regex – Regex (re.Pattern object or string) expected to be found in error message.
args – Function to be called and extra positional args.
kwargs – Extra kwargs.
msg – Optional message used in case of failure. Can only be used when assertWarnsRegex is used as a context manager.
- countTestCases()
- debug()
Run the test without collecting errors in a TestResult
- defaultTestResult()
- classmethod doClassCleanups()
Execute all class cleanup functions. Normally called for you after tearDownClass.
- doCleanups()
Execute all cleanup functions. Normally called for you after tearDown.
- classmethod enterClassContext(cm)
Same as enterContext, but class-wide.
- enterContext(cm)
Enters the supplied context manager.
If successful, also adds its __exit__ method as a cleanup function and returns the result of the __enter__ method.
- fail(msg=None)
Fail immediately, with the given message.
- failureException
alias of
AssertionError
- id()
- longMessage = True
- maxDiff = 640
- run(result=None)
- setUp()
Hook method for setting up the test fixture before exercising it.
- classmethod setUpClass()
Hook method for setting up class fixture before running tests in the class.
- shortDescription()
Returns a one-line description of the test, or None if no description has been provided.
The default implementation of this method returns the first line of the specified test method’s docstring.
- skipTest(reason)
Skip this test.
- subTest(msg=<object object>, **params)
Return a context manager that will return the enclosed block of code in a subtest identified by the optional message and keyword parameters. A failure in the subtest marks the test case as failed but resumes execution at the end of the enclosed block, allowing further test code to be executed.
- tearDown()
Hook method for deconstructing the test fixture after testing it.
- classmethod tearDownClass()
Hook method for deconstructing the class fixture after running all tests in the class.