Skip to content

Commit 8264d49

Browse files
committed
[roottest] Remove code for testing with Python 2
Python 2 is not supported anymore for some time already.
1 parent 49a5dec commit 8264d49

File tree

9 files changed

+52
-111
lines changed

9 files changed

+52
-111
lines changed

roottest/python/basic/PyROOT_basictests.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,8 @@ def make_obj_str(s):
369369
l.sort()
370370
self.assertEqual( list(l), ['2', '4', '5', '6', '8', 'a', 'b', 'i', 'j'] )
371371

372-
if sys.hexversion >= 0x3000000:
373-
l.sort( key=TObjString.GetName )
374-
l.reverse()
375-
else:
376-
l.sort( lambda a, b: cmp(b.GetName(),a.GetName()) )
372+
l.sort( key=TObjString.GetName )
373+
l.reverse()
377374
self.assertEqual( list(l), ['j', 'i', 'b', 'a', '8', '6', '5', '4', '2'] )
378375

379376
l2 = l[:3]
@@ -387,15 +384,11 @@ def make_obj_str(s):
387384
l3 = l[6:8]
388385
self.assertEqual( list(l2+l3), ['j', 'i', 'b', '5', '4'] )
389386

390-
if sys.hexversion >= 0x3000000:
391-
next = '__next__'
392-
else:
393-
next = 'next'
394387
i = iter(l2)
395-
self.assertEqual( getattr( i, next )(), 'j' )
396-
self.assertEqual( getattr( i, next )(), 'i' )
397-
self.assertEqual( getattr( i, next )(), 'b' )
398-
self.assertRaises( StopIteration, getattr( i, next ) )
388+
self.assertEqual( getattr( i, "__next__" )(), 'j' )
389+
self.assertEqual( getattr( i, "__next__" )(), 'i' )
390+
self.assertEqual( getattr( i, "__next__" )(), 'b' )
391+
self.assertRaises( StopIteration, getattr( i, "__next__" ) )
399392

400393
def test3TVector( self ):
401394
"""Test TVector2/3/T behavior"""

roottest/python/cling/force_flush.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
from __future__ import print_function
22

3-
import sys
4-
53
def print_flushed(*args):
6-
if sys.hexversion < 0x3000000:
7-
return print(*args)
8-
else:
9-
return print(*args, flush=True)
4+
return print(*args, flush=True)

roottest/python/common.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,19 @@
99
import pytest
1010

1111

12-
if sys.hexversion >= 0x3000000:
13-
pylong = int
14-
maxvalue = sys.maxsize
15-
16-
class MyTestCase( unittest.TestCase ):
17-
def shortDescription( self ):
18-
desc = str(self)
19-
doc_first_line = None
20-
21-
if self._testMethodDoc:
22-
doc_first_line = self._testMethodDoc.split("\n")[0].strip()
23-
if doc_first_line:
24-
desc = doc_first_line
25-
return desc
26-
else:
27-
pylong = long
28-
maxvalue = sys.maxint
29-
30-
class MyTestCase( unittest.TestCase ):
31-
pass
12+
pylong = int
13+
maxvalue = sys.maxsize
14+
15+
class MyTestCase( unittest.TestCase ):
16+
def shortDescription( self ):
17+
desc = str(self)
18+
doc_first_line = None
19+
20+
if self._testMethodDoc:
21+
doc_first_line = self._testMethodDoc.split("\n")[0].strip()
22+
if doc_first_line:
23+
desc = doc_first_line
24+
return desc
3225

3326
FIXCLING = '--fixcling' in sys.argv
3427
if 'FIXCLING' in os.environ:

roottest/python/cpp/PyROOT_advancedtests.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,14 @@ def test2PassBuiltinsByNonConstRef( self ):
387387
SetDoubleThroughRef = ROOT.SetDoubleThroughRef
388388
SetIntThroughRef = ROOT.SetIntThroughRef
389389

390-
if sys.hexversion >= 0x2050000:
391-
import ctypes
392-
l = ctypes.c_long(42)
393-
SetLongThroughRef( l, 41 )
394-
self.assertEqual( l.value, 41 )
395-
396-
if sys.hexversion >= 0x2050000:
397-
i = ctypes.c_int(42)
398-
SetIntThroughRef( i, 13 )
399-
self.assertEqual( i.value, 13 )
390+
import ctypes
391+
l = ctypes.c_long(42)
392+
SetLongThroughRef( l, 41 )
393+
self.assertEqual( l.value, 41 )
394+
395+
i = ctypes.c_int(42)
396+
SetIntThroughRef( i, 13 )
397+
self.assertEqual( i.value, 13 )
400398

401399
def test3PassBuiltinsByNonConstRef( self ):
402400
"""Test parameter passing of builtins through const reference"""

roottest/python/memory/PyROOT_memorytests.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,16 @@
1919
'Memory1TestCase'
2020
]
2121

