Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zlib_into
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dataAnalysis
zlib_into
Commits
b3f4a41d
Commit
b3f4a41d
authored
1 month ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Autoformat test file
parent
9b0e738a
No related branches found
No related tags found
No related merge requests found
Pipeline
#163022
passed
1 month ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test_zlib_into.py
+10
-9
10 additions, 9 deletions
test_zlib_into.py
with
10 additions
and
9 deletions
test_zlib_into.py
+
10
−
9
View file @
b3f4a41d
...
@@ -4,9 +4,10 @@ import pytest
...
@@ -4,9 +4,10 @@ import pytest
from
zlib_into
import
compress_into
,
decompress_into
from
zlib_into
import
compress_into
,
decompress_into
def
test_compress_into
():
def
test_compress_into
():
buf_size
=
5000
buf_size
=
5000
data_in
=
b
'
abcde
'
*
5000
data_in
=
b
"
abcde
"
*
5000
buf
=
bytearray
(
buf_size
)
buf
=
bytearray
(
buf_size
)
n_bytes_out
=
compress_into
(
data_in
,
buf
)
n_bytes_out
=
compress_into
(
data_in
,
buf
)
...
@@ -14,7 +15,7 @@ def test_compress_into():
...
@@ -14,7 +15,7 @@ def test_compress_into():
assert
0
<
n_bytes_out
<
buf_size
assert
0
<
n_bytes_out
<
buf_size
# Remaining space in buffer should not have been touched
# Remaining space in buffer should not have been touched
assert
bytes
(
buf
[
n_bytes_out
:])
==
b
'
\0
'
*
(
buf_size
-
n_bytes_out
)
assert
bytes
(
buf
[
n_bytes_out
:])
==
b
"
\0
"
*
(
buf_size
-
n_bytes_out
)
# Roundtrip
# Roundtrip
assert
zlib
.
decompress
(
buf
[:
n_bytes_out
])
==
data_in
assert
zlib
.
decompress
(
buf
[:
n_bytes_out
])
==
data_in
...
@@ -22,7 +23,7 @@ def test_compress_into():
...
@@ -22,7 +23,7 @@ def test_compress_into():
def
test_compress_into_err
():
def
test_compress_into_err
():
buf_size
=
5000
buf_size
=
5000
data_in
=
b
'
abcde
'
*
5000
data_in
=
b
"
abcde
"
*
5000
buf
=
bytearray
(
5000
)
buf
=
bytearray
(
5000
)
with
pytest
.
raises
(
BufferError
):
with
pytest
.
raises
(
BufferError
):
compress_into
(
memoryview
(
data_in
)[::
2
],
buf
)
# Input not contiguous
compress_into
(
memoryview
(
data_in
)[::
2
],
buf
)
# Input not contiguous
...
@@ -35,7 +36,7 @@ def test_compress_into_err():
...
@@ -35,7 +36,7 @@ def test_compress_into_err():
def
test_decompress_into
():
def
test_decompress_into
():
expanded_data
=
b
'
abcde
'
*
5000
expanded_data
=
b
"
abcde
"
*
5000
compressed_data
=
zlib
.
compress
(
expanded_data
)
compressed_data
=
zlib
.
compress
(
expanded_data
)
buf
=
bytearray
(
len
(
expanded_data
)
+
10
)
buf
=
bytearray
(
len
(
expanded_data
)
+
10
)
...
@@ -46,7 +47,7 @@ def test_decompress_into():
...
@@ -46,7 +47,7 @@ def test_decompress_into():
assert
buf
[:
n_bytes_out
]
==
expanded_data
assert
buf
[:
n_bytes_out
]
==
expanded_data
# Remaining space in buffer should not have been touched
# Remaining space in buffer should not have been touched
assert
bytes
(
buf
[
n_bytes_out
:])
==
b
'
\0
'
*
(
len
(
buf
)
-
n_bytes_out
)
assert
bytes
(
buf
[
n_bytes_out
:])
==
b
"
\0
"
*
(
len
(
buf
)
-
n_bytes_out
)
# Exactly the right amount of space
# Exactly the right amount of space
buf2
=
bytearray
(
len
(
expanded_data
))
buf2
=
bytearray
(
len
(
expanded_data
))
...
@@ -58,19 +59,19 @@ def test_decompress_into():
...
@@ -58,19 +59,19 @@ def test_decompress_into():
decompress_into
(
compressed_data
,
buf3
)
decompress_into
(
compressed_data
,
buf3
)
# Corner case: decompress 0 bytes
# Corner case: decompress 0 bytes
compressed_nothing
=
zlib
.
compress
(
b
''
)
compressed_nothing
=
zlib
.
compress
(
b
""
)
buf_size_0
=
bytearray
(
0
)
buf_size_0
=
bytearray
(
0
)
n_bytes_out
=
decompress_into
(
compressed_nothing
,
buf_size_0
)
n_bytes_out
=
decompress_into
(
compressed_nothing
,
buf_size_0
)
assert
n_bytes_out
==
0
assert
n_bytes_out
==
0
def
test_decompress_into_err
():
def
test_decompress_into_err
():
expanded_data
=
b
'
abcde
'
*
5000
expanded_data
=
b
"
abcde
"
*
5000
compressed_data
=
zlib
.
compress
(
expanded_data
)
compressed_data
=
zlib
.
compress
(
expanded_data
)
buf
=
bytearray
(
len
(
expanded_data
)
+
10
)
buf
=
bytearray
(
len
(
expanded_data
)
+
10
)
with
pytest
.
raises
(
BufferError
):
with
pytest
.
raises
(
BufferError
):
compress_into
(
memoryview
(
compressed_data
)[::
2
],
buf
)
# Input not contiguous
compress_into
(
memoryview
(
compressed_data
)[::
2
],
buf
)
# Input not contiguous
with
pytest
.
raises
(
TypeError
):
with
pytest
.
raises
(
TypeError
):
# Output not writable
compress_into
(
compressed_data
,
memoryview
(
buf
).
toreadonly
())
# Output not writable
compress_into
(
compressed_data
,
memoryview
(
buf
).
toreadonly
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment