Skip to content

Commit

Permalink
add sjis loop test
Browse files Browse the repository at this point in the history
  • Loading branch information
mogproject committed Sep 1, 2015
1 parent f6231a0 commit 3a910ab
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tests/easy_menu/view/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
from __future__ import division, print_function, absolute_import, unicode_literals

import tempfile
import io

from easy_menu.view import Terminal
from easy_menu.controller import CommandExecutor
from easy_menu.exceptions import InterruptError
from tests.universal import TestCase
from tests.easy_menu.logger.mock_logger import MockLogger
from tests.fake_io import FakeInput, FakeOutput
from tests.fake_io import FakeInput


class TestTerminal(TestCase):
Expand Down Expand Up @@ -389,3 +390,32 @@ def test_loop(self):
(6, '[INFO] Command started: echo executing 9'),
(6, '[INFO] Command ended with return code: 0'),
])

def test_loop_sjis(self):
self.maxDiff = None

root_menu = {'メインメニュー': [{'メニュー 1': "echo 'あいうえお'"}]}

_in = FakeInput(''.join(['1yx', '0']))

# We use a temporary file due to capture the output of subprocess#call.
with tempfile.TemporaryFile() as out:
t = Terminal(
root_menu, 'ホスト', 'ユーザ', self.get_exec(), _input=_in, _output=out, encoding='sjis', lang='ja_JP')
t.loop()

with io.open('tests/resources/expect/terminal_test_loop_sjis.txt', encoding='sjis') as f:
expect = f.read().splitlines()

out.seek(0)
actual = out.read().splitlines(0)

self.assertEqual(len(actual), len(expect))
for i in range(len(expect)):
self.assertEqual(actual[i].decode('sjis'), expect[i],
'i=%d, actual=%r,expect=%r' % (i, actual[i], expect[i]))

self.assertEqual(t.executor.logger.buffer, [
(6, "[INFO] Command started: echo 'あいうえお'"),
(6, "[INFO] Command ended with return code: 0"),
])
31 changes: 31 additions & 0 deletions tests/resources/expect/terminal_test_loop_sjis.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
�z�X�g��: �z�X�g ���s���[�U: ���[�U
================================================================================
���C�����j���[
--------------------------------------------------------------------------------
[1] | ���j���[ 1
------+-------------------------------------------------------------------------
[0] | �I��
================================================================================
�ԍ�����͂��Ă������� (0-1): �z�X�g��: �z�X�g ���s���[�U: ���[�U
================================================================================
���s�m�F
--------------------------------------------------------------------------------
���j���[ 1 ���s���܂��B
================================================================================
��낵���ł���? (y/n) [n]: �z�X�g��: �z�X�g ���s���[�U: ���[�U
================================================================================
���s: ���j���[ 1
--------------------------------------------------------------------------------
����������
--------------------------------------------------------------------------------
Return code: 0
================================================================================
�����L�[�������ƃ��j���[�ɖ߂�܂�...�z�X�g��: �z�X�g ���s���[�U: ���[�U
================================================================================
���C�����j���[
--------------------------------------------------------------------------------
[1] | ���j���[ 1
------+-------------------------------------------------------------------------
[0] | �I��
================================================================================
�ԍ�����͂��Ă������� (0-1):

0 comments on commit 3a910ab

Please sign in to comment.