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

Add TerminalConsole test_without_start_listening #6224

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/test_extension_telnet.py
Expand Up @@ -50,3 +50,29 @@ def test_custom_credentials(self):
d = portal.login(creds, None, ITelnetProtocol)
yield d
console.stop_listening()


class TestWithStartListening(unittest.TestCase):
def test_with_start_Lintening(self):
"""
Calls are made in the correct order so there should be no problems.
"""
telnet_console = TelnetConsole(crawler=get_crawler())
telnet_console.start_listening() # Called as expected.
telnet_console.stop_listening()


class TestWithoutStartListening(unittest.TestCase):
def test_without_start_Lintening(self):
"""
Calls are made in an incorrect order so `self.port` is never initialized.
Class variables should be initialized in the .__init__() method but .port
is not. This raises an AttributeError as discussed in scrapy/scrapy#2702
"""
telnet_console = TelnetConsole(crawler=get_crawler())
# .start_listening() method should be called but developers are imperfect
# telnet_console.start_listening()
with self.assertRaises(
AttributeError, msg="'TelnetConsole' object has no attribute 'port'"
):
telnet_console.stop_listening()