Skip to content

Commit 8ed996e

Browse files
authored
Use py3 compatible syntax in tests (#591)
1 parent 89f47de commit 8ed996e

4 files changed

Lines changed: 80 additions & 95 deletions

File tree

Tests/modules/io_related/test__bytesio.py

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import unittest
1111

1212
from _io import BytesIO
13+
1314
from iptest import run_test
1415

1516
def bytesio_helper():
@@ -28,131 +29,129 @@ def bytesio_helper():
2829
class BytesIOTest(unittest.TestCase):
2930

3031
def test__BytesIO___class__(self):
31-
print "TODO"
32+
print("TODO")
3233

3334
def test__BytesIO___delattr__(self):
34-
print "TODO"
35+
print("TODO")
3536

3637
def test__BytesIO___doc__(self):
37-
print "TODO"
38+
print("TODO")
3839

3940
def test__BytesIO___format__(self):
40-
print "TODO"
41+
print("TODO")
4142

4243
def test__BytesIO___getattribute__(self):
43-
print "TODO"
44+
print("TODO")
4445

4546
def test__BytesIO___hash__(self):
46-
print "TODO"
47+
print("TODO")
4748

4849
def test__BytesIO___init__(self):
49-
print "TODO"
50+
print("TODO")
5051

5152
def test__BytesIO___iter__(self):
52-
print "TODO"
53+
print("TODO")
5354

5455
def test__BytesIO___new__(self):
55-
print "TODO"
56+
print("TODO")
5657

5758
def test__BytesIO___reduce__(self):
58-
print "TODO"
59+
print("TODO")
5960

6061
def test__BytesIO___reduce_ex__(self):
61-
print "TODO"
62+
print("TODO")
6263

6364
def test__BytesIO___repr__(self):
64-
print "TODO"
65+
print("TODO")
6566

6667
def test__BytesIO___setattr__(self):
67-
print "TODO"
68+
print("TODO")
6869

6970
def test__BytesIO___sizeof__(self):
70-
print "TODO"
71+
print("TODO")
7172

7273
def test__BytesIO___str__(self):
73-
print "TODO"
74+
print("TODO")
7475

7576
def test__BytesIO___subclasshook__(self):
76-
print "TODO"
77+
print("TODO")
7778

7879
def test__BytesIO_close(self):
79-
print "TODO"
80+
print("TODO")
8081

8182
def test__BytesIO_closed(self):
82-
print "TODO"
83+
print("TODO")
8384

8485
def test__BytesIO_flush(self):
85-
print "TODO"
86+
print("TODO")
8687

8788
def test__BytesIO_getvalue(self):
88-
print "TODO"
89+
print("TODO")
8990

9091
def test__BytesIO_isatty(self):
91-
print "TODO"
92+
print("TODO")
9293

9394
def test__BytesIO_next(self):
94-
print "TODO"
95+
print("TODO")
9596

9697
def test__BytesIO_read(self):
97-
print "TODO"
98+
print("TODO")
9899

99100
def test__BytesIO_read1(self):
100-
print "TODO"
101+
print("TODO")
101102

102103
def test__BytesIO_readable(self):
103-
print "TODO"
104+
print("TODO")
104105

105106
def test__BytesIO_readinto(self):
106-
print "TODO"
107+
print("TODO")
107108

108109
def test__BytesIO_readline(self):
109-
print "TODO"
110+
print("TODO")
110111

111112
def test__BytesIO_readlines(self):
112-
print "TODO"
113+
print("TODO")
113114

114115
def test__BytesIO_seek(self):
115-
# TODO: add cases that seek
116116
x = BytesIO()
117117

118118
# these should all succeed
119119
x.seek(0)
120-
x.seek(0L)
120+
x.seek(long(0))
121121
x.seek(0, 0)
122-
x.seek(0L, 0)
123-
x.seek(0, 0L)
124-
x.seek(0L, 0L)
122+
x.seek(long(0), 0)
123+
x.seek(0, long(0))
124+
x.seek(long(0), long(0))
125125

126126
# these should all fail
127127
self.assertRaises(TypeError, x.seek, 0, 0.0)
128-
self.assertRaises(TypeError, x.seek, 0L, 0.0)
128+
self.assertRaises(TypeError, x.seek, long(0), 0.0)
129129
self.assertRaises(ValueError, x.seek, 0, 1000)
130-
self.assertRaises(ValueError, x.seek, 0L, 1000)
130+
self.assertRaises(ValueError, x.seek, long(0), 1000)
131131
self.assertRaises(OverflowError, x.seek, 0, sys.maxsize+1)
132-
self.assertRaises(OverflowError, x.seek, 0L, sys.maxsize+1)
132+
self.assertRaises(OverflowError, x.seek, long(0), sys.maxsize+1)
133133
self.assertRaises(TypeError, x.seek, 0.0)
134134
self.assertRaises(TypeError, x.seek, 0.0, 0)
135135
self.assertRaises(OverflowError, x.seek, sys.maxsize+1)
136136
self.assertRaises(OverflowError, x.seek, sys.maxsize+1, 0)
137137

138138
def test__BytesIO_seekable(self):
139-
print "TODO"
139+
print("TODO")
140140

141141
def test__BytesIO_tell(self):
142-
print "TODO"
142+
print("TODO")
143143

144144
def test__BytesIO_truncate(self):
145-
print "TODO"
145+
print("TODO")
146146

147147
def test__BytesIO_writable(self):
148-
print "TODO"
148+
print("TODO")
149149

150150
def test__BytesIO_write(self):
151-
print "TODO"
151+
print("TODO")
152152

153153
def test__BytesIO_writelines(self):
154-
print "TODO"
155-
154+
print("TODO")
156155

157156
def test_coverage(self):
158157
'''
@@ -254,11 +253,11 @@ def test_coverage(self):
254253
[('I',),
255254
[[],[],[],[],[],[],[],[],[],[]],
256255
[0,0,0,0,0,0,0,0,0,0]],
257-
[('I',[1L]),
258-
[[1L],[97L],[25185L],[6513249L],[1684234849L],[1684234849L],[1684234849L],[1684234849L],[1684234849L],[1684234849L]],
256+
[('I',[long(1)]),
257+
[[long(1)],[long(97)],[long(25185)],[long(6513249)],[long(1684234849)],[long(1684234849)],[long(1684234849)],[long(1684234849)],[long(1684234849)],[long(1684234849)]],
259258
[0,1,2,3,4,4,4,4,4,4]],
260-
[('I',[1L,999L,47L]),
261-
[[1L,999L,47L],[97L,999L,47L],[25185L,999L,47L],[6513249L,999L,47L],[1684234849L,999L,47L],[1684234849L,869L,47L],[1684234849L,26213L,47L],[1684234849L,6776421L,47L],[1684234849L,1751606885L,47L],[1684234849L,1751606885L,105L]],
259+
[('I',[long(1),long(999),long(47)]),
260+
[[long(1),long(999),long(47)],[long(97),long(999),long(47)],[long(25185),long(999),long(47)],[long(6513249),long(999),long(47)],[long(1684234849),long(999),long(47)],[long(1684234849),long(869),long(47)],[long(1684234849),long(26213),long(47)],[long(1684234849),long(6776421),long(47)],[long(1684234849),long(1751606885),long(47)],[long(1684234849),long(1751606885),long(105)]],
262261
[0,1,2,3,4,5,6,7,8,9]],
263262
[('l',),
264263
[[],[],[],[],[],[],[],[],[],[]],
@@ -278,11 +277,11 @@ def test_coverage(self):
278277
[('L',),
279278
[[],[],[],[],[],[],[],[],[],[]],
280279
[0,0,0,0,0,0,0,0,0,0]],
281-
[('L',[100000000L]),
282-
[[100000000L],[100000097L],[99967585L],[90399329L],[1684234849L],[1684234849L],[1684234849L],[1684234849L],[1684234849L],[1684234849L]],
280+
[('L',[long(100000000)]),
281+
[[long(100000000)],[long(100000097)],[long(99967585)],[long(90399329)],[long(1684234849)],[long(1684234849)],[long(1684234849)],[long(1684234849)],[long(1684234849)],[long(1684234849)]],
283282
[0,1,2,3,4,4,4,4,4,4]],
284-
[('L',[1L,99L,47L]),
285-
[[1L,99L,47L],[97L,99L,47L],[25185L,99L,47L],[6513249L,99L,47L],[1684234849L,99L,47L],[1684234849L,101L,47L],[1684234849L,26213L,47L],[1684234849L,6776421L,47L],[1684234849L,1751606885L,47L],[1684234849L,1751606885L,105L]],
283+
[('L',[long(1),long(99),long(47)]),
284+
[[long(1),long(99),long(47)],[long(97),long(99),long(47)],[long(25185),long(99),long(47)],[long(6513249),long(99),long(47)],[long(1684234849),long(99),long(47)],[long(1684234849),long(101),long(47)],[long(1684234849),long(26213),long(47)],[long(1684234849),long(6776421),long(47)],[long(1684234849),long(1751606885),long(47)],[long(1684234849),long(1751606885),long(105)]],
286285
[0,1,2,3,4,5,6,7,8,9]],
287286
[('f',[]),
288287
[[],[],[],[],[],[],[],[],[],[]],

Tests/modules/io_related/test_binascii.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
# See the LICENSE file in the project root for more information.
44

5-
65
##
76
## Test the binascii module
87
##
@@ -12,7 +11,6 @@
1211

1312
from iptest import run_test, skipUnlessIronPython
1413

15-
1614
class BinasciiTest(unittest.TestCase):
1715
def test_negative(self):
1816
"""verify extra characters are ignored, and that we require padding."""

Tests/modules/io_related/test_io_StringIO.py

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
#####################################################################################
2-
#
3-
# Copyright (c) IronPython Team. All rights reserved.
4-
#
5-
# This source code is subject to terms and conditions of the Apache License, Version 2.0. A
6-
# copy of the license can be found in the License.html file at the root of this distribution. If
7-
# you cannot locate the Apache License, Version 2.0, please send an email to
8-
# ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
9-
# by the terms of the Apache License, Version 2.0.
10-
#
11-
# You must not remove this notice, or any other, from this software.
12-
#
13-
#
14-
#####################################################################################
1+
# Licensed to the .NET Foundation under one or more agreements.
2+
# The .NET Foundation licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information.
154

165
##
176
## Test the io.StringIO
@@ -20,7 +9,7 @@
209

2110
import unittest
2211

23-
import io as cStringIO
12+
import io
2413

2514
from iptest import run_test
2615

@@ -97,8 +86,8 @@ def call_getvalue(self, i):
9786
# __iter__, next
9887
def call_next(self, i):
9988
self.assertEqual(i.__iter__(), i)
100-
self.assertEqual(i.next(), "Line 1\n")
101-
self.assertEqual(i.next(), "Line 2\n")
89+
self.assertEqual(next(i), "Line 1\n")
90+
self.assertEqual(next(i), "Line 2\n")
10291
self.assertEqual([l for l in i], ["Line 3\n", "Line 4\n", "Line 5"])
10392
i.close()
10493
self.assertRaises(ValueError, i.readlines)
@@ -208,16 +197,16 @@ def call_flush(self, i):
208197
self.assertEqual(i,i)
209198

210199
def init_StringI(self):
211-
return cStringIO.StringIO(text)
200+
return io.StringIO(text)
212201

213202
def init_StringO(self):
214-
o = cStringIO.StringIO()
203+
o = io.StringIO()
215204
o.write(text)
216205
o.seek(0)
217206
return o
218207

219208
def init_emptyStringI(self):
220-
return cStringIO.StringIO("")
209+
return io.StringIO("")
221210

222211
def test_empty(self):
223212
i = self.init_emptyStringI()
@@ -302,7 +291,7 @@ def test_empty(self):
302291
def test_cp8567(self):
303292
for x in ["", "1", "12", "12345"]:
304293
for i in [5, 6, 7, 2**8, 100, 2**16-1, 2**16, 2**16, 2**31-2, 2**31-1]:
305-
cio = cStringIO.StringIO(x)
294+
cio = io.StringIO(x)
306295
# make sure it doesn't thorow and it doesn't change seek position
307296
cio.truncate(i)
308297
self.assertEqual(cio.tell(), 0)
@@ -336,7 +325,7 @@ def test_o(self):
336325
t(o)
337326

338327
def test_cp22017(self):
339-
m = cStringIO.StringIO()
328+
m = io.StringIO()
340329
m.seek(2)
341330
m.write("hello!")
342331
self.assertEqual(m.getvalue(), '\x00\x00hello!')
@@ -346,19 +335,19 @@ def test_cp22017(self):
346335
# tests from Jeffrey Bester, cp34683
347336
def test_read(self):
348337
# test stringio is readable
349-
with cStringIO.StringIO("hello world\r\n") as infile:
338+
with io.StringIO("hello world\r\n") as infile:
350339
self.assertSequenceEqual(infile.readline(), "hello world\r\n")
351340

352341
def test_seekable(self):
353342
# test stringio is seekable
354-
with cStringIO.StringIO("hello") as infile:
343+
with io.StringIO("hello") as infile:
355344
infile.seek(0, 2)
356345
infile.write(" world\r\n")
357346
self.assertSequenceEqual(infile.getvalue(), "hello world\r\n")
358347

359348
def test_write(self):
360349
# test stringio is writable
361-
with cStringIO.StringIO() as output_file:
350+
with io.StringIO() as output_file:
362351
output_file.write("hello")
363352
output_file.write(" world\n")
364353
self.assertSequenceEqual(output_file.getvalue(), "hello world\n")
@@ -367,9 +356,9 @@ def test_write(self):
367356
def test_redirect(self):
368357
import sys
369358
stdout_save = sys.stdout
370-
capture = cStringIO.StringIO()
359+
capture = io.StringIO()
371360
sys.stdout = capture
372-
print "Testing"
361+
print("Testing")
373362
sys.stdout = stdout_save
374363
self.assertEqual(capture.getvalue(), "Testing\n")
375364

0 commit comments

Comments
 (0)