Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 815fee6

Browse files
committed
MAINT clean up test suite
1 parent 6cbd724 commit 815fee6

File tree

1 file changed

+44
-48
lines changed

1 file changed

+44
-48
lines changed

numpy/core/tests/test_longdouble.py

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import locale
44
from tempfile import NamedTemporaryFile
5-
import unittest
65

76
import numpy as np
87
from numpy.testing import (
98
run_module_suite, assert_, assert_equal, dec, assert_raises,
10-
assert_array_equal
9+
assert_array_equal, TestCase
1110
)
1211
from numpy.compat import sixu
1312
from test_print import in_foreign_locale
@@ -16,6 +15,10 @@
1615
< np.finfo(np.double).eps)
1716

1817

18+
_o = 1 + np.finfo(np.longdouble).eps
19+
string_to_longdouble_inaccurate = (_o != np.longdouble(repr(_o)))
20+
del _o
21+
1922
def test_scalar_extraction():
2023
"""Confirm that extracting a value doesn't convert to python float"""
2124
o = 1 + np.finfo(np.longdouble).eps
@@ -51,6 +54,7 @@ def test_fromstring_foreign():
5154
assert_equal(a[0], f)
5255

5356

57+
@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
5458
def test_repr_roundtrip_bytes():
5559
o = 1 + np.finfo(np.longdouble).eps
5660
assert_equal(np.longdouble(repr(o).encode("ascii")), o)
@@ -67,10 +71,7 @@ def test_bogus_string():
6771
assert_raises(ValueError, np.longdouble, "1.0 flub")
6872

6973

70-
def test_underflow_zero():
71-
z = np.finfo
72-
73-
74+
@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
7475
def test_fromstring():
7576
o = 1 + np.finfo(np.longdouble).eps
7677
s = (" " + repr(o))*5
@@ -79,47 +80,6 @@ def test_fromstring():
7980
err_msg="reading '%s'" % s)
8081

8182

82-
def test_loadtxt():
83-
o = 1 + np.finfo(np.longdouble).eps
84-
f = NamedTemporaryFile(mode="wt")
85-
for i in range(5):
86-
f.write(repr(o) + "\n")
87-
f.flush()
88-
a = np.array([o]*5)
89-
assert_equal(np.loadtxt(f.name, dtype=np.longdouble), a)
90-
f.close()
91-
92-
93-
def test_genfromtxt():
94-
o = 1 + np.finfo(np.longdouble).eps
95-
f = NamedTemporaryFile(mode="wt")
96-
for i in range(5):
97-
f.write(repr(o) + "\n")
98-
f.flush()
99-
a = np.array([o]*5)
100-
assert_equal(np.genfromtxt(f.name, dtype=np.longdouble), a)
101-
f.close()
102-
103-
104-
def test_fromfile():
105-
o = 1 + np.finfo(np.longdouble).eps
106-
f = NamedTemporaryFile(mode="wt")
107-
for i in range(5):
108-
f.write(repr(o) + "\n")
109-
f.flush()
110-
a = np.array([o]*5)
111-
F = open(f.name, "rt")
112-
b = np.fromfile(F,
113-
dtype=np.longdouble,
114-
sep="\n")
115-
F.close()
116-
F = open(f.name, "rt")
117-
s = F.read()
118-
F.close()
119-
f.close()
120-
assert_equal(b, a, err_msg="decoded %s as %s" % (repr(s), repr(b)))
121-
122-
12383
def test_fromstring_bogus():
12484
assert_equal(np.fromstring("1. 2. 3. flop 4.", dtype=float, sep=" "),
12585
np.array([1., 2., 3.]))
@@ -135,7 +95,7 @@ def test_fromstring_missing():
13595
np.array([1]))
13696

13797

138-
class FileBased(unittest.TestCase):
98+
class FileBased(TestCase):
13999
def setUp(self):
140100
self.o = 1 + np.finfo(np.longdouble).eps
141101
self.f = NamedTemporaryFile(mode="wt")
@@ -154,6 +114,39 @@ def test_fromfile_bogus(self):
154114
finally:
155115
F.close()
156116

117+
@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
118+
def test_fromfile(self):
119+
for i in range(5):
120+
self.f.write(repr(self.o) + "\n")
121+
self.f.flush()
122+
a = np.array([self.o]*5)
123+
F = open(self.f.name, "rt")
124+
b = np.fromfile(F,
125+
dtype=np.longdouble,
126+
sep="\n")
127+
F.close()
128+
F = open(self.f.name, "rt")
129+
s = F.read()
130+
F.close()
131+
assert_equal(b, a, err_msg="decoded %s as %s" % (repr(s), repr(b)))
132+
133+
@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
134+
def test_genfromtxt(self):
135+
for i in range(5):
136+
self.f.write(repr(self.o) + "\n")
137+
self.f.flush()
138+
a = np.array([self.o]*5)
139+
assert_equal(np.genfromtxt(self.f.name, dtype=np.longdouble), a)
140+
141+
@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
142+
def test_loadtxt(self):
143+
for i in range(5):
144+
self.f.write(repr(self.o) + "\n")
145+
self.f.flush()
146+
a = np.array([self.o]*5)
147+
assert_equal(np.loadtxt(self.f.name, dtype=np.longdouble), a)
148+
149+
@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
157150
def test_tofile_roundtrip(self):
158151
a = np.array([self.o]*3)
159152
a.tofile(self.f.name, sep=" ")
@@ -194,18 +187,21 @@ def test_repr_exact():
194187

195188

196189
@dec.knownfailureif(longdouble_longer_than_double, "BUG #2376")
190+
@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
197191
def test_format():
198192
o = 1 + np.finfo(np.longdouble).eps
199193
assert_("{0:.40g}".format(o) != '1')
200194

201195

202196
@dec.knownfailureif(longdouble_longer_than_double, "BUG #2376")
197+
@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
203198
def test_percent():
204199
o = 1 + np.finfo(np.longdouble).eps
205200
assert_("%.40g" % o != '1')
206201

207202

208203
@dec.knownfailureif(longdouble_longer_than_double, "array repr problem")
204+
@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
209205
def test_array_repr():
210206
o = 1 + np.finfo(np.longdouble).eps
211207
a = np.array([o])

0 commit comments

Comments
 (0)