Skip to content

Commit

Permalink
Fix console tests hanging so we can unpin pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-Kamina committed Sep 9, 2024
1 parent 7a9d7c0 commit 8525b5f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
5 changes: 3 additions & 2 deletions deluge/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import traceback

import pytest
import pytest_twisted
from twisted.internet import defer, protocol, reactor
from twisted.internet.defer import Deferred
from twisted.internet.error import CannotListenError
Expand Down Expand Up @@ -130,7 +131,7 @@ def outConnectionLost(self): # NOQA: N802
with open(self.logfile, 'w') as f:
f.write(self.log_output)

@defer.inlineCallbacks
@pytest_twisted.inlineCallbacks
def kill(self):
"""Kill the running process.
Expand Down Expand Up @@ -296,7 +297,7 @@ def start_core(
if extra_callbacks:
callbacks.extend(extra_callbacks)

@defer.inlineCallbacks
@pytest_twisted.inlineCallbacks
def shutdown_daemon():
username, password = get_localhost_auth()
client = Client()
Expand Down
4 changes: 2 additions & 2 deletions deluge/tests/daemon_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#

import pytest
from twisted.internet import defer
import pytest_twisted
from twisted.internet.error import CannotListenError

import deluge.component as component
Expand All @@ -29,7 +29,7 @@ def terminate_core(self, *args):
d = self.core.kill()
return d

@defer.inlineCallbacks
@pytest_twisted.inlineCallbacks
def start_core(
self,
arg,
Expand Down
10 changes: 5 additions & 5 deletions deluge/tests/test_maybe_coroutine.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import pytest
import pytest_twisted
import twisted.python.failure
from twisted.internet import defer, reactor, task
from twisted.internet import reactor, task
from twisted.internet.defer import maybeDeferred

from deluge.decorators import maybe_coroutine


@defer.inlineCallbacks
@pytest_twisted.inlineCallbacks
def inline_func():
result = yield task.deferLater(reactor, 0, lambda: 'function_result')
return result


@defer.inlineCallbacks
@pytest_twisted.inlineCallbacks
def inline_error():
raise Exception('function_error')
yield
Expand All @@ -35,13 +35,13 @@ async def coro_error():
raise Exception('function_error')


@defer.inlineCallbacks
@pytest_twisted.inlineCallbacks
def coro_func_from_inline():
result = yield coro_func()
return result


@defer.inlineCallbacks
@pytest_twisted.inlineCallbacks
def coro_error_from_inline():
result = yield coro_error()
return result
Expand Down
16 changes: 10 additions & 6 deletions deluge/tests/test_ui_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import pytest
import pytest_twisted
from twisted.internet import defer

import deluge
import deluge.component as component
Expand Down Expand Up @@ -353,7 +352,8 @@ def test_console_command_add(self):
fd = StringFileDescriptor(sys.stdout)
self.patch(sys, 'stdout', fd)

yield self.exec_command()
with mock.patch('deluge.ui.console.main.ConsoleUI.quit', autospec=True):
yield self.exec_command()

std_output = fd.out.getvalue()
assert (
Expand All @@ -377,7 +377,8 @@ def test_console_command_add_move_completed(self):
fd = StringFileDescriptor(sys.stdout)
self.patch(sys, 'stdout', fd)

yield self.exec_command()
with mock.patch('deluge.ui.console.main.ConsoleUI.quit', autospec=True):
yield self.exec_command()

std_output = fd.out.getvalue()
assert std_output.endswith(
Expand All @@ -391,19 +392,22 @@ async def test_console_command_status(self):
self.patch_arg_command(['status'])
self.patch(sys, 'stdout', fd)

await self.exec_command()
with mock.patch('deluge.ui.console.main.ConsoleUI.quit', autospec=True):
await self.exec_command()

std_output = fd.out.getvalue()
assert std_output.startswith('Total upload: ')
assert std_output.endswith(' Moving: 0\n')

@defer.inlineCallbacks
@pytest_twisted.inlineCallbacks
def test_console_command_config_set_download_location(self):
fd = StringFileDescriptor(sys.stdout)
self.patch_arg_command(['config --set download_location /downloads'])
self.patch(sys, 'stdout', fd)

yield self.exec_command()
with mock.patch('deluge.ui.console.main.ConsoleUI.quit', autospec=True):
yield self.exec_command()

std_output = fd.out.getvalue()
assert std_output.startswith('Setting "download_location" to: \'/downloads\'')
assert std_output.endswith('Configuration value successfully updated.\n')
Expand Down
6 changes: 3 additions & 3 deletions deluge/tests/test_web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import pytest
import pytest_twisted
from twisted.internet import defer, reactor
from twisted.internet import reactor
from twisted.web.client import Agent, FileBodyProducer
from twisted.web.http_headers import Headers
from twisted.web.static import File
Expand Down Expand Up @@ -45,7 +45,7 @@ def on_connect(result):
def test_disconnect(self):
d = self.deluge_web.web_api.connect(self.host_id)

@defer.inlineCallbacks
@pytest_twisted.inlineCallbacks
def on_connect(result):
assert self.deluge_web.web_api.connected()
yield self.deluge_web.web_api.disconnect()
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_set_config(self):
assert config['pwd_sha1'] != web_config['pwd_sha1']
assert config['sessions'] != web_config['sessions']

@defer.inlineCallbacks
@pytest_twisted.inlineCallbacks
def get_host_status(self):
host = list(self.deluge_web.web_api.hostlist.get_host_info(self.host_id))
host[3] = 'Online'
Expand Down
2 changes: 1 addition & 1 deletion requirements-ci.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-r requirements.txt
-r requirements-tests.txt
pytest==7.4.2
pytest
libtorrent==2.0.7

0 comments on commit 8525b5f

Please sign in to comment.