Skip to content

Commit 8dd19a9

Browse files
author
Davies Liu
committed
fix tests in python 2.6
1 parent 35ccb9f commit 8dd19a9

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

python/pyspark/sql_tests.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@
2020
individual modules.
2121
"""
2222
import os
23+
import sys
2324
import pydoc
2425
import shutil
2526
import tempfile
26-
import unittest
27+
28+
if sys.version_info[:2] <= (2, 6):
29+
try:
30+
import unittest2 as unittest
31+
except ImportError:
32+
sys.stderr.write('Please install unittest2 to test with Python 2.6 or earlier')
33+
sys.exit(1)
34+
else:
35+
import unittest
2736

2837
from pyspark.sql import SQLContext, IntegerType, Row, ArrayType, StructType, StructField, \
2938
UserDefinedType, DoubleType
@@ -83,18 +92,16 @@ def setUpClass(cls):
8392
ReusedPySparkTestCase.setUpClass()
8493
cls.tempdir = tempfile.NamedTemporaryFile(delete=False)
8594
os.unlink(cls.tempdir.name)
95+
cls.sqlCtx = SQLContext(cls.sc)
96+
cls.testData = [Row(key=i, value=str(i)) for i in range(100)]
97+
rdd = cls.sc.parallelize(cls.testData)
98+
cls.df = cls.sqlCtx.inferSchema(rdd)
8699

87100
@classmethod
88101
def tearDownClass(cls):
89102
ReusedPySparkTestCase.tearDownClass()
90103
shutil.rmtree(cls.tempdir.name, ignore_errors=True)
91104

92-
def setUp(self):
93-
self.sqlCtx = SQLContext(self.sc)
94-
self.testData = [Row(key=i, value=str(i)) for i in range(100)]
95-
rdd = self.sc.parallelize(self.testData)
96-
self.df = self.sqlCtx.inferSchema(rdd)
97-
98105
def test_udf(self):
99106
self.sqlCtx.registerFunction("twoArgs", lambda x, y: len(x) + y, IntegerType())
100107
[row] = self.sqlCtx.sql("SELECT twoArgs('test', 1)").collect()

python/pyspark/tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from fileinput import input
2424
from glob import glob
2525
import os
26-
import pydoc
2726
import re
2827
import shutil
2928
import subprocess

0 commit comments

Comments
 (0)