summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac-HD <zac.hatfield.dodds@gmail.com>2020-01-24 16:28:16 +1100
committerZac-HD <zac.hatfield.dodds@gmail.com>2020-02-05 21:42:21 +1100
commit219004e0926cf4030b2242c188f85ce87aa1c83a (patch)
tree2bb2576f0af048f0d60d7b018f2401ee04ada54c
parent32ce6b8cea5b464ea9b008e2b0cc3d86615a1bd5 (diff)
downloadnumpy-219004e0926cf4030b2242c188f85ce87aa1c83a.tar.gz
Property test for Unicode array printing
Co-Authored-By: kitchoi <kit@kychoi.org>
-rw-r--r--numpy/core/tests/test_arrayprint.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py
index cd3e501a5..008ca20e6 100644
--- a/numpy/core/tests/test_arrayprint.py
+++ b/numpy/core/tests/test_arrayprint.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
import sys
import gc
+from hypothesis import given
+from hypothesis.extra import numpy as hynp
import pytest
import numpy as np
@@ -393,6 +395,18 @@ class TestArray2String:
"[ 'xxxxx']"
)
+ @given(hynp.from_dtype(np.dtype("U")))
+ def test_any_text(self, text):
+ # This test checks that, given any value that can be represented in an
+ # array of dtype("U") (i.e. unicode string), ...
+ a = np.array([text, text, text])
+ # casting a list of them to an array does not e.g. truncate the value
+ assert_equal(a[0], text)
+ # and that np.array2string puts a newline in the expected location
+ expected_repr = "[{0!r} {0!r}\n {0!r}]".format(text)
+ result = np.array2string(a, max_line_width=len(repr(text)) * 2 + 3)
+ assert_equal(result, expected_repr)
+
@pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
def test_refcount(self):
# make sure we do not hold references to the array due to a recursive