22-
if sys.hexversion >= 0x3000000:
23-
class MyTestCase( unittest.TestCase ):
24-
def shortDescription( self ):
25-
desc = str(self)
26-
doc_first_line = None
27-
28-
if self._testMethodDoc:
29-
doc_first_line = self._testMethodDoc.split("\n")[0].strip()
30-
if doc_first_line:
31-
desc = doc_first_line
32-
return desc
33-
else:
34-
class MyTestCase( unittest.TestCase ):
35-
pass
22+
class MyTestCase( unittest.TestCase ):
23+
def shortDescription( self ):
24+
desc = str(self)
25+
doc_first_line = None
26+
27+
if self._testMethodDoc:
28+
doc_first_line = self._testMethodDoc.split("\n")[0].strip()
29+
if doc_first_line:
30+
desc = doc_first_line
31+
return desc
3632

3733

3834
### Memory management test cases =============================================

roottest/python/pickle/common.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Created: 04/16/08
44
# Last: 09/24/10
55

6-
import sys, unittest
6+
import unittest
77

88
pclfn = "PyROOT_test.pcl"
99
cpclfn = "PyROOT_test.cpcl"
@@ -18,17 +18,13 @@
1818
Nvec = 12
1919
Mvec = 7
2020

21-
if sys.hexversion >= 0x3000000:
22-
class MyTestCase( unittest.TestCase ):
23-
def shortDescription( self ):
24-
desc = str(self)
25-
doc_first_line = None
21+
class MyTestCase( unittest.TestCase ):
22+
def shortDescription( self ):
23+
desc = str(self)
24+
doc_first_line = None
2625

27-
if self._testMethodDoc:
28-
doc_first_line = self._testMethodDoc.split("\n")[0].strip()
29-
if doc_first_line:
30-
desc = doc_first_line
31-
return desc
32-
else:
33-
class MyTestCase( unittest.TestCase ):
34-
pass
26+
if self._testMethodDoc:
27+
doc_first_line = self._testMethodDoc.split("\n")[0].strip()
28+
if doc_first_line:
29+
desc = doc_first_line
30+
return desc

roottest/python/regression/Amir.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import sys
2-
3-
# Note: ROOT does not support import * for Python 3.x
4-
# More info at https://sft.its.cern.ch/jira/browse/ROOT-8931
5-
6-
if sys.hexversion >= 0x3000000:
7-
from ROOT import TChain
8-
else:
9-
from ROOT import *
1+
from ROOT import TChain
102

113
class TestTChain:
124
def __init__( self ):

roottest/python/regression/PyROOT_regressiontests.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,6 @@ def test2ImportStyles( self ):
180180
if self.hasThread == self.noThread:
181181
cmd += " - -b"
182182

183-
# Do not test 'from ROOT import *' on Python 3.x, since it's not supported
184-
if sys.hexversion < 0x300000:
185-
stat, out = commands.getstatusoutput( cmd % "from ROOT import *" )
186-
self.assertEqual( WEXITSTATUS(stat), self.hasThread )
187-
188183
stat, out = commands.getstatusoutput( cmd % "from ROOT import gROOT" )
189184
self.assertEqual( WEXITSTATUS(stat), self.noThread )
190185

@@ -218,20 +213,6 @@ def test3SettingOfBatchMode( self ):
218213
cmd % 'from ROOT import PyConfig; PyConfig.StartGuiThread = 1; from ROOT import gDebug;' )
219214
self.assertEqual( WEXITSTATUS(stat), self.hasThread )
220215

221-
# Do not test 'from ROOT import *' on Python 3.x, since it's not supported
222-
if sys.hexversion < 0x300000:
223-
stat, out = commands.getstatusoutput( (cmd % 'from ROOT import *;') + ' - -b' )
224-
self.assertEqual( WEXITSTATUS(stat), self.noThread )
225-
226-
stat, out = commands.getstatusoutput(
227-
cmd % 'from ROOT import gROOT; gROOT.SetBatch( 1 ); from ROOT import *;' )
228-
self.assertEqual( WEXITSTATUS(stat), self.noThread )
229-
230-
if not gROOT.IsBatch(): # can't test if no display ...
231-
stat, out = commands.getstatusoutput(
232-
cmd % 'from ROOT import gROOT; gROOT.SetBatch( 0 ); from ROOT import *;' )
233-
self.assertEqual( WEXITSTATUS(stat), self.hasThread )
234-
235216
# Restore the cleaned LD_PRELOAD for other tests
236217
if cleaned_preload is not None:
237218
os.environ['LD_PRELOAD'] = cleaned_preload

roottest/python/stl/PyROOT_stltests.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,9 @@ def __run_tests(self, container):
410410
b1, e1 = container.begin(), container.end()
411411
b2, e2 = container.begin(), container.end()
412412

413-
if sys.hexversion >= 0x3000000:
414-
def pr_cmp(a, b):
415-
if a == b: return 0
416-
return 1
417-
else:
418-
pr_cmp = cmp
413+
def pr_cmp(a, b):
414+
if a == b: return 0
415+
return 1
419416

420417
assert b1.__eq__(b2)
421418
assert not b1.__ne__(b2)

0 commit comments

Comments
 (0)