1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-02-23 23:43:52 +00:00
scrapy/tests/test_utils_console.py
nyov 509cc8d41e Add support for bpython console.
Adds support for configuration of shells from scrapy.cfg
and SCRAPY_PYTHON_SHELL.

config snippet:

cat <<EOF >> ~/.scrapy.cfg
[settings]
# shell can be one of ipython, bpython or python;
# to be tried as the interactive python console
# (in above order, unless set here).
shell = python
EOF

(closes #270, #1100, #1301)
2015-08-21 01:12:58 +01:00

45 lines
1.1 KiB
Python

import unittest
from scrapy.utils.console import get_shell_embed_func
try:
import bpython
bpy = True
del bpython
except ImportError:
bpy = False
try:
import IPython
ipy = True
del IPython
except ImportError:
ipy = False
class UtilsConsoleTestCase(unittest.TestCase):
def test_get_shell_embed_func(self):
shell = get_shell_embed_func(['invalid'])
self.assertEqual(shell, None)
shell = get_shell_embed_func(['invalid','python'])
self.assertTrue(callable(shell))
self.assertEqual(shell.__name__, '_embed_standard_shell')
@unittest.skipIf(not bpy, 'bpython not available in testenv')
def test_get_shell_embed_func2(self):
shell = get_shell_embed_func(['bpython'])
self.assertTrue(callable(shell))
self.assertEqual(shell.__name__, '_embed_bpython_shell')
@unittest.skipIf(not ipy, 'IPython not available in testenv')
def test_get_shell_embed_func3(self):
# default shell should be 'ipython'
shell = get_shell_embed_func()
self.assertEqual(shell.__name__, '_embed_ipython_shell')
if __name__ == "__main__":
unittest.main()