diff options
| author | David Lechner <david@lechnology.com> | 2020-03-22 21:26:08 -0500 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2020-03-30 13:21:58 +1100 |
| commit | 3dc324d3f1312e40d3a8ed87e7244966bb756f26 (patch) | |
| tree | 94ff44f8eabba0039582c245b901173597edd11e /tests/stress/qstr_limit.py | |
| parent | 488613bca6c460340ed2995ae5cafafe22d0bfff (diff) | |
tests: Format all Python code with black, except tests in basics subdir.
This adds the Python files in the tests/ directory to be formatted with
./tools/codeformat.py. The basics/ subdirectory is excluded for now so we
aren't changing too much at once.
In a few places `# fmt: off`/`# fmt: on` was used where the code had
special formatting for readability or where the test was actually testing
the specific formatting.
Diffstat (limited to 'tests/stress/qstr_limit.py')
| -rw-r--r-- | tests/stress/qstr_limit.py | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/tests/stress/qstr_limit.py b/tests/stress/qstr_limit.py index 889ab7e51..d8ce0cf7c 100644 --- a/tests/stress/qstr_limit.py +++ b/tests/stress/qstr_limit.py @@ -1,28 +1,32 @@ # Test interning qstrs that go over the limit of the maximum qstr length # (which is 255 bytes for the default configuration) -def make_id(n, base='a'): - return ''.join(chr(ord(base) + i % 26) for i in range(n)) + +def make_id(n, base="a"): + return "".join(chr(ord(base) + i % 26) for i in range(n)) + # identifiers in parser for l in range(254, 259): g = {} var = make_id(l) try: - exec(var + '=1', g) + exec(var + "=1", g) except RuntimeError: - print('RuntimeError', l) + print("RuntimeError", l) continue print(var in g) # calling a function with kwarg def f(**k): print(k) + + for l in range(254, 259): try: - exec('f({}=1)'.format(make_id(l))) + exec("f({}=1)".format(make_id(l))) except RuntimeError: - print('RuntimeError', l) + print("RuntimeError", l) # type construction for l in range(254, 259): @@ -30,38 +34,40 @@ for l in range(254, 259): try: print(type(id, (), {}).__name__) except RuntimeError: - print('RuntimeError', l) + print("RuntimeError", l) # hasattr, setattr, getattr class A: pass + + for l in range(254, 259): id = make_id(l) a = A() try: setattr(a, id, 123) except RuntimeError: - print('RuntimeError', l) + print("RuntimeError", l) try: print(hasattr(a, id), getattr(a, id)) except RuntimeError: - print('RuntimeError', l) + print("RuntimeError", l) # format with keys for l in range(254, 259): id = make_id(l) try: - print(('{' + id + '}').format(**{id: l})) + print(("{" + id + "}").format(**{id: l})) except RuntimeError: - print('RuntimeError', l) + print("RuntimeError", l) # modulo format with keys for l in range(254, 259): id = make_id(l) try: - print(('%(' + id + ')d') % {id: l}) + print(("%(" + id + ")d") % {id: l}) except RuntimeError: - print('RuntimeError', l) + print("RuntimeError", l) # import module # (different OS's have different results so only run those that are consistent) @@ -69,15 +75,15 @@ for l in (100, 101, 256, 257, 258): try: __import__(make_id(l)) except ImportError: - print('ok', l) + print("ok", l) except RuntimeError: - print('RuntimeError', l) + print("RuntimeError", l) # import package for l in (100, 101, 102, 128, 129): try: - exec('import ' + make_id(l) + '.' + make_id(l, 'A')) + exec("import " + make_id(l) + "." + make_id(l, "A")) except ImportError: - print('ok', l) + print("ok", l) except RuntimeError: - print('RuntimeError', l) + print("RuntimeError", l) |
