Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Doc/library/base64.rst
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ Refer to the documentation of the individual functions for more information.
*adobe* controls whether the input sequence is in Adobe Ascii85 format
(i.e. is framed with <~ and ~>).

*ignorechars* should be a :term:`bytes-like object` or ASCII string
containing characters to ignore
*ignorechars* should be a byte string containing characters to ignore
from the input. This should only contain whitespace characters, and by
default contains all whitespace characters in ASCII.

Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,19 @@ def test_a85decode_errors(self):
self.assertRaises(ValueError, base64.a85decode, b'aaaay',
foldspaces=True)

self.assertEqual(base64.a85decode(b"a b\nc", ignorechars=b" \n"),
b'\xc9\x89')
with self.assertRaises(ValueError):
base64.a85decode(b"a b\nc", ignorechars=b"")
with self.assertRaises(ValueError):
base64.a85decode(b"a b\nc", ignorechars=b" ")
with self.assertRaises(ValueError):
base64.a85decode(b"a b\nc", ignorechars=b"\n")
with self.assertRaises(TypeError):
base64.a85decode(b"a b\nc", ignorechars=" \n")
with self.assertRaises(TypeError):
base64.a85decode(b"a b\nc", ignorechars=None)

def test_b85decode_errors(self):
illegal = list(range(33)) + \
list(b'"\',./:[\\]') + \
Expand Down
56 changes: 23 additions & 33 deletions Lib/test/test_unicodedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ def iterallchars():
maxunicode = 0xffff if quicktest else sys.maxunicode
return map(chr, range(maxunicode + 1))


def check_version(testfile):
hdr = testfile.readline()
return unicodedata.unidata_version in hdr


def download_test_data_file(filename):
TESTDATAURL = f"http://www.pythontest.net/unicode/{unicodedata.unidata_version}/{filename}"

try:
return open_urlresource(TESTDATAURL, encoding="utf-8", check=check_version)
except PermissionError:
raise unittest.SkipTest(
f"Permission error when downloading {TESTDATAURL} "
f"into the test data directory"
)
except (OSError, HTTPException) as exc:
raise unittest.SkipTest(f"Failed to download {TESTDATAURL}: {exc}")


class UnicodeMethodsTest(unittest.TestCase):

# update this, if the database changes
Expand Down Expand Up @@ -956,11 +976,6 @@ def test_segment_object(self):


class NormalizationTest(unittest.TestCase):
@staticmethod
def check_version(testfile):
hdr = testfile.readline()
return unicodedata.unidata_version in hdr

@staticmethod
def unistr(data):
data = [int(x, 16) for x in data.split(" ")]
Expand All @@ -970,17 +985,7 @@ def unistr(data):
@requires_resource('cpu')
def test_normalization(self):
TESTDATAFILE = "NormalizationTest.txt"
TESTDATAURL = f"http://www.pythontest.net/unicode/{unicodedata.unidata_version}/{TESTDATAFILE}"

# Hit the exception early
try:
testdata = open_urlresource(TESTDATAURL, encoding="utf-8",
check=self.check_version)
except PermissionError:
self.skipTest(f"Permission error when downloading {TESTDATAURL} "
f"into the test data directory")
except (OSError, HTTPException) as exc:
self.skipTest(f"Failed to download {TESTDATAURL}: {exc}")
testdata = download_test_data_file(TESTDATAFILE)

with testdata:
self.run_normalization_tests(testdata, unicodedata)
Expand Down Expand Up @@ -1077,25 +1082,10 @@ class MyStr(str):


class GraphemeBreakTest(unittest.TestCase):
@staticmethod
def check_version(testfile):
hdr = testfile.readline()
return unicodedata.unidata_version in hdr

@requires_resource('network')
def test_grapheme_break(self):
TESTDATAFILE = "auxiliary/GraphemeBreakTest.txt"
TESTDATAURL = f"https://www.unicode.org/Public/{unicodedata.unidata_version}/ucd/{TESTDATAFILE}"

# Hit the exception early
try:
testdata = open_urlresource(TESTDATAURL, encoding="utf-8",
check=self.check_version)
except PermissionError:
self.skipTest(f"Permission error when downloading {TESTDATAURL} "
f"into the test data directory")
except (OSError, HTTPException) as exc:
self.skipTest(f"Failed to download {TESTDATAURL}: {exc}")
TESTDATAFILE = "GraphemeBreakTest.txt"
testdata = download_test_data_file(TESTDATAFILE)

with testdata:
self.run_grapheme_break_tests(testdata)
Expand Down
Loading