Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary async statements #7139

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def test_channels_peers_mapping_drop_excess_peers(self):
assert len(mapping._peers_channels) == 0
assert len(mapping._channels_dict) == 0

async def test_get_known_subscribed_peers_for_node(self):
def test_get_known_subscribed_peers_for_node(self):
key = default_eccrypto.generate_key("curve25519")
with db_session:
channel = self.overlay(0).mds.ChannelMetadata(origin_id=0, infohash=random_infohash(), sign_with=key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ def test_get_gui_process():
GuiProcessWatcher.get_gui_process()


async def test_check_gui_process_working(watcher):
def test_check_gui_process_working(watcher):
watcher.check_gui_process()
assert not watcher.shutdown_callback.called
assert not watcher.shutdown_callback_called


async def test_check_gui_process_zombie(watcher):
def test_check_gui_process_zombie(watcher):
watcher.gui_process.status.return_value = psutil.STATUS_ZOMBIE
watcher.check_gui_process()
assert watcher.shutdown_callback.called
assert watcher.shutdown_callback_called


async def test_check_gui_process_not_running(watcher):
def test_check_gui_process_not_running(watcher):
watcher.gui_process.is_running.return_value = False
watcher.check_gui_process()
assert not watcher.gui_process.status.called
Expand Down
14 changes: 7 additions & 7 deletions src/tribler/core/components/ipv8/eva/tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def start(self):
self.container[self.peer] = self


async def test_can_be_send_immediately(scheduler: Scheduler):
def test_can_be_send_immediately(scheduler: Scheduler):
scheduler.eva.incoming = {}
scheduler.eva.outgoing = {}
assert scheduler.can_be_send_immediately(MockTransfer(peer='peer', container=scheduler.eva.incoming))
Expand All @@ -54,7 +54,7 @@ async def test_can_be_send_immediately(scheduler: Scheduler):
assert not scheduler.can_be_send_immediately(MockTransfer(peer='peer', container=scheduler.eva.outgoing))


async def test_is_simultaneously_served_transfers_limit_not_exceeded(scheduler: Scheduler):
def test_is_simultaneously_served_transfers_limit_not_exceeded(scheduler: Scheduler):
# In this test we will try to exceed `max_simultaneous_transfers` limit.
scheduler.eva.settings.max_simultaneous_transfers = 2

Expand Down Expand Up @@ -83,7 +83,7 @@ async def test_is_simultaneously_served_transfers_limit_not_exceeded(scheduler:
assert scheduler._is_simultaneously_served_transfers_limit_exceeded()


async def test_is_simultaneously_served_transfers_limit_exceeded(scheduler: Scheduler):
def test_is_simultaneously_served_transfers_limit_exceeded(scheduler: Scheduler):
# In this test we will try to exceed `max_simultaneous_transfers` limit.
scheduler.eva.settings.max_simultaneous_transfers = 2

Expand All @@ -100,7 +100,7 @@ async def test_is_simultaneously_served_transfers_limit_exceeded(scheduler: Sche
assert scheduler._is_simultaneously_served_transfers_limit_exceeded()


async def test_schedule(scheduler: Scheduler):
def test_schedule(scheduler: Scheduler):
scheduler.can_be_send_immediately = Mock(return_value=False)

scheduler.schedule(transfer=MockTransfer())
Expand All @@ -109,7 +109,7 @@ async def test_schedule(scheduler: Scheduler):
assert len(scheduler.scheduled) == 1


async def test_start_transfer(scheduler: Scheduler):
def test_start_transfer(scheduler: Scheduler):
scheduler.can_be_send_immediately = Mock(return_value=True)
transfer = MockTransfer()
transfer.start = Mock(wraps=transfer.start)
Expand Down Expand Up @@ -143,7 +143,7 @@ def _transform_to_str(eva, transfers: Iterable[Transfer]) -> Iterable[str]:
yield f'{transfer.peer}_{container}'


async def test_transfers_that_can_be_send(scheduler: Scheduler):
def test_transfers_that_can_be_send(scheduler: Scheduler):
_fill_test_data(scheduler)

# Regarding the test data, all scheduled transfer should be ready to send
Expand All @@ -154,7 +154,7 @@ async def test_transfers_that_can_be_send(scheduler: Scheduler):
assert str_representation == ['peer1_out', 'peer2_in', 'peer3_in', 'peer3_out']


async def test_send_scheduled(scheduler: Scheduler):
def test_send_scheduled(scheduler: Scheduler):
_fill_test_data(scheduler)

# Regarding the test data, all scheduled transfer should be ready to send
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def transfer():


@pytest.mark.looptime(start=42)
async def test_update(transfer: Transfer):
def test_update(transfer: Transfer):
# In this test we ensure that `transfer.update` method sets `time.time` value
# to `transfer.updated` property.
transfer.update()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ async def window() -> TransferWindow:
return TransferWindow(start=0, size=10)


async def test_constructor(window: TransferWindow):
def test_constructor(window: TransferWindow):
assert len(window.blocks) == 10
assert all(not block for block in window.blocks)


async def test_add(window: TransferWindow):
def test_add(window: TransferWindow):
window.add(0, b'first')
window.add(0, b'first')
window.add(9, b'last')
Expand All @@ -25,15 +25,15 @@ async def test_add(window: TransferWindow):
assert not window.is_finished()


async def test_finished(window: TransferWindow):
def test_finished(window: TransferWindow):
for i in range(10):
window.add(i, b'block')

assert window.processed == 10
assert window.is_finished()


async def test_consecutive_blocks(window: TransferWindow):
def test_consecutive_blocks(window: TransferWindow):
window.add(0, b'first')
window.add(1, b'second')
window.add(3, b'fourth')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@


@pytest.mark.parametrize('tag', VALID_TAGS)
async def test_valid_tags(tag):
def test_valid_tags(tag):
validate_resource(tag) # no exception
assert is_valid_resource(tag)


@pytest.mark.parametrize('tag', INVALID_TAGS)
async def test_invalid(tag):
def test_invalid(tag):
assert not is_valid_resource(tag)
with pytest.raises(ValueError):
validate_resource(tag)


async def test_correct_operation():
def test_correct_operation():
for operation in Operation:
validate_operation(operation) # no exception
validate_operation(operation.value) # no exception


async def test_incorrect_operation():
def test_incorrect_operation():
max_operation = max(Operation)
with pytest.raises(ValueError):
validate_operation(max_operation.value + 1)


async def test_correct_relation():
def test_correct_relation():
for relation in ResourceType:
validate_resource_type(relation) # no exception
validate_resource_type(relation.value) # no exception


async def test_incorrect_relation():
def test_incorrect_relation():
max_relation = max(ResourceType)
with pytest.raises(ValueError):
validate_operation(max_relation.value + 1)
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ def operations_requests():
return OperationsRequests()


async def test_add_peer(operations_requests):
def test_add_peer(operations_requests):
operations_requests.register_peer('peer', number_of_responses=10)
assert operations_requests.requests['peer'] == 10


async def test_clear_requests(operations_requests):
def test_clear_requests(operations_requests):
operations_requests.register_peer('peer', number_of_responses=10)
assert len(operations_requests.requests) == 1

operations_requests.clear_requests()
assert len(operations_requests.requests) == 0


async def test_valid_peer(operations_requests):
def test_valid_peer(operations_requests):
operations_requests.register_peer('peer', number_of_responses=10)
operations_requests.validate_peer('peer')


async def test_missed_peer(operations_requests):
def test_missed_peer(operations_requests):
with pytest.raises(ValueError):
operations_requests.validate_peer('peer')


async def test_invalid_peer(operations_requests):
def test_invalid_peer(operations_requests):
operations_requests.register_peer('peer', number_of_responses=1)
operations_requests.validate_peer('peer')

Expand Down
Loading