-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into freeze-resets
- Loading branch information
Showing
3 changed files
with
153 additions
and
1 deletion.
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
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,77 @@ | ||
import asynctest | ||
from kopf.clients.watching import _iter_jsonlines | ||
|
||
|
||
async def test_empty_content(): | ||
async def iter_chunked(n: int): | ||
if False: # to make this function a generator | ||
yield b'' | ||
|
||
content = asynctest.Mock(iter_chunked=iter_chunked) | ||
lines = [] | ||
async for line in _iter_jsonlines(content): | ||
lines.append(line) | ||
|
||
assert lines == [] | ||
|
||
|
||
async def test_empty_chunk(): | ||
async def iter_chunked(n: int): | ||
yield b'' | ||
|
||
content = asynctest.Mock(iter_chunked=iter_chunked) | ||
lines = [] | ||
async for line in _iter_jsonlines(content): | ||
lines.append(line) | ||
|
||
assert lines == [] | ||
|
||
|
||
async def test_one_chunk_one_line(): | ||
async def iter_chunked(n: int): | ||
yield b'hello' | ||
|
||
content = asynctest.Mock(iter_chunked=iter_chunked) | ||
lines = [] | ||
async for line in _iter_jsonlines(content): | ||
lines.append(line) | ||
|
||
assert lines == [b'hello'] | ||
|
||
|
||
async def test_one_chunk_two_lines(): | ||
async def iter_chunked(n: int): | ||
yield b'hello\nworld' | ||
|
||
content = asynctest.Mock(iter_chunked=iter_chunked) | ||
lines = [] | ||
async for line in _iter_jsonlines(content): | ||
lines.append(line) | ||
|
||
assert lines == [b'hello', b'world'] | ||
|
||
|
||
async def test_one_chunk_empty_lines(): | ||
async def iter_chunked(n: int): | ||
yield b'\n\nhello\n\nworld\n\n' | ||
|
||
content = asynctest.Mock(iter_chunked=iter_chunked) | ||
lines = [] | ||
async for line in _iter_jsonlines(content): | ||
lines.append(line) | ||
|
||
assert lines == [b'hello', b'world'] | ||
|
||
|
||
async def test_few_chunks_split(): | ||
async def iter_chunked(n: int): | ||
yield b'\n\nhell' | ||
yield b'o\n\nwor' | ||
yield b'ld\n\n' | ||
|
||
content = asynctest.Mock(iter_chunked=iter_chunked) | ||
lines = [] | ||
async for line in _iter_jsonlines(content): | ||
lines.append(line) | ||
|
||
assert lines == [b'hello', b'world'] |