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
69d99fb7
Commit
69d99fb7
authored
2 months ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Add some tests
parent
940df880
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
test_zlib_into.py
+70
-0
70 additions, 0 deletions
test_zlib_into.py
with
71 additions
and
0 deletions
.gitignore
+
1
−
0
View file @
69d99fb7
...
...
@@ -2,3 +2,4 @@ build/
dist/
wheelhouse/
*.egg-info
__pycache__/
This diff is collapsed.
Click to expand it.
test_zlib_into.py
0 → 100644
+
70
−
0
View file @
69d99fb7
import
zlib
import
pytest
from
zlib_into
import
compress_into
,
decompress_into
def
test_compress_into
():
buf_size
=
5000
data_in
=
b
'
abcde
'
*
5000
buf
=
bytearray
(
buf_size
)
n_bytes_out
=
compress_into
(
data_in
,
buf
)
assert
isinstance
(
n_bytes_out
,
int
)
assert
0
<
n_bytes_out
<
buf_size
# Remaining space in buffer should not have been touched
assert
bytes
(
buf
[
n_bytes_out
:])
==
b
'
\0
'
*
(
buf_size
-
n_bytes_out
)
# Roundtrip
assert
zlib
.
decompress
(
buf
[:
n_bytes_out
])
==
data_in
def
test_compress_into_err
():
buf_size
=
5000
data_in
=
b
'
abcde
'
*
5000
buf
=
bytearray
(
5000
)
with
pytest
.
raises
(
BufferError
):
compress_into
(
memoryview
(
data_in
)[::
2
],
buf
)
# Input not contiguous
with
pytest
.
raises
(
TypeError
):
compress_into
(
data_in
,
memoryview
(
buf
).
toreadonly
())
# Output not writable
with
pytest
.
raises
(
BufferError
):
compress_into
(
data_in
,
buf
[:
10
])
# Output too small
def
test_decompress_into
():
expanded_data
=
b
'
abcde
'
*
5000
compressed_data
=
zlib
.
compress
(
expanded_data
)
buf
=
bytearray
(
len
(
expanded_data
)
+
10
)
n_bytes_out
=
decompress_into
(
compressed_data
,
buf
)
assert
isinstance
(
n_bytes_out
,
int
)
assert
n_bytes_out
==
len
(
expanded_data
)
assert
buf
[:
n_bytes_out
]
==
expanded_data
# Remaining space in buffer should not have been touched
assert
bytes
(
buf
[
n_bytes_out
:])
==
b
'
\0
'
*
(
len
(
buf
)
-
n_bytes_out
)
# Exactly the right amount of space
buf2
=
bytearray
(
len
(
expanded_data
))
assert
decompress_into
(
compressed_data
,
buf2
)
==
len
(
expanded_data
)
# Not enough space, by 1 byte
buf3
=
bytearray
(
len
(
expanded_data
)
-
1
)
with
pytest
.
raises
(
BufferError
):
decompress_into
(
compressed_data
,
buf3
)
def
test_decompress_into_err
():
expanded_data
=
b
'
abcde
'
*
5000
compressed_data
=
zlib
.
compress
(
expanded_data
)
buf
=
bytearray
(
len
(
expanded_data
)
+
10
)
with
pytest
.
raises
(
BufferError
):
compress_into
(
memoryview
(
compressed_data
)[::
2
],
buf
)
# Input not contiguous
with
pytest
.
raises
(
TypeError
):
compress_into
(
compressed_data
,
memoryview
(
buf
).
toreadonly
())
# Output not writable
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