Skip to content

Commit

Permalink
refine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TennyZhuang committed Nov 16, 2024
1 parent 13ef152 commit 6a19304
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,26 @@

import pytest
import pickle
from random import randint
from uuid import uuid4
import os


@pytest.mark.need_capability()
def test_operator_pickle(service_name, operator, async_operator):
@pytest.mark.asyncio
@pytest.mark.need_capability("read", "write", "delete", "shared")
async def test_operator_pickle(service_name, operator, async_operator):
"""
Test Operator's pickle serialization and deserialization.
Test AsyncOperator's pickle serialization and deserialization.
"""
serialized = pickle.dumps(operator)
deserialized = pickle.loads(serialized)
assert repr(operator) == repr(deserialized)

size = randint(1, 1024)
filename = f"random_file_{str(uuid4())}"
content = os.urandom(size)
await async_operator.write(filename, content)

serialized = pickle.dumps(async_operator)

deserialized = pickle.loads(serialized)
assert repr(async_operator) == repr(deserialized)
assert await deserialized.read(filename) == content

await async_operator.delete(filename)

0 comments on commit 6a19304

Please sign in to comment.