Debian Codegraph @

tests/test_restart.py

raw symbols SCIP
1 import pytest
2
3
4 @pytest.mark.parametrize("offset", [0, 3, 10])
5 @pytest.mark.asyncio
6 async def test_restart_retr(pair_factory, offset):
7 async with pair_factory() as pair:
8 atom = b"foobar"
9 name = "foo.txt"
10 await pair.make_server_files(name, size=1, atom=atom)
11 async with pair.client.download_stream(name, offset=offset) as stream:
12 assert await stream.read() == atom[offset:]
13
14
15 @pytest.mark.parametrize("offset", [1, 3, 10])
16 @pytest.mark.parametrize("method", ["upload_stream", "append_stream"])
17 @pytest.mark.asyncio
18 async def test_restart_stor_appe(pair_factory, offset, method):
19 async with pair_factory() as pair:
20 atom = b"foobar"
21 name = "foo.txt"
22 insert = b"123"
23 expect = atom[:offset] + b"\x00" * (offset - len(atom)) + insert + atom[offset + len(insert) :]
24 await pair.make_server_files(name, size=1, atom=atom)
25 stream_factory = getattr(pair.client, method)
26 async with stream_factory(name, offset=offset) as stream:
27 await stream.write(b"123")
28 async with pair.client.download_stream(name) as stream:
29 assert await stream.read() == expect
30
31
32 @pytest.mark.asyncio
33 async def test_restart_reset(pair_factory):
34 async with pair_factory() as pair:
35 atom = b"foobar"
36 name = "foo.txt"
37 await pair.make_server_files(name, size=1, atom=atom)
38 await pair.client.command("REST 3", "350")
39 async with pair.client.download_stream("foo.txt") as stream:
40 assert await stream.read() == atom
41
42
43 @pytest.mark.asyncio
44 async def test_restart_syntax_error(pair_factory, expect_codes_in_exception):
45 async with pair_factory() as pair:
46 with expect_codes_in_exception("501"):
47 await pair.client.command("REST 3abc", "350")