Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aaa2f1d

Browse files
committed
Patch #1276356: Implement new resource "urlfetch" for regrtest.
This enables even impatient people to run tests that require remote files such as test_normalization and test_codecmaps_*.
1 parent 432be36 commit aaa2f1d

10 files changed

Lines changed: 29 additions & 74 deletions

Lib/test/regrtest.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
9898
subprocess Run all tests for the subprocess module.
9999
100+
urlfetch - It is okay to download files required on testing.
101+
100102
To enable all resources except one, use '-uall,-<resource>'. For
101103
example, to run all the tests except for the bsddb tests, give the
102104
option '-uall,-bsddb'.
@@ -140,7 +142,7 @@
140142
from test import test_support
141143

142144
RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb',
143-
'decimal', 'compiler', 'subprocess')
145+
'decimal', 'compiler', 'subprocess', 'urlfetch')
144146

145147

146148
def usage(code, msg=''):
@@ -671,20 +673,12 @@ def printlist(x, width=70, indent=4):
671673
# test_pep277
672674
# The _ExpectedSkips constructor adds this to the set of expected
673675
# skips if not os.path.supports_unicode_filenames.
674-
# test_normalization
675-
# Whether a skip is expected here depends on whether a large test
676-
# input file has been downloaded. test_normalization.skip_expected
677-
# controls that.
678676
# test_socket_ssl
679677
# Controlled by test_socket_ssl.skip_expected. Requires the network
680678
# resource, and a socket module with ssl support.
681679
# test_timeout
682680
# Controlled by test_timeout.skip_expected. Requires the network
683681
# resource and a socket module.
684-
# test_codecmaps_*
685-
# Whether a skip is expected here depends on whether a large test
686-
# input file has been downloaded. test_codecmaps_*.skip_expected
687-
# controls that.
688682

689683
_expectations = {
690684
'win32':
@@ -1056,7 +1050,6 @@ def printlist(x, width=70, indent=4):
10561050
test_macfs
10571051
test_macostools
10581052
test_nis
1059-
test_normalization
10601053
test_ossaudiodev
10611054
test_pep277
10621055
test_plistlib
@@ -1108,12 +1101,8 @@ def printlist(x, width=70, indent=4):
11081101
class _ExpectedSkips:
11091102
def __init__(self):
11101103
import os.path
1111-
from test import test_normalization
11121104
from test import test_socket_ssl
11131105
from test import test_timeout
1114-
from test import test_codecmaps_cn, test_codecmaps_jp
1115-
from test import test_codecmaps_kr, test_codecmaps_tw
1116-
from test import test_codecmaps_hk
11171106

11181107
self.valid = False
11191108
if sys.platform in _expectations:
@@ -1126,19 +1115,12 @@ def __init__(self):
11261115
if not os.path.supports_unicode_filenames:
11271116
self.expected.add('test_pep277')
11281117

1129-
if test_normalization.skip_expected:
1130-
self.expected.add('test_normalization')
1131-
11321118
if test_socket_ssl.skip_expected:
11331119
self.expected.add('test_socket_ssl')
11341120

11351121
if test_timeout.skip_expected:
11361122
self.expected.add('test_timeout')
11371123

1138-
for cc in ('cn', 'jp', 'kr', 'tw', 'hk'):
1139-
if eval('test_codecmaps_' + cc).skip_expected:
1140-
self.expected.add('test_codecmaps_' + cc)
1141-
11421124
if sys.maxint == 9223372036854775807L:
11431125
self.expected.add('test_rgbimg')
11441126
self.expected.add('test_imageop')

Lib/test/test_codecmaps_cn.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
class TestGB2312Map(test_multibytecodec_support.TestBase_Mapping,
1313
unittest.TestCase):
1414
encoding = 'gb2312'
15-
mapfilename = 'EUC-CN.TXT'
1615
mapfileurl = 'http://people.freebsd.org/~perky/i18n/EUC-CN.TXT'
1716

1817
class TestGBKMap(test_multibytecodec_support.TestBase_Mapping,
1918
unittest.TestCase):
2019
encoding = 'gbk'
21-
mapfilename = 'CP936.TXT'
2220
mapfileurl = 'http://www.unicode.org/Public/MAPPINGS/VENDORS/' \
2321
'MICSFT/WINDOWS/CP936.TXT'
2422

@@ -28,6 +26,5 @@ def test_main():
2826
suite.addTest(unittest.makeSuite(TestGBKMap))
2927
test_support.run_suite(suite)
3028

31-
test_multibytecodec_support.register_skip_expected(TestGB2312Map, TestGBKMap)
3229
if __name__ == "__main__":
3330
test_main()

Lib/test/test_codecmaps_hk.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
class TestBig5HKSCSMap(test_multibytecodec_support.TestBase_Mapping,
1313
unittest.TestCase):
1414
encoding = 'big5hkscs'
15-
mapfilename = 'BIG5HKSCS.TXT'
1615
mapfileurl = 'http://people.freebsd.org/~perky/i18n/BIG5HKSCS.TXT'
1716

1817
def test_main():
1918
suite = unittest.TestSuite()
2019
suite.addTest(unittest.makeSuite(TestBig5HKSCSMap))
2120
test_support.run_suite(suite)
2221

23-
test_multibytecodec_support.register_skip_expected(TestBig5HKSCSMap)
2422
if __name__ == "__main__":
2523
test_main()

Lib/test/test_codecmaps_jp.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
class TestCP932Map(test_multibytecodec_support.TestBase_Mapping,
1313
unittest.TestCase):
1414
encoding = 'cp932'
15-
mapfilename = 'CP932.TXT'
1615
mapfileurl = 'http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/' \
1716
'WINDOWS/CP932.TXT'
1817
supmaps = [
@@ -71,9 +70,5 @@ def test_main():
7170
suite.addTest(unittest.makeSuite(TestSJISX0213Map))
7271
test_support.run_suite(suite)
7372

74-
test_multibytecodec_support.register_skip_expected(TestCP932Map,
75-
TestEUCJPCOMPATMap, TestSJISCOMPATMap, TestEUCJISX0213Map,
76-
TestSJISX0213Map)
77-
7873
if __name__ == "__main__":
7974
test_main()

Lib/test/test_codecmaps_kr.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@
1212
class TestCP949Map(test_multibytecodec_support.TestBase_Mapping,
1313
unittest.TestCase):
1414
encoding = 'cp949'
15-
mapfilename = 'CP949.TXT'
1615
mapfileurl = 'http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT' \
1716
'/WINDOWS/CP949.TXT'
1817

1918

2019
class TestEUCKRMap(test_multibytecodec_support.TestBase_Mapping,
2120
unittest.TestCase):
2221
encoding = 'euc_kr'
23-
mapfilename = 'EUC-KR.TXT'
2422
mapfileurl = 'http://people.freebsd.org/~perky/i18n/EUC-KR.TXT'
2523

2624

2725
class TestJOHABMap(test_multibytecodec_support.TestBase_Mapping,
2826
unittest.TestCase):
2927
encoding = 'johab'
30-
mapfilename = 'JOHAB.TXT'
3128
mapfileurl = 'http://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/' \
3229
'KSC/JOHAB.TXT'
3330
# KS X 1001 standard assigned 0x5c as WON SIGN.
@@ -44,7 +41,5 @@ def test_main():
4441
suite.addTest(unittest.makeSuite(TestJOHABMap))
4542
test_support.run_suite(suite)
4643

47-
test_multibytecodec_support.register_skip_expected(TestCP949Map,
48-
TestEUCKRMap, TestJOHABMap)
4944
if __name__ == "__main__":
5045
test_main()

Lib/test/test_codecmaps_tw.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
class TestBIG5Map(test_multibytecodec_support.TestBase_Mapping,
1313
unittest.TestCase):
1414
encoding = 'big5'
15-
mapfilename = 'BIG5.TXT'
1615
mapfileurl = 'http://www.unicode.org/Public/MAPPINGS/OBSOLETE/' \
1716
'EASTASIA/OTHER/BIG5.TXT'
1817

1918
class TestCP950Map(test_multibytecodec_support.TestBase_Mapping,
2019
unittest.TestCase):
2120
encoding = 'cp950'
22-
mapfilename = 'CP950.TXT'
2321
mapfileurl = 'http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/' \
2422
'WINDOWS/CP950.TXT'
2523
pass_enctest = [
@@ -33,6 +31,5 @@ def test_main():
3331
suite.addTest(unittest.makeSuite(TestCP950Map))
3432
test_support.run_suite(suite)
3533

36-
test_multibytecodec_support.register_skip_expected(TestBIG5Map, TestCP950Map)
3734
if __name__ == "__main__":
3835
test_main()

Lib/test/test_multibytecodec_support.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,16 @@ class TestBase_Mapping(unittest.TestCase):
163163

164164
def __init__(self, *args, **kw):
165165
unittest.TestCase.__init__(self, *args, **kw)
166-
if not os.path.exists(self.mapfilename):
167-
raise test_support.TestSkipped('%s not found, download from %s' %
168-
(self.mapfilename, self.mapfileurl))
166+
self.open_mapping_file() # test it to report the error early
167+
168+
def open_mapping_file(self):
169+
return test_support.open_urlresource(self.mapfileurl)
169170

170171
def test_mapping_file(self):
171172
unichrs = lambda s: u''.join(map(unichr, map(eval, s.split('+'))))
172173
urt_wa = {}
173174

174-
for line in open(self.mapfilename):
175+
for line in self.open_mapping_file():
175176
if not line:
176177
break
177178
data = line.split('#')[0].strip().split()
@@ -217,16 +218,3 @@ def load_teststring(encoding):
217218
else:
218219
from test import cjkencodings_test
219220
return cjkencodings_test.teststring[encoding]
220-
221-
def register_skip_expected(*cases):
222-
for case in cases: # len(cases) must be 1 at least.
223-
for path in [os.path.curdir, os.path.pardir]:
224-
fn = os.path.join(path, case.mapfilename)
225-
if os.path.exists(fn):
226-
case.mapfilename = fn
227-
break
228-
else:
229-
sys.modules[case.__module__].skip_expected = True
230-
break
231-
else:
232-
sys.modules[case.__module__].skip_expected = False

Lib/test/test_normalization.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
from test.test_support import verbose, TestFailed, TestSkipped, verify
1+
from test.test_support import (verbose, TestFailed, TestSkipped, verify,
2+
open_urlresource)
23
import sys
34
import os
45
from unicodedata import normalize
56

67
TESTDATAFILE = "NormalizationTest-3.2.0" + os.extsep + "txt"
7-
8-
# This search allows using a build directory just inside the source
9-
# directory, and saving just one copy of the test data in the source
10-
# tree, rather than having a copy in each build directory.
11-
# There might be a better way to do this.
12-
13-
for path in [os.path.curdir, os.path.pardir]:
14-
fn = os.path.join(path, TESTDATAFILE)
15-
skip_expected = not os.path.exists(fn)
16-
if not skip_expected:
17-
TESTDATAFILE = fn
18-
break
8+
TESTDATAURL = "http://www.unicode.org/Public/3.2-Update/" + TESTDATAFILE
199

2010
class RangeError:
2111
pass
@@ -40,12 +30,8 @@ def unistr(data):
4030
return u"".join([unichr(x) for x in data])
4131

4232
def test_main():
43-
if skip_expected:
44-
raise TestSkipped(TESTDATAFILE + " not found, download from " +
45-
"http://www.unicode.org/Public/3.2-Update/" + TESTDATAFILE)
46-
4733
part1_data = {}
48-
for line in open(TESTDATAFILE):
34+
for line in open_urlresource(TESTDATAURL):
4935
if '#' in line:
5036
line = line.split('#')[0]
5137
line = line.strip()

Lib/test/test_support.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,21 @@ def check_syntax(statement):
237237
else:
238238
print 'Missing SyntaxError: "%s"' % statement
239239

240+
def open_urlresource(url):
241+
import urllib, urlparse
242+
import os.path
240243

244+
filename = urlparse.urlparse(url)[2].split('/')[-1] # '/': it's URL!
245+
246+
for path in [os.path.curdir, os.path.pardir]:
247+
fn = os.path.join(path, filename)
248+
if os.path.exists(fn):
249+
return open(fn)
250+
251+
requires('urlfetch')
252+
print >> get_original_stdout(), '\tfetching %s ...' % url
253+
fn, _ = urllib.urlretrieve(url, filename)
254+
return open(fn)
241255

242256
#=======================================================================
243257
# Preliminary PyUNIT integration.

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@ Tests
633633

634634
- In test_os, st_?time is now truncated before comparing it with ST_?TIME.
635635

636+
- Patch #1276356: New resource "urlfetch" is implemented. This enables
637+
even impatient people to run tests that require remote files.
638+
636639

637640
Documentation
638641
-------------

0 commit comments

Comments
 (0)