Skip to content

Commit 68ce180

Browse files
committed
add typing to tests
1 parent a1f513a commit 68ce180

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

tests/query/test_query_session.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import pytest
22

3+
from ydb.query.session import QuerySessionSync
34

4-
def _check_session_state_empty(session):
5+
6+
def _check_session_state_empty(session: QuerySessionSync):
57
assert session._state.session_id is None
68
assert session._state.node_id is None
79
assert not session._state.attached
810

911

10-
def _check_session_state_full(session):
12+
def _check_session_state_full(session: QuerySessionSync):
1113
assert session._state.session_id is not None
1214
assert session._state.node_id is not None
1315
assert session._state.attached
1416

1517

1618
class TestQuerySession:
17-
def test_session_normal_lifecycle(self, session):
19+
def test_session_normal_lifecycle(self, session: QuerySessionSync):
1820
_check_session_state_empty(session)
1921

2022
session.create()
@@ -23,7 +25,7 @@ def test_session_normal_lifecycle(self, session):
2325
session.delete()
2426
_check_session_state_empty(session)
2527

26-
def test_second_create_do_nothing(self, session):
28+
def test_second_create_do_nothing(self, session: QuerySessionSync):
2729
session.create()
2830
_check_session_state_full(session)
2931

@@ -36,49 +38,49 @@ def test_second_create_do_nothing(self, session):
3638
assert session._state.session_id == session_id_before
3739
assert session._state.node_id == node_id_before
3840

39-
def test_second_delete_do_nothing(self, session):
41+
def test_second_delete_do_nothing(self, session: QuerySessionSync):
4042
session.create()
4143

4244
session.delete()
4345
session.delete()
4446

45-
def test_delete_before_create_not_possible(self, session):
47+
def test_delete_before_create_not_possible(self, session: QuerySessionSync):
4648
with pytest.raises(RuntimeError):
4749
session.delete()
4850

49-
def test_create_after_delete_not_possible(self, session):
51+
def test_create_after_delete_not_possible(self, session: QuerySessionSync):
5052
session.create()
5153
session.delete()
5254
with pytest.raises(RuntimeError):
5355
session.create()
5456

55-
def test_transaction_before_create_raises(self, session):
57+
def test_transaction_before_create_raises(self, session: QuerySessionSync):
5658
with pytest.raises(RuntimeError):
5759
session.transaction()
5860

59-
def test_transaction_after_delete_raises(self, session):
61+
def test_transaction_after_delete_raises(self, session: QuerySessionSync):
6062
session.create()
6163

6264
session.delete()
6365

6466
with pytest.raises(RuntimeError):
6567
session.transaction()
6668

67-
def test_transaction_after_create_not_raises(self, session):
69+
def test_transaction_after_create_not_raises(self, session: QuerySessionSync):
6870
session.create()
6971
session.transaction()
7072

71-
def test_execute_before_create_raises(self, session):
73+
def test_execute_before_create_raises(self, session: QuerySessionSync):
7274
with pytest.raises(RuntimeError):
7375
session.execute("select 1;")
7476

75-
def test_execute_after_delete_raises(self, session):
77+
def test_execute_after_delete_raises(self, session: QuerySessionSync):
7678
session.create()
7779
session.delete()
7880
with pytest.raises(RuntimeError):
7981
session.execute("select 1;")
8082

81-
def test_basic_execute(self, session):
83+
def test_basic_execute(self, session: QuerySessionSync):
8284
session.create()
8385
it = session.execute("select 1;")
8486
result_sets = [result_set for result_set in it]

tests/query/test_query_transaction.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,69 @@
11
import pytest
22

3+
from ydb.query.transaction import BaseTxContext
34
from ydb.query.transaction import QueryTxStateEnum
45

56
class TestQueryTransaction:
6-
def test_tx_begin(self, tx):
7+
def test_tx_begin(self, tx: BaseTxContext):
78
assert tx.tx_id is None
89

910
tx.begin()
1011
assert tx.tx_id is not None
1112

12-
def test_tx_allow_double_commit(self, tx):
13+
def test_tx_allow_double_commit(self, tx: BaseTxContext):
1314
tx.begin()
1415
tx.commit()
1516
tx.commit()
1617

17-
def test_tx_allow_double_rollback(self, tx):
18+
def test_tx_allow_double_rollback(self, tx: BaseTxContext):
1819
tx.begin()
1920
tx.rollback()
2021
tx.rollback()
2122

22-
def test_tx_commit_raises_before_begin(self, tx):
23+
def test_tx_commit_raises_before_begin(self, tx: BaseTxContext):
2324
with pytest.raises(RuntimeError):
2425
tx.commit()
2526

26-
def test_tx_rollback_raises_before_begin(self, tx):
27+
def test_tx_rollback_raises_before_begin(self, tx: BaseTxContext):
2728
with pytest.raises(RuntimeError):
2829
tx.rollback()
2930

30-
def test_tx_first_execute_begins_tx(self, tx):
31+
def test_tx_first_execute_begins_tx(self, tx: BaseTxContext):
3132
tx.execute("select 1;")
3233
tx.commit()
3334

34-
def test_interactive_tx_commit(self, tx):
35+
def test_interactive_tx_commit(self, tx: BaseTxContext):
3536
tx.execute("select 1;", commit_tx=True)
3637
with pytest.raises(RuntimeError):
3738
tx.execute("select 1;")
3839

39-
def test_tx_execute_raises_after_commit(self, tx):
40+
def test_tx_execute_raises_after_commit(self, tx: BaseTxContext):
4041
tx.begin()
4142
tx.commit()
4243
with pytest.raises(RuntimeError):
4344
tx.execute("select 1;")
4445

45-
def test_tx_execute_raises_after_rollback(self, tx):
46+
def test_tx_execute_raises_after_rollback(self, tx: BaseTxContext):
4647
tx.begin()
4748
tx.rollback()
4849
with pytest.raises(RuntimeError):
4950
tx.execute("select 1;")
5051

51-
def test_context_manager_rollbacks_tx(self, tx):
52+
def test_context_manager_rollbacks_tx(self, tx: BaseTxContext):
5253
with tx:
5354
tx.begin()
5455

5556
assert tx._tx_state._state == QueryTxStateEnum.ROLLBACKED
5657

57-
def test_context_manager_normal_flow(self, tx):
58+
def test_context_manager_normal_flow(self, tx: BaseTxContext):
5859
with tx:
5960
tx.begin()
6061
tx.execute("select 1;")
6162
tx.commit()
6263

6364
assert tx._tx_state._state == QueryTxStateEnum.COMMITTED
6465

65-
def test_context_manager_does_not_hide_exceptions(self, tx):
66+
def test_context_manager_does_not_hide_exceptions(self, tx: BaseTxContext):
6667
with pytest.raises(RuntimeError):
6768
with tx:
6869
tx.commit()

0 commit comments

Comments
 (0)