2
2
3
3
import locale
4
4
from tempfile import NamedTemporaryFile
5
- import unittest
6
5
7
6
import numpy as np
8
7
from numpy .testing import (
9
8
run_module_suite , assert_ , assert_equal , dec , assert_raises ,
10
- assert_array_equal
9
+ assert_array_equal , TestCase
11
10
)
12
11
from numpy .compat import sixu
13
12
from test_print import in_foreign_locale
16
15
< np .finfo (np .double ).eps )
17
16
18
17
18
+ _o = 1 + np .finfo (np .longdouble ).eps
19
+ string_to_longdouble_inaccurate = (_o != np .longdouble (repr (_o )))
20
+ del _o
21
+
19
22
def test_scalar_extraction ():
20
23
"""Confirm that extracting a value doesn't convert to python float"""
21
24
o = 1 + np .finfo (np .longdouble ).eps
@@ -51,6 +54,7 @@ def test_fromstring_foreign():
51
54
assert_equal (a [0 ], f )
52
55
53
56
57
+ @dec .knownfailureif (string_to_longdouble_inaccurate , "Need strtold_l" )
54
58
def test_repr_roundtrip_bytes ():
55
59
o = 1 + np .finfo (np .longdouble ).eps
56
60
assert_equal (np .longdouble (repr (o ).encode ("ascii" )), o )
@@ -67,10 +71,7 @@ def test_bogus_string():
67
71
assert_raises (ValueError , np .longdouble , "1.0 flub" )
68
72
69
73
70
- def test_underflow_zero ():
71
- z = np .finfo
72
-
73
-
74
+ @dec .knownfailureif (string_to_longdouble_inaccurate , "Need strtold_l" )
74
75
def test_fromstring ():
75
76
o = 1 + np .finfo (np .longdouble ).eps
76
77
s = (" " + repr (o ))* 5
@@ -79,47 +80,6 @@ def test_fromstring():
79
80
err_msg = "reading '%s'" % s )
80
81
81
82
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
-
123
83
def test_fromstring_bogus ():
124
84
assert_equal (np .fromstring ("1. 2. 3. flop 4." , dtype = float , sep = " " ),
125
85
np .array ([1. , 2. , 3. ]))
@@ -135,7 +95,7 @@ def test_fromstring_missing():
135
95
np .array ([1 ]))
136
96
137
97
138
- class FileBased (unittest . TestCase ):
98
+ class FileBased (TestCase ):
139
99
def setUp (self ):
140
100
self .o = 1 + np .finfo (np .longdouble ).eps
141
101
self .f = NamedTemporaryFile (mode = "wt" )
@@ -154,6 +114,39 @@ def test_fromfile_bogus(self):
154
114
finally :
155
115
F .close ()
156
116
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" )
157
150
def test_tofile_roundtrip (self ):
158
151
a = np .array ([self .o ]* 3 )
159
152
a .tofile (self .f .name , sep = " " )
@@ -194,18 +187,21 @@ def test_repr_exact():
194
187
195
188
196
189
@dec .knownfailureif (longdouble_longer_than_double , "BUG #2376" )
190
+ @dec .knownfailureif (string_to_longdouble_inaccurate , "Need strtold_l" )
197
191
def test_format ():
198
192
o = 1 + np .finfo (np .longdouble ).eps
199
193
assert_ ("{0:.40g}" .format (o ) != '1' )
200
194
201
195
202
196
@dec .knownfailureif (longdouble_longer_than_double , "BUG #2376" )
197
+ @dec .knownfailureif (string_to_longdouble_inaccurate , "Need strtold_l" )
203
198
def test_percent ():
204
199
o = 1 + np .finfo (np .longdouble ).eps
205
200
assert_ ("%.40g" % o != '1' )
206
201
207
202
208
203
@dec .knownfailureif (longdouble_longer_than_double , "array repr problem" )
204
+ @dec .knownfailureif (string_to_longdouble_inaccurate , "Need strtold_l" )
209
205
def test_array_repr ():
210
206
o = 1 + np .finfo (np .longdouble ).eps
211
207
a = np .array ([o ])
0 commit comments