diff options
author | Ronan Lamy <ronan.lamy@gmail.com> | 2017-02-08 20:21:59 +0000 |
---|---|---|
committer | Ronan Lamy <ronan.lamy@gmail.com> | 2017-02-08 20:21:59 +0000 |
commit | de988b40c704d1772f629e5a6d0a4e8748f057fc (patch) | |
tree | 46520d9eeefd25851348f682a3de6b8924ec5732 /numpy | |
parent | 98b3127fa61e09387e1f7cf925acfcb36043e48a (diff) | |
download | numpy-de988b40c704d1772f629e5a6d0a4e8748f057fc.tar.gz |
TST: Replace use of sys.getsizeof() with explicit computation of unicode representation size
This is for PyPy3 compatibility: sys.getsizeof() is CPython-specific and
there doesn't seem to be a pure-Python way of getting the size of the
internal PEP393 Unicode representation, so recompute it using documented
invariants.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/tests/test_unicode.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/numpy/core/tests/test_unicode.py b/numpy/core/tests/test_unicode.py index 9935b60ad..f2c501235 100644 --- a/numpy/core/tests/test_unicode.py +++ b/numpy/core/tests/test_unicode.py @@ -15,7 +15,17 @@ if sys.version_info[:2] >= (3, 3): def buffer_length(arr): if isinstance(arr, unicode): arr = str(arr) - return (sys.getsizeof(arr+"a") - sys.getsizeof(arr)) * len(arr) + if not arr: + charmax = 0 + else: + charmax = max([ord(c) for c in arr]) + if charmax < 256: + size = 1 + elif charmax < 65536: + size = 2 + else: + size = 4 + return size * len(arr) v = memoryview(arr) if v.shape is None: return len(v) * v.itemsize |