diff options
author | Victor Stinner <vstinner@python.org> | 2023-09-09 23:41:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-09 23:41:21 (GMT) |
commit | 0c0f254230bbc9532a7e78077a639a3ac940953c (patch) | |
tree | d35badf6fac682af73666dc883292a67df5778da /Lib/test/test_support.py | |
parent | 24fa8f2046965b46c70a750a5a004708a63ac770 (diff) | |
download | cpython-0c0f254230bbc9532a7e78077a639a3ac940953c.zip cpython-0c0f254230bbc9532a7e78077a639a3ac940953c.tar.gz cpython-0c0f254230bbc9532a7e78077a639a3ac940953c.tar.bz2 |
gh-109162: libregrtest: remove WorkerJob class (#109204)
* Add attributes to Regrtest and RunTests:
* gc_threshold
* memory_limit
* python_cmd
* use_resources
* Remove WorkerJob class. Add as_json() and from_json() methods to
RunTests. A worker process now only uses RunTests for all
parameters.
* Add tests on support.set_memlimit() in test_support. Create
_parse_memlimit() and also adds tests on it.
* Remove 'ns' parameter from runtest.py.
Diffstat (limited to 'Lib/test/test_support.py')
-rw-r--r-- | Lib/test/test_support.py | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 6428073..5b57c5f 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -760,7 +760,45 @@ class TestSupport(unittest.TestCase): else: self.fail("RecursionError was not raised") - #self.assertEqual(available, 2) + def test_parse_memlimit(self): + parse = support._parse_memlimit + KiB = 1024 + MiB = KiB * 1024 + GiB = MiB * 1024 + TiB = GiB * 1024 + self.assertEqual(parse('0k'), 0) + self.assertEqual(parse('3k'), 3 * KiB) + self.assertEqual(parse('2.4m'), int(2.4 * MiB)) + self.assertEqual(parse('4g'), int(4 * GiB)) + self.assertEqual(parse('1t'), TiB) + + for limit in ('', '3', '3.5.10k', '10x'): + with self.subTest(limit=limit): + with self.assertRaises(ValueError): + parse(limit) + + def test_set_memlimit(self): + _4GiB = 4 * 1024 ** 3 + TiB = 1024 ** 4 + old_max_memuse = support.max_memuse + old_real_max_memuse = support.real_max_memuse + try: + if sys.maxsize > 2**32: + support.set_memlimit('4g') + self.assertEqual(support.max_memuse, _4GiB) + self.assertEqual(support.real_max_memuse, _4GiB) + + big = 2**100 // TiB + support.set_memlimit(f'{big}t') + self.assertEqual(support.max_memuse, sys.maxsize) + self.assertEqual(support.real_max_memuse, big * TiB) + else: + support.set_memlimit('4g') + self.assertEqual(support.max_memuse, sys.maxsize) + self.assertEqual(support.real_max_memuse, _4GiB) + finally: + support.max_memuse = old_max_memuse + support.real_max_memuse = old_real_max_memuse # XXX -follows a list of untested API # make_legacy_pyc @@ -773,7 +811,6 @@ class TestSupport(unittest.TestCase): # EnvironmentVarGuard # transient_internet # run_with_locale - # set_memlimit # bigmemtest # precisionbigmemtest # bigaddrspacetest |