Skip to content

Commit c135495

Browse files
committed
Fix Python 3 test error.
1 parent a1a7a10 commit c135495

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

tests/testspec.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
import math
1919
import sys
2020
import unittest
21-
import urllib2
21+
try:
22+
from urllib2 import urlopen
23+
except ImportError:
24+
from urllib.request import urlopen
2225

2326
from histogrammar import *
2427
import histogrammar.version
@@ -44,12 +47,12 @@ def compare(self, x, y, name):
4447
def runTest(self):
4548
sys.stdout.write("Downloading expected results, generated by specification {0}...\n".format(histogrammar.version.specification))
4649
try:
47-
testdata = json.load(urllib2.urlopen("http://histogrammar.org/test/{0}/test-data.json".format(histogrammar.version.specification)))
50+
testdata = json.load(urlopen("http://histogrammar.org/test/{0}/test-data.json".format(histogrammar.version.specification)))
4851
except Exception as err:
4952
sys.stdout.write("could not download http://histogrammar.org/test/{0}/test-data.json\nbecause of {1}: {2}\n".format(histogrammar.version.specification, err.__class__.__name__, str(err)))
5053
return
5154
try:
52-
testresults = json.load(urllib2.urlopen("http://histogrammar.org/test/{0}/test-results.json".format(histogrammar.version.specification)))
55+
testresults = json.load(urlopen("http://histogrammar.org/test/{0}/test-results.json".format(histogrammar.version.specification)))
5356
except Exception as err:
5457
sys.stdout.write("could not download http://histogrammar.org/test/{0}/test-results.jsonbecause of {1}: {2}\n\n".format(histogrammar.version.specification, err.__class__.__name__, str(err)))
5558
return

0 commit comments

Comments
 (0)