Skip to content

Commit f01d6da

Browse files
committed
🔧 refactor(tests): remove unnecessary parentheses in assert statements for better readability and consistency with Python's idiomatic style
1 parent 5354c9a commit f01d6da

File tree

11 files changed

+168
-161
lines changed

11 files changed

+168
-161
lines changed

tests/intergration/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

tests/intergration/test_account_api.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,43 @@
33
44
"""
55

6-
import pytest
76
import secrets
87

8+
import pytest
9+
910
from convex_api import (
1011
API,
11-
KeyPair,
12+
KeyPair
1213
)
1314
from tests.types import KeyPairInfo
1415

1516
TEST_ACCOUNT_NAME = 'test.convex-api'
1617

18+
1719
@pytest.fixture
1820
def account_name():
1921
return f'{TEST_ACCOUNT_NAME}-{secrets.token_hex(8)}'
2022

23+
2124
def test_account_api_create_account(convex_url: str):
2225

2326
convex = API(convex_url)
2427
key_pair = KeyPair()
2528
result = convex.create_account(key_pair)
26-
assert(result)
29+
assert result
2730

2831

2932
def test_account_api_multi_create_account(convex_url: str):
3033
convex = API(convex_url)
3134
key_pair = KeyPair()
3235
account_1 = convex.create_account(key_pair)
33-
assert(account_1)
36+
assert account_1
3437
account_2 = convex.create_account(key_pair)
35-
assert(account_2)
38+
assert account_2
3639

37-
assert(account_1.public_key == account_1.public_key)
38-
assert(account_1.public_key == account_2.public_key)
39-
assert(account_1.address != account_2.address)
40+
assert account_1.public_key == account_1.public_key
41+
assert account_1.public_key == account_2.public_key
42+
assert account_1.address != account_2.address
4043

4144

4245
def test_account_name(convex_url: str, test_key_pair_info: KeyPairInfo, account_name: str):
@@ -48,19 +51,19 @@ def test_account_name(convex_url: str, test_key_pair_info: KeyPairInfo, account_
4851
account = convex.create_account(import_key_pair)
4952
convex.topup_account(account)
5053
account = convex.register_account_name(account_name, account)
51-
assert(account is not None)
52-
assert(account.address)
53-
assert(account.name)
54-
assert(account.name == account_name)
55-
assert(convex.resolve_account_name(account_name) == account.address)
54+
assert account is not None
55+
assert account.address
56+
assert account.name
57+
assert account.name == account_name
58+
assert convex.resolve_account_name(account_name) == account.address
5659

5760

5861
def test_account_setup_account(convex_url: str, test_key_pair_info: KeyPairInfo, account_name: str):
5962
convex = API(convex_url)
6063
import_key_pair = KeyPair.import_from_bytes(test_key_pair_info['private_bytes'])
6164
account = convex.setup_account(account_name, import_key_pair)
62-
assert(account is not None)
63-
assert(account.address)
64-
assert(account.name)
65-
assert(account.name == account_name)
66-
assert(convex.resolve_account_name(account_name) == account.address)
65+
assert account is not None
66+
assert account.address
67+
assert account.name
68+
assert account.name == account_name
69+
assert convex.resolve_account_name(account_name) == account.address

tests/intergration/test_api.py

Lines changed: 64 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
Test Convex api
44
55
"""
6-
import pytest
76
import secrets
87

8+
import pytest
9+
910
from convex_api.account import Account
1011
from convex_api.api import API
12+
from convex_api.exceptions import ConvexRequestError
1113
from convex_api.key_pair import KeyPair
12-
from convex_api.exceptions import (
13-
ConvexRequestError
14-
)
1514

1615
TEST_FUNDING_AMOUNT = 8888888
1716

@@ -20,27 +19,29 @@ def test_convex_api_request_funds(convex_url: str, test_account: Account):
2019
convex = API(convex_url)
2120
amount = secrets.randbelow(100) + 1
2221
request_amount = convex.request_funds(amount, test_account)
23-
assert(request_amount == amount)
22+
assert request_amount == amount
23+
2424

2525
def test_convex_api_topup_account(convex_url: str):
2626
convex = API(convex_url)
2727
key_pair = KeyPair()
2828
account = convex.create_account(key_pair)
2929
topup_amount = TEST_FUNDING_AMOUNT
3030
amount = convex.topup_account(account, topup_amount)
31-
assert(amount >= topup_amount)
31+
assert amount >= topup_amount
3232

3333
account = convex.create_account(key_pair)
3434
amount = convex.topup_account(account)
35-
assert(amount >= 0)
35+
assert amount >= 0
36+
3637

3738
def test_convex_get_account_info(convex_url: str, test_account: Account):
3839
convex = API(convex_url)
3940
info = convex.get_account_info(test_account)
40-
assert(info)
41-
assert(info.type == 'user')
42-
assert(info.balance > 0)
43-
assert(info.sequence >= 0)
41+
assert info
42+
assert info.type == 'user'
43+
assert info.balance > 0
44+
assert info.sequence >= 0
4445

4546
with pytest.raises(ConvexRequestError, match='INCORRECT'):
4647
info = convex.get_account_info(pow(2, 100))
@@ -51,42 +52,42 @@ def test_convex_get_account_info(convex_url: str, test_account: Account):
5152
key_pair = KeyPair()
5253
account = convex.create_account(key_pair)
5354
request_amount = convex.request_funds(TEST_FUNDING_AMOUNT, account)
54-
assert(request_amount == TEST_FUNDING_AMOUNT)
55+
assert request_amount == TEST_FUNDING_AMOUNT
5556
info = convex.get_account_info(account)
56-
assert(info)
57-
assert(info.balance == TEST_FUNDING_AMOUNT)
57+
assert info
58+
assert info.balance == TEST_FUNDING_AMOUNT
59+
5860

5961
def test_convex_account_name_registry(convex_url: str, test_account: Account, test_key_pair: KeyPair):
6062
account_name = f'test.convex-api.{secrets.token_hex(4)}'
6163
convex = API(convex_url)
6264

6365
address = convex.resolve_account_name(account_name)
64-
assert(not address)
66+
assert not address
6567

6668
account = convex.load_account(account_name, test_key_pair)
67-
assert(not account)
68-
69+
assert not account
6970

7071
register_account = convex.register_account_name(account_name, test_account)
71-
assert(register_account.address == test_account.address)
72+
assert register_account.address == test_account.address
7273

73-
assert(convex.resolve_account_name(account_name) == test_account.address)
74+
assert convex.resolve_account_name(account_name) == test_account.address
7475

7576
new_account = convex.create_account(test_key_pair)
7677
register_account = convex.register_account_name(account_name, new_account, test_account)
7778

78-
assert(register_account.address == new_account.address)
79-
assert(convex.resolve_account_name(account_name) == new_account.address)
79+
assert register_account.address == new_account.address
80+
assert convex.resolve_account_name(account_name) == new_account.address
8081

8182
# clear the cache in the registry
8283
convex.registry.clear()
83-
assert(convex.resolve_account_name(account_name) == new_account.address)
84+
assert convex.resolve_account_name(account_name) == new_account.address
8485

8586

8687
def test_convex_resolve_name(convex_url: str):
8788
convex = API(convex_url)
8889
address = convex.resolve_name('convex.trust')
89-
assert(address)
90+
assert address
9091

9192

9293
def test_convex_transfer_account(convex_url: str, test_account: Account):
@@ -97,60 +98,64 @@ def test_convex_transfer_account(convex_url: str, test_account: Account):
9798
account_1 = convex.create_account(key_pair)
9899
convex.topup_account(account_1)
99100
result = convex.send('(map inc [1 2 3 4 5])', account_1)
100-
assert(result is not None)
101+
assert result is not None
101102
assert 'value' in result.model_dump()
102-
assert(result.value == [2, 3, 4, 5, 6])
103+
assert result.value == [2, 3, 4, 5, 6]
103104

104105
# transfer the new account_1 to use the same keys as the test_account
105106
account_1_change = convex.transfer_account(test_account, account_1)
106-
assert(account_1_change)
107+
assert account_1_change
107108
# public key should be the same as the test_account
108-
assert(account_1_change.key_pair.is_equal(test_account.key_pair))
109+
assert account_1_change.key_pair.is_equal(test_account.key_pair)
109110
# adress still the same
110-
assert(account_1_change.address == account_1.address )
111+
assert account_1_change.address == account_1.address
111112

112113
# test out new key
113114
result = convex.send('(map inc [1 2 3 4 5])', account_1_change)
114-
assert(result is not None)
115+
assert result is not None
115116
assert 'value' in result.model_dump()
116-
assert(result.value == [2, 3, 4, 5, 6])
117+
assert result.value == [2, 3, 4, 5, 6]
117118

118119

119120
def test_convex_api_send_basic_lisp(convex_url: str, test_account: Account):
120121
convex = API(convex_url)
121122
request_amount = convex.request_funds(TEST_FUNDING_AMOUNT, test_account)
122-
assert(request_amount == TEST_FUNDING_AMOUNT)
123+
assert request_amount == TEST_FUNDING_AMOUNT
123124
result = convex.send('(map inc [1 2 3 4 5])', test_account)
124-
assert(result is not None)
125+
assert result is not None
125126
assert 'value' in result.model_dump()
126-
assert(result.value == [2, 3, 4, 5, 6])
127+
assert result.value == [2, 3, 4, 5, 6]
128+
127129

128130
def test_convex_api_get_balance_no_funds(convex_url: str):
129131
convex = API(convex_url)
130132
key_pair = KeyPair()
131133
account = convex.create_account(key_pair)
132134
new_balance = convex.get_balance(account)
133-
assert(new_balance == 0)
135+
assert new_balance == 0
136+
134137

135138
def test_convex_api_get_balance_small_funds(convex_url: str, test_account: Account):
136139
convex = API(convex_url)
137140
key_pair = KeyPair()
138141
account = convex.create_account(key_pair)
139142
amount = 100
140143
request_amount = convex.request_funds(amount, account)
141-
assert(request_amount == amount)
144+
assert request_amount == amount
142145
new_balance = convex.get_balance(account)
143-
assert(new_balance == amount)
146+
assert new_balance == amount
147+
144148

145149
def test_convex_api_get_balance_new_account(convex_url: str):
146150
convex = API(convex_url)
147151
key_pair = KeyPair()
148152
account = convex.create_account(key_pair)
149153
amount = TEST_FUNDING_AMOUNT
150154
request_amount = convex.request_funds(amount, account)
151-
assert(request_amount == amount)
155+
assert request_amount == amount
152156
new_balance = convex.get_balance(account)
153-
assert(new_balance == TEST_FUNDING_AMOUNT)
157+
assert new_balance == TEST_FUNDING_AMOUNT
158+
154159

155160
def test_convex_api_call(convex_url: str):
156161

@@ -181,58 +186,61 @@ def test_convex_api_call(convex_url: str):
181186
account = convex.create_account(key_pair)
182187
amount = TEST_FUNDING_AMOUNT
183188
request_amount = convex.request_funds(amount, account)
184-
assert(request_amount == amount)
189+
assert request_amount == amount
185190
result = convex.send(deploy_storage, account)
186-
assert(result is not None)
191+
assert result is not None
187192
contract_address = Account.to_address(result.value)
188-
assert(contract_address)
193+
assert contract_address
189194
test_number = secrets.randbelow(1000)
190195
call_set_result = convex.send(f'(call storage-example(set {test_number}))', account)
191-
assert(call_set_result is not None)
192-
assert(call_set_result.value == test_number)
196+
assert call_set_result is not None
197+
assert call_set_result.value == test_number
193198
call_get_result = convex.query('(call storage-example(get))', account)
194-
assert(call_get_result is not None)
195-
assert(call_get_result.value == test_number)
199+
assert call_get_result is not None
200+
assert call_get_result.value == test_number
196201

197202
# now api calls using language scrypt
198203
"""
199204
convex = API(convex_url, API.LANGUAGE_SCRYPT)
200205
test_number = secrets.randbelow(1000)
201206
call_set_result = convex.send(f'call storage_example set({test_number})', account)
202-
assert(call_set_result['value'] == test_number)
207+
assert call_set_result['value'] == test_number
203208
204209
call_get_result = convex.query('call storage_example get()', account)
205-
assert(call_get_result['value'] == test_number)
210+
assert call_get_result['value'] == test_number
206211
207212
call_get_result = convex.query(f'call {contract_address} get()', account)
208-
assert(call_get_result['value'] == test_number)
213+
assert call_get_result['value'] == test_number
209214
210215
with pytest.raises(ConvexRequestError, match='400'):
211216
call_set_result = convex.send(f'call {contract_address}.set({test_number})', account)
212217
213218
address = convex.get_address('storage_example', account)
214-
assert(address == contract_address)
219+
assert address == contract_address
215220
"""
221+
222+
216223
def test_convex_api_transfer(convex_url: str):
217224
convex = API(convex_url)
218225
key_pair = KeyPair()
219226
account_from = convex.create_account(key_pair)
220227
account_to = convex.create_account(key_pair)
221228
amount = TEST_FUNDING_AMOUNT
222229
request_amount = convex.request_funds(amount, account_from)
223-
assert(request_amount == amount)
230+
assert request_amount == amount
224231

225232
transfer_amount = int(amount / 2)
226233
result = convex.transfer(account_to, transfer_amount, account_from)
227-
assert(result)
228-
assert(result == transfer_amount)
229-
#balance_from = convex.get_balance(account_from)
234+
assert result
235+
assert result == transfer_amount
236+
# balance_from = convex.get_balance(account_from)
230237
balance_to = convex.get_balance(account_to)
231-
assert(balance_to == transfer_amount)
238+
assert balance_to == transfer_amount
239+
232240

233241
def test_convex_api_query_lisp(convex_url: str, test_account: Account):
234242
convex = API(convex_url)
235243
result = convex.query(f'(address {test_account.address})', test_account)
236-
assert(result is not None)
244+
assert result is not None
237245
# return value is the address as a checksum
238-
assert(Account.to_address(result.value) == test_account.address)
246+
assert Account.to_address(result.value) == test_account.address

0 commit comments

Comments
 (0)