Skip to content

Commit c6e0811

Browse files
committed
style issues
1 parent 9cc545b commit c6e0811

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

python/pyspark/accumulators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def authenticate_and_accum_updates():
262262
raise Exception(
263263
"The value of the provided token to the AccumulatorServer is not correct.")
264264

265-
if auth_token:
265+
if auth_token is not None:
266266
# first we keep polling till we've received the authentication token
267267
poll(authenticate_and_accum_updates)
268268
# now we've authenticated if needed, don't need to check for the token anymore

python/pyspark/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def __init__(self, master=None, appName=None, sparkHome=None, pyFiles=None,
119119
"You are passing in an insecure Py4j gateway. This "
120120
"presents a security risk, and will be completely forbidden in Spark 3.0")
121121
else:
122-
raise Exception(
122+
raise ValueError(
123123
"You are trying to pass an insecure Py4j gateway to Spark. This"
124124
" presents a security risk. If you are sure you understand and accept this"
125125
" risk, you can set the environment variable"

python/pyspark/java_gateway.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def _launch_gateway(conf=None, insecure=False):
5353
:param insecure: True to create an insecure gateway; only for testing
5454
:return: a JVM gateway
5555
"""
56-
if insecure and not os.environ.get("SPARK_TESTING", "0") == "1":
57-
raise Exception("creating insecure gateways is only for testing")
56+
if insecure and os.environ.get("SPARK_TESTING", "0") != "1":
57+
raise ValueError("creating insecure gateways is only for testing")
5858
if "PYSPARK_GATEWAY_PORT" in os.environ:
5959
gateway_port = int(os.environ["PYSPARK_GATEWAY_PORT"])
6060
gateway_secret = os.environ["PYSPARK_GATEWAY_SECRET"]

python/pyspark/tests.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,11 +2386,17 @@ def test_forbid_insecure_gateway(self):
23862386
# By default, we fail immediately if you try to create a SparkContext
23872387
# with an insecure gateway
23882388
gateway = _launch_gateway(insecure=True)
2389-
with self.assertRaises(Exception) as context:
2390-
SparkContext(gateway=gateway)
2391-
self.assertIn("insecure Py4j gateway", str(context.exception))
2392-
self.assertIn("PYSPARK_ALLOW_INSECURE_GATEWAY", str(context.exception))
2393-
self.assertIn("removed in Spark 3.0", str(context.exception))
2389+
log4j = gateway.jvm.org.apache.log4j
2390+
old_level = log4j.LogManager.getRootLogger().getLevel()
2391+
try:
2392+
log4j.LogManager.getRootLogger().setLevel(log4j.Level.FATAL)
2393+
with self.assertRaises(Exception) as context:
2394+
SparkContext(gateway=gateway)
2395+
self.assertIn("insecure Py4j gateway", str(context.exception))
2396+
self.assertIn("PYSPARK_ALLOW_INSECURE_GATEWAY", str(context.exception))
2397+
self.assertIn("removed in Spark 3.0", str(context.exception))
2398+
finally:
2399+
log4j.LogManager.getRootLogger().setLevel(old_level)
23942400

23952401
def test_allow_insecure_gateway_with_conf(self):
23962402
with SparkContext._lock:
@@ -2400,7 +2406,6 @@ def test_allow_insecure_gateway_with_conf(self):
24002406
try:
24012407
os.environ["PYSPARK_ALLOW_INSECURE_GATEWAY"] = "1"
24022408
with SparkContext(gateway=gateway) as sc:
2403-
print("sc created, about to create accum")
24042409
a = sc.accumulator(1)
24052410
rdd = sc.parallelize([1, 2, 3])
24062411
rdd.foreach(lambda x: a.add(x))

0 commit comments

Comments
 (0)