Skip to content

Commit fda5f3c

Browse files
committed
-
1 parent f2910c2 commit fda5f3c

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

source_py2/test_python_toolbox/test_caching/test_cache.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,17 @@ def test_unhashable_arguments():
115115

116116
f = cache()(counting_func)
117117

118+
x = set((1, 2))
118119

119-
assert f(set((1, 2))) == f(set((1, 2)))
120+
assert f(x) == f(x)
120121

121-
assert f(7, set((1, 2))) != f(8, set((1, 2)))
122+
assert f(7, x) != f(8, x)
122123

123124
assert f('boo') != f(meow='frrr')
124125

125-
assert f(meow={1: [1, 2], 2: frozenset([3, 'b'])}) == \
126-
f(1, meow={1: [1, 2], 2: frozenset([3, 'b'])})
126+
y = {1: [1, 2], 2: frozenset([3, 'b'])}
127+
128+
assert f(meow=y) == f(1, meow=y)
127129

128130

129131
def test_helpful_message_when_forgetting_parentheses():

source_py3/python_toolbox/zip_tools.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import contextlib
99
import zipfile as zip_module
1010
import os.path
11-
import io as string_io_module
11+
import io
1212
import re
1313
import fnmatch
1414

@@ -35,9 +35,8 @@ def zip_folder(folder, zip_path, ignored_patterns=()):
3535
zip_name = os.path.splitext(os.path.split(zip_path)[1])[0]
3636
source_folder_name = os.path.split(source_folder)[1]
3737

38-
with contextlib.closing(
39-
zip_module.ZipFile(zip_path, 'w', zip_module.ZIP_DEFLATED)
40-
) as zip_file:
38+
with zip_module.ZipFile(zip_path, 'w', zip_module.ZIP_DEFLATED) \
39+
as zip_file:
4140

4241
for root, subfolders, files in os.walk(source_folder):
4342

@@ -63,9 +62,9 @@ def zip_in_memory(files):
6362
6463
Files should be given as tuples of `(file_path, file_contents)`.
6564
'''
66-
zip_stream = string_io_module.StringIO()
67-
with contextlib.closing(zip_module.ZipFile(zip_stream, mode='w',
68-
compression=zip_module.ZIP_DEFLATED)) as zip_file:
65+
zip_stream = io.BytesIO()
66+
with zip_module.ZipFile(zip_stream, mode='w',
67+
compression=zip_module.ZIP_DEFLATED) as zip_file:
6968
assert isinstance(zip_file, zip_module.ZipFile)
7069
for file_name, file_data in files:
7170
zip_file.writestr(file_name, file_data)
@@ -78,9 +77,9 @@ def unzip_in_memory(zip_archive):
7877
7978
Files are returned as tuples of `(file_path, file_contents)`.
8079
'''
81-
zip_stream = string_io_module.StringIO(zip_archive)
82-
with contextlib.closing(zip_module.ZipFile(zip_stream, mode='r',
83-
compression=zip_module.ZIP_DEFLATED)) as zip_file:
80+
zip_stream = io.BytesIO(zip_archive)
81+
with zip_module.ZipFile(zip_stream, mode='r',
82+
compression=zip_module.ZIP_DEFLATED) as zip_file:
8483
assert isinstance(zip_file, zip_module.ZipFile)
8584
return tuple((file_name, zip_file.read(file_name)) for file_name in
8685
zip_file.namelist())

source_py3/test_python_toolbox/test_caching/test_cache.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,17 @@ def test_unhashable_arguments():
115115

116116
f = cache()(counting_func)
117117

118+
x = set((1, 2))
118119

119-
assert f(set((1, 2))) == f(set((1, 2)))
120+
assert f(x) == f(x)
120121

121-
assert f(7, set((1, 2))) != f(8, set((1, 2)))
122+
assert f(7, x) != f(8, x)
122123

123124
assert f('boo') != f(meow='frrr')
124125

125-
assert f(meow={1: [1, 2], 2: frozenset([3, 'b'])}) == \
126-
f(1, meow={1: [1, 2], 2: frozenset([3, 'b'])})
126+
y = {1: [1, 2], 2: frozenset([3, 'b'])}
127+
128+
assert f(meow=y) == f(1, meow=y)
127129

128130

129131
def test_helpful_message_when_forgetting_parentheses():

source_py3/test_python_toolbox/test_zip_tools/test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
def test_zipping_in_memory():
1212
''' '''
1313
files = (
14-
('meow.txt', "I'm a cat."),
15-
('dog.txt', "I'm a dog."),
16-
('folder/binary.bin', ''.join(map(chr, range(256))))
14+
('meow.txt', b"I'm a cat."),
15+
('dog.txt', b"I'm a dog."),
16+
('folder/binary.bin', bytes(bytearray(range(256))))
1717
)
1818

1919
zip_archive = zip_tools.zip_in_memory(files)
20-
assert isinstance(zip_archive, str)
20+
assert isinstance(zip_archive, bytes)
2121
assert set(zip_tools.unzip_in_memory(zip_archive)) == set(files)
2222

0 commit comments

Comments
 (0)