-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
/
tests.py
30 lines (26 loc) · 1.05 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from django import __version__
from django.core.management import call_command
from django.test import mock, SimpleTestCase
from django.test.utils import patch_logger
from django.utils.six import StringIO
class ShellCommandTestCase(SimpleTestCase):
def test_command_option(self):
with patch_logger('test', 'info') as logger:
call_command(
'shell',
command=(
'import django; from logging import getLogger; '
'getLogger("test").info(django.__version__)'
),
)
self.assertEqual(len(logger), 1)
self.assertEqual(logger[0], __version__)
@mock.patch('django.core.management.commands.shell.select')
@mock.patch('django.core.management.commands.shell.sys.stdin')
@mock.patch('sys.stdout', new_callable=StringIO)
def test_stdin_read(self, stdout, stdin, select):
stdin.read.return_value = 'print(100)'
call_command(
'shell',
)
self.assertEqual(stdout.getvalue().strip(), '100')