Run Black on veilid-python
This commit is contained in:
@@ -27,9 +27,7 @@ async def test_get_node_id(api_connection: veilid.VeilidAPI):
|
||||
@pytest.mark.asyncio
|
||||
async def test_fail_connect():
|
||||
with pytest.raises(socket.gaierror) as exc:
|
||||
await veilid.json_api_connect(
|
||||
"fuahwelifuh32luhwafluehawea", 1, simple_update_callback
|
||||
)
|
||||
await veilid.json_api_connect("fuahwelifuh32luhwafluehawea", 1, simple_update_callback)
|
||||
|
||||
assert exc.value.errno == socket.EAI_NONAME
|
||||
|
||||
|
@@ -12,14 +12,13 @@ async def test_best_crypto_system(api_connection: veilid.VeilidAPI):
|
||||
async with cs:
|
||||
assert await cs.default_salt_length() == 16
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_crypto_system(api_connection: veilid.VeilidAPI):
|
||||
cs: CryptoSystem = await api_connection.get_crypto_system(
|
||||
veilid.CryptoKind.CRYPTO_KIND_VLD0
|
||||
)
|
||||
cs: CryptoSystem = await api_connection.get_crypto_system(veilid.CryptoKind.CRYPTO_KIND_VLD0)
|
||||
async with cs:
|
||||
assert await cs.default_salt_length() == 16
|
||||
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_crypto_system_invalid(api_connection: veilid.VeilidAPI):
|
||||
@@ -45,4 +44,3 @@ async def test_hash_and_verify_password(api_connection: veilid.VeilidAPI):
|
||||
# Password mismatch
|
||||
phash2 = await cs.hash_password(b"abc1234", salt)
|
||||
assert not await cs.verify_password(b"abc12345", phash)
|
||||
|
||||
|
@@ -47,7 +47,9 @@ async def test_delete_dht_record_nonexistent(api_connection: veilid.VeilidAPI):
|
||||
async def test_create_delete_dht_record_simple(api_connection: veilid.VeilidAPI):
|
||||
rc = await api_connection.new_routing_context()
|
||||
async with rc:
|
||||
rec = await rc.create_dht_record(veilid.DHTSchema.dflt(1), veilid.CryptoKind.CRYPTO_KIND_VLD0)
|
||||
rec = await rc.create_dht_record(
|
||||
veilid.DHTSchema.dflt(1), veilid.CryptoKind.CRYPTO_KIND_VLD0
|
||||
)
|
||||
await rc.close_dht_record(rec.key)
|
||||
await rc.delete_dht_record(rec.key)
|
||||
|
||||
|
@@ -34,9 +34,7 @@ async def test_routing_contexts(api_connection: veilid.VeilidAPI):
|
||||
|
||||
rc = await (await api_connection.new_routing_context()).with_custom_privacy(
|
||||
veilid.SafetySelection.safe(
|
||||
veilid.SafetySpec(
|
||||
None, 2, veilid.Stability.RELIABLE, veilid.Sequencing.ENSURE_ORDERED
|
||||
)
|
||||
veilid.SafetySpec(None, 2, veilid.Stability.RELIABLE, veilid.Sequencing.ENSURE_ORDERED)
|
||||
)
|
||||
)
|
||||
await rc.release()
|
||||
@@ -117,14 +115,10 @@ async def test_routing_context_app_call_loopback():
|
||||
|
||||
# send an app message to our own private route
|
||||
request = b"abcd1234"
|
||||
app_call_task = asyncio.create_task(
|
||||
rc.app_call(prr, request), name="app call task"
|
||||
)
|
||||
app_call_task = asyncio.create_task(rc.app_call(prr, request), name="app call task")
|
||||
|
||||
# we should get the same request back
|
||||
update: veilid.VeilidUpdate = await asyncio.wait_for(
|
||||
app_call_queue.get(), timeout=10
|
||||
)
|
||||
update: veilid.VeilidUpdate = await asyncio.wait_for(app_call_queue.get(), timeout=10)
|
||||
appcall = update.detail
|
||||
|
||||
assert isinstance(appcall, veilid.VeilidAppCall)
|
||||
@@ -164,9 +158,9 @@ async def test_routing_context_app_message_loopback_big_packets():
|
||||
await api.debug("purge routes")
|
||||
|
||||
# make a routing context that uses a safety route
|
||||
rc = await (
|
||||
await (await api.new_routing_context()).with_privacy()
|
||||
).with_sequencing(veilid.Sequencing.ENSURE_ORDERED)
|
||||
rc = await (await (await api.new_routing_context()).with_privacy()).with_sequencing(
|
||||
veilid.Sequencing.ENSURE_ORDERED
|
||||
)
|
||||
async with rc:
|
||||
# make a new local private route
|
||||
prl, blob = await api.new_private_route()
|
||||
@@ -223,14 +217,12 @@ async def test_routing_context_app_call_loopback_big_packets():
|
||||
# purge routes to ensure we start fresh
|
||||
await api.debug("purge routes")
|
||||
|
||||
app_call_task = asyncio.create_task(
|
||||
app_call_queue_task_handler(api), name="app call task"
|
||||
)
|
||||
app_call_task = asyncio.create_task(app_call_queue_task_handler(api), name="app call task")
|
||||
|
||||
# make a routing context that uses a safety route
|
||||
rc = await (
|
||||
await (await api.new_routing_context()).with_privacy()
|
||||
).with_sequencing(veilid.Sequencing.ENSURE_ORDERED)
|
||||
rc = await (await (await api.new_routing_context()).with_privacy()).with_sequencing(
|
||||
veilid.Sequencing.ENSURE_ORDERED
|
||||
)
|
||||
async with rc:
|
||||
# make a new local private route
|
||||
prl, blob = await api.new_private_route()
|
||||
@@ -249,9 +241,7 @@ async def test_routing_context_app_call_loopback_big_packets():
|
||||
app_call_task.cancel()
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
os.getenv("NOSKIP") != "1", reason="unneeded test, only for performance check"
|
||||
)
|
||||
@pytest.mark.skipif(os.getenv("NOSKIP") != "1", reason="unneeded test, only for performance check")
|
||||
@pytest.mark.asyncio
|
||||
async def test_routing_context_app_message_loopback_bandwidth():
|
||||
app_message_queue: asyncio.Queue = asyncio.Queue()
|
||||
|
@@ -8,6 +8,7 @@ from veilid.api import CryptoSystem
|
||||
TEST_DB = "__pytest_db"
|
||||
TEST_NONEXISTENT_DB = "__pytest_nonexistent_db"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_table_db_nonexistent(api_connection: veilid.VeilidAPI):
|
||||
deleted = await api_connection.delete_table_db(TEST_NONEXISTENT_DB)
|
||||
@@ -25,11 +26,12 @@ async def test_open_delete_table_db(api_connection: veilid.VeilidAPI):
|
||||
with pytest.raises(veilid.VeilidAPIErrorGeneric) as exc:
|
||||
await api_connection.delete_table_db(TEST_DB)
|
||||
# drop the db
|
||||
|
||||
|
||||
# now delete should succeed
|
||||
deleted = await api_connection.delete_table_db(TEST_DB)
|
||||
assert deleted
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_open_twice_table_db(api_connection: veilid.VeilidAPI):
|
||||
# delete test db if it exists
|
||||
@@ -37,12 +39,12 @@ async def test_open_twice_table_db(api_connection: veilid.VeilidAPI):
|
||||
|
||||
tdb = await api_connection.open_table_db(TEST_DB, 1)
|
||||
tdb2 = await api_connection.open_table_db(TEST_DB, 1)
|
||||
|
||||
|
||||
# delete should fail because open
|
||||
with pytest.raises(veilid.VeilidAPIErrorGeneric) as exc:
|
||||
await api_connection.delete_table_db(TEST_DB)
|
||||
await tdb.release()
|
||||
|
||||
|
||||
# delete should fail because open
|
||||
with pytest.raises(veilid.VeilidAPIErrorGeneric) as exc:
|
||||
await api_connection.delete_table_db(TEST_DB)
|
||||
@@ -62,7 +64,7 @@ async def test_open_twice_table_db_store_load(api_connection: veilid.VeilidAPI):
|
||||
async with tdb:
|
||||
tdb2 = await api_connection.open_table_db(TEST_DB, 1)
|
||||
async with tdb2:
|
||||
# store into first db copy
|
||||
# store into first db copy
|
||||
await tdb.store(b"asdf", b"1234")
|
||||
# load from second db copy
|
||||
assert await tdb.load(b"asdf") == b"1234"
|
||||
@@ -71,6 +73,7 @@ async def test_open_twice_table_db_store_load(api_connection: veilid.VeilidAPI):
|
||||
deleted = await api_connection.delete_table_db(TEST_DB)
|
||||
assert deleted
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_open_twice_table_db_store_delete_load(api_connection: veilid.VeilidAPI):
|
||||
# delete test db if it exists
|
||||
@@ -80,12 +83,11 @@ async def test_open_twice_table_db_store_delete_load(api_connection: veilid.Veil
|
||||
async with tdb:
|
||||
tdb2 = await api_connection.open_table_db(TEST_DB, 1)
|
||||
async with tdb2:
|
||||
|
||||
# store into first db copy
|
||||
# store into first db copy
|
||||
await tdb.store(b"asdf", b"1234")
|
||||
# delete from second db copy and clean up
|
||||
await tdb2.delete(b"asdf")
|
||||
|
||||
|
||||
# load from first db copy
|
||||
assert await tdb.load(b"asdf") == None
|
||||
|
||||
@@ -104,24 +106,22 @@ async def test_resize_table_db(api_connection: veilid.VeilidAPI):
|
||||
# reopen the db with more columns should fail if it is already open
|
||||
with pytest.raises(veilid.VeilidAPIErrorGeneric) as exc:
|
||||
await api_connection.open_table_db(TEST_DB, 2)
|
||||
|
||||
|
||||
tdb2 = await api_connection.open_table_db(TEST_DB, 2)
|
||||
async with tdb2:
|
||||
# write something to second column
|
||||
await tdb2.store(b"qwer", b"5678", col = 1)
|
||||
|
||||
await tdb2.store(b"qwer", b"5678", col=1)
|
||||
|
||||
# reopen the db with fewer columns
|
||||
tdb = await api_connection.open_table_db(TEST_DB, 1)
|
||||
async with tdb:
|
||||
|
||||
# Should fail access to second column
|
||||
# Should fail access to second column
|
||||
with pytest.raises(veilid.VeilidAPIErrorGeneric) as exc:
|
||||
await tdb.load(b"qwer", col = 1)
|
||||
|
||||
# Should succeed with access to second column
|
||||
assert await tdb2.load(b"qwer", col = 1) == b"5678"
|
||||
|
||||
await tdb.load(b"qwer", col=1)
|
||||
|
||||
# Should succeed with access to second column
|
||||
assert await tdb2.load(b"qwer", col=1) == b"5678"
|
||||
|
||||
# now delete should succeed
|
||||
deleted = await api_connection.delete_table_db(TEST_DB)
|
||||
assert deleted
|
||||
|
||||
|
Reference in New Issue
Block a user