Skip to content

Commit 35fb82a

Browse files
committed
* os.py: _exit doesn't exist in all variations of posix
* Added fcmp() to test_support.py and use it in test*.py
1 parent 93f0740 commit 35fb82a

4 files changed

Lines changed: 45 additions & 19 deletions

File tree

Lib/os.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
try:
2020
from posix import *
21-
from posix import _exit
21+
try:
22+
from posix import _exit
23+
except ImportError:
24+
pass
2225
name = 'posix'
2326
curdir = '.'
2427
pardir = '..'

Lib/test/test_b1.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def f3(a1, a2, a3):
4242
if cmp(1, 1) <> 0: raise TestFailed, 'cmp(1, 1)'
4343

4444
print 'coerce'
45-
if coerce(1, 1.1) <> (1.0, 1.1): raise TestFailed, 'coerce(1, 1.1)'
45+
if fcmp(coerce(1, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1, 1.1)'
4646
if coerce(1, 1L) <> (1L, 1L): raise TestFailed, 'coerce(1, 1L)'
47-
if coerce(1L, 1.1) <> (1.0, 1.1): raise TestFailed, 'coerce(1L, 1.1)'
47+
if fcmp(coerce(1L, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1L, 1.1)'
4848

4949
print 'dir'
5050
x = 1
@@ -68,10 +68,14 @@ def f3(a1, a2, a3):
6868
if divmod(12L, -7) <> (-2L, -2): raise TestFailed, 'divmod(12L, -7)'
6969
if divmod(-12L, -7) <> (1L, -5): raise TestFailed, 'divmod(-12L, -7)'
7070
#
71-
if divmod(3.25, 1.0) <> (3.0, 0.25): raise TestFailed, 'divmod(3.25, 1.0)'
72-
if divmod(-3.25, 1.0) <> (-4.0, 0.75): raise TestFailed, 'divmod(-3.25, 1.0)'
73-
if divmod(3.25, -1.0) <> (-4.0, -0.75): raise TestFailed, 'divmod(3.25, -1.0)'
74-
if divmod(-3.25, -1.0) <> (3.0, -0.25): raise TestFailed, 'divmod(-3.25, -1.0)'
71+
if fcmp(divmod(3.25, 1.0), (3.0, 0.25)):
72+
raise TestFailed, 'divmod(3.25, 1.0)'
73+
if fcmp(divmod(-3.25, 1.0), (-4.0, 0.75)):
74+
raise TestFailed, 'divmod(-3.25, 1.0)'
75+
if fcmp(divmod(3.25, -1.0), (-4.0, -0.75)):
76+
raise TestFailed, 'divmod(3.25, -1.0)'
77+
if fcmp(divmod(-3.25, -1.0), (3.0, -0.25)):
78+
raise TestFailed, 'divmod(-3.25, -1.0)'
7579

7680
print 'eval'
7781
if eval('1+1') <> 2: raise TestFailed, 'eval(\'1+1\')'

Lib/test/test_b2.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@
7171
if pow(-2L,2) <> 4: raise TestFailed, 'pow(-2L,2)'
7272
if pow(-2L,3) <> -8: raise TestFailed, 'pow(-2L,3)'
7373
#
74-
if pow(0.,0) <> 1.: raise TestFailed, 'pow(0.,0)'
75-
if pow(0.,1) <> 0.: raise TestFailed, 'pow(0.,1)'
76-
if pow(1.,0) <> 1.: raise TestFailed, 'pow(1.,0)'
77-
if pow(1.,1) <> 1.: raise TestFailed, 'pow(1.,1)'
74+
if fcmp(pow(0.,0), 1.): raise TestFailed, 'pow(0.,0)'
75+
if fcmp(pow(0.,1), 0.): raise TestFailed, 'pow(0.,1)'
76+
if fcmp(pow(1.,0), 1.): raise TestFailed, 'pow(1.,0)'
77+
if fcmp(pow(1.,1), 1.): raise TestFailed, 'pow(1.,1)'
7878
#
79-
if pow(2.,0) <> 1.: raise TestFailed, 'pow(2.,0)'
80-
if pow(2.,10) <> 1024.: raise TestFailed, 'pow(2.,10)'
81-
if pow(2.,20) <> 1024.*1024.: raise TestFailed, 'pow(2.,20)'
82-
if pow(2.,30) <> 1024.*1024.*1024.: raise TestFailed, 'pow(2.,30)'
79+
if fcmp(pow(2.,0), 1.): raise TestFailed, 'pow(2.,0)'
80+
if fcmp(pow(2.,10), 1024.): raise TestFailed, 'pow(2.,10)'
81+
if fcmp(pow(2.,20), 1024.*1024.): raise TestFailed, 'pow(2.,20)'
82+
if fcmp(pow(2.,30), 1024.*1024.*1024.): raise TestFailed, 'pow(2.,30)'
8383
#
8484
# XXX These don't work -- negative float to the float power...
85-
#if pow(-2.,0) <> 1.: raise TestFailed, 'pow(-2.,0)'
86-
#if pow(-2.,1) <> -2.: raise TestFailed, 'pow(-2.,1)'
87-
#if pow(-2.,2) <> 4.: raise TestFailed, 'pow(-2.,2)'
88-
#if pow(-2.,3) <> -8.: raise TestFailed, 'pow(-2.,3)'
85+
#if fcmp(pow(-2.,0), 1.): raise TestFailed, 'pow(-2.,0)'
86+
#if fcmp(pow(-2.,1), -2.): raise TestFailed, 'pow(-2.,1)'
87+
#if fcmp(pow(-2.,2), 4.): raise TestFailed, 'pow(-2.,2)'
88+
#if fcmp(pow(-2.,3), -8.): raise TestFailed, 'pow(-2.,3)'
8989

9090
print 'range'
9191
if range(3) <> [0, 1, 2]: raise TestFailed, 'range(3)'

Lib/test/test_support.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,24 @@ def forget(modname):
1818
except os.error:
1919
pass
2020

21+
FUZZ = 1e-6
22+
23+
def fcmp(x, y): # fuzzy comparison function
24+
if type(x) == type(0.0) or type(y) == type(0.0):
25+
try:
26+
x, y = coerce(x, y)
27+
fuzz = (abs(x) + abs(y)) * FUZZ
28+
if abs(x-y) <= fuzz:
29+
return 0
30+
except:
31+
pass
32+
elif type(x) == type(y) and type(x) in (type(()), type([])):
33+
for i in range(min(len(x), len(y))):
34+
outcome = fcmp(x[i], y[i])
35+
if outcome <> 0:
36+
return outcome
37+
return cmp(len(x), len(y))
38+
return cmp(x, y)
39+
2140
TESTFN = '@test' # Filename used for testing
2241
from os import unlink

0 commit comments

Comments
 (0)