Hacks to assist with testing.
*Latest release 20241122*:
assertSingleThread: new optional exclude parameter which is a callable to test where a Thread should be ignored.
## <a name="assertSingleThread"></a>`assertSingleThread(include_daemon=False, exclude=None)`
Test that there is only one `Thread` still running.
Parameters:
* `include_daemon`: also count daemon `Thread`s, normally skipped
* `exclude`: optional `Callable[Thread]` to test for other `Thread`s to exclude
## <a name="product_test"></a>`product_test(*da, **dkw)`
Decorator for test methods which should run subTests
against the Cartesian products from `params`.
A specific TestCase would define its own decorator
and apply it throughout the suite.
Here is an example from cs.vt.datadir_tests:
def multitest(test_method):
return product_test(
test_method,
datadirclass=[DataDir, RawDataDir],
indexclass=[
indexclass_by_name(indexname)
for indexname in sorted(indexclass_names())
],
hashclass=[
HASHCLASS_BY_NAME[hashname]
for hashname in sorted(HASHCLASS_BY_NAME.keys())
],
)
whose test suite then just decorates each method with `@multitest`:
@multitest
def test000IndexEntry(self):
....
Note that because there must be setup and teardown for each product,
the TestCase class may well have empty `setUp` and `tearDown` methods
and instead is expected to provide:
* `product_setup(self,**params)`:
a setup method taking keyword arguments for each product
* `product_teardown(self)`:
the corresponding testdown method
There are called around each `subTest`.
## <a name="SetupTeardownMixin"></a>Class `SetupTeardownMixin`
A mixin to support a single `setupTeardown()` context manager method.
*`SetupTeardownMixin.setUp(self)`*:
Run `super().setUp()` then the set up step of `self.setupTeardown()`.
*`SetupTeardownMixin.tearDown(self)`*:
Run the tear down step of `self.setupTeardown()`,
then `super().tearDown()`.
# Release Log
*Release 20241122*:
assertSingleThread: new optional exclude parameter which is a callable to test where a Thread should be ignored.
*Release 20240623*:
New assertSingleThread() function to check that there are no left over Threads.
*Release 20230109*:
* @product_test decorator for running test matrices.
* SetupTeardownMixin providing unittest setUp/tearDown from setupTeardown context manager method.
Raw data
{
"_id": null,
"home_page": null,
"name": "cs-testutils",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "python3",
"author": null,
"author_email": "Cameron Simpson <cs@cskk.id.au>",
"download_url": "https://files.pythonhosted.org/packages/17/7b/a53b272e1a0692d52a329ad2eb5841a3ccb30fd69de1ff34da914d53b8d3/cs_testutils-20241122.tar.gz",
"platform": null,
"description": "Hacks to assist with testing.\n\n*Latest release 20241122*:\nassertSingleThread: new optional exclude parameter which is a callable to test where a Thread should be ignored.\n\n## <a name=\"assertSingleThread\"></a>`assertSingleThread(include_daemon=False, exclude=None)`\n\nTest that there is only one `Thread` still running.\n\nParameters:\n* `include_daemon`: also count daemon `Thread`s, normally skipped\n* `exclude`: optional `Callable[Thread]` to test for other `Thread`s to exclude\n\n## <a name=\"product_test\"></a>`product_test(*da, **dkw)`\n\nDecorator for test methods which should run subTests\nagainst the Cartesian products from `params`.\n\nA specific TestCase would define its own decorator\nand apply it throughout the suite.\nHere is an example from cs.vt.datadir_tests:\n\n def multitest(test_method):\n return product_test(\n test_method,\n datadirclass=[DataDir, RawDataDir],\n indexclass=[\n indexclass_by_name(indexname)\n for indexname in sorted(indexclass_names())\n ],\n hashclass=[\n HASHCLASS_BY_NAME[hashname]\n for hashname in sorted(HASHCLASS_BY_NAME.keys())\n ],\n )\n\nwhose test suite then just decorates each method with `@multitest`:\n\n @multitest\n def test000IndexEntry(self):\n ....\n\nNote that because there must be setup and teardown for each product,\nthe TestCase class may well have empty `setUp` and `tearDown` methods\nand instead is expected to provide:\n* `product_setup(self,**params)`:\n a setup method taking keyword arguments for each product\n* `product_teardown(self)`:\n the corresponding testdown method\nThere are called around each `subTest`.\n\n## <a name=\"SetupTeardownMixin\"></a>Class `SetupTeardownMixin`\n\nA mixin to support a single `setupTeardown()` context manager method.\n\n*`SetupTeardownMixin.setUp(self)`*:\nRun `super().setUp()` then the set up step of `self.setupTeardown()`.\n\n*`SetupTeardownMixin.tearDown(self)`*:\nRun the tear down step of `self.setupTeardown()`,\nthen `super().tearDown()`.\n\n# Release Log\n\n\n\n*Release 20241122*:\nassertSingleThread: new optional exclude parameter which is a callable to test where a Thread should be ignored.\n\n*Release 20240623*:\nNew assertSingleThread() function to check that there are no left over Threads.\n\n*Release 20230109*:\n* @product_test decorator for running test matrices.\n* SetupTeardownMixin providing unittest setUp/tearDown from setupTeardown context manager method.\n",
"bugtrack_url": null,
"license": "GNU General Public License v3 or later (GPLv3+)",
"summary": "Hacks to assist with testing.",
"version": "20241122",
"project_urls": {
"MonoRepo Commits": "https://bitbucket.org/cameron_simpson/css/commits/branch/main",
"Monorepo Git Mirror": "https://github.com/cameron-simpson/css",
"Monorepo Hg/Mercurial Mirror": "https://hg.sr.ht/~cameron-simpson/css",
"Source": "https://github.com/cameron-simpson/css/blob/main/lib/python/cs/testutils.py"
},
"split_keywords": [
"python3"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "11d598d045706dc6f8ef2ad1d5eac25f156d5a18b713d99b93b160780064eb78",
"md5": "becc4c5e0db7e1fed7fe661d00b21fa2",
"sha256": "98d5b98bcaa6d2ac05850427bca39bac3a803d4ad5180f9c4ec057fe5967eeb9"
},
"downloads": -1,
"filename": "cs_testutils-20241122-py3-none-any.whl",
"has_sig": false,
"md5_digest": "becc4c5e0db7e1fed7fe661d00b21fa2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4243,
"upload_time": "2024-11-22T07:41:06",
"upload_time_iso_8601": "2024-11-22T07:41:06.587668Z",
"url": "https://files.pythonhosted.org/packages/11/d5/98d045706dc6f8ef2ad1d5eac25f156d5a18b713d99b93b160780064eb78/cs_testutils-20241122-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "177ba53b272e1a0692d52a329ad2eb5841a3ccb30fd69de1ff34da914d53b8d3",
"md5": "57e041b6e9751d1f5cb73a604d5a77fd",
"sha256": "39704928812f3a2147f33c043e1bd37e6eca0bc174d066798ece7f18386975aa"
},
"downloads": -1,
"filename": "cs_testutils-20241122.tar.gz",
"has_sig": false,
"md5_digest": "57e041b6e9751d1f5cb73a604d5a77fd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3851,
"upload_time": "2024-11-22T07:41:08",
"upload_time_iso_8601": "2024-11-22T07:41:08.335309Z",
"url": "https://files.pythonhosted.org/packages/17/7b/a53b272e1a0692d52a329ad2eb5841a3ccb30fd69de1ff34da914d53b8d3/cs_testutils-20241122.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-22 07:41:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cameron-simpson",
"github_project": "css",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "cs-testutils"
}