-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add test_allocation_cleanup and test_core_foundation_types
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import gc | ||
|
||
|
||
def test_allocate_file_fd_context_manager(client, tmp_path): | ||
# make sure when the test starts, all previous Allocated references are freed | ||
gc.collect() | ||
fds_count = len(client.processes.get_fds(client.pid)) | ||
with client.fs.open(tmp_path / 'test', 'w'): | ||
assert fds_count + 1 == len(client.processes.get_fds(client.pid)) | ||
assert fds_count == len(client.processes.get_fds(client.pid)) | ||
|
||
|
||
def test_allocate_file_fd_gc(client, tmp_path): | ||
# make sure when the test starts, all previous Allocated references are freed | ||
gc.collect() | ||
fds_count = len(client.processes.get_fds(client.pid)) | ||
|
||
# create a new fd with zero references, so it should be free immediately | ||
client.fs.open(tmp_path / 'test', 'w') | ||
|
||
# make sure python's GC had a chance to free the newly created fd | ||
gc.collect() | ||
assert fds_count == len(client.processes.get_fds(client.pid)) | ||
|
||
|
||
def test_allocate_file_fd_explicit_del(client, tmp_path): | ||
# make sure when the test starts, all previous Allocated references are freed | ||
gc.collect() | ||
fds_count = len(client.processes.get_fds(client.pid)) | ||
fd = client.fs.open(tmp_path / 'test', 'w') | ||
assert fds_count + 1 == len(client.processes.get_fds(client.pid)) | ||
del fd | ||
assert fds_count == len(client.processes.get_fds(client.pid)) | ||
|
||
|
||
def test_allocate_file_fd_explicit_deallocate(client, tmp_path): | ||
# make sure when the test starts, all previous Allocated references are freed | ||
gc.collect() | ||
fds_count = len(client.processes.get_fds(client.pid)) | ||
fd = client.fs.open(tmp_path / 'test', 'w') | ||
assert fds_count + 1 == len(client.processes.get_fds(client.pid)) | ||
fd.deallocate() | ||
assert fds_count >= len(client.processes.get_fds(client.pid)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize('data', ['string', | ||
b'bytes', | ||
123, | ||
0.1, | ||
[0, 1, 'abc'], | ||
{'key': 'value'}, | ||
[{'key': 'value'}, [1, 2]]]) | ||
def test_serialization(client, data): | ||
assert client.cf(data).py == data |