[CLN] try - finally blocks

This commit is contained in:
Benedek Racz 2019-12-06 20:43:28 +01:00
parent b9ab8d76a0
commit f2822c0d42
2 changed files with 13 additions and 19 deletions

View File

@ -24,17 +24,17 @@ from . import PexpectTestCase
class SplitCommandLineTestCase(PexpectTestCase.PexpectTestCase):
def testSplitSizes(self):
assert len(wexpect.split_command_line(r'')) == 0
assert len(wexpect.split_command_line(r'one')) == 1
assert len(wexpect.split_command_line(r'one two')) == 2
assert len(wexpect.split_command_line(r'one two')) == 2
assert len(wexpect.split_command_line(r'one two')) == 2
assert len(wexpect.split_command_line(r'one^ one')) == 1
assert len(wexpect.split_command_line('\'one one\'')) == 1
assert len(wexpect.split_command_line(r'one\"one')) == 1
assert len(wexpect.split_command_line(r"This^' is a^'^ test")) == 3
self.assertEqual(len(wexpect.split_command_line(r'')), 0)
self.assertEqual(len(wexpect.split_command_line(r'one')), 1)
self.assertEqual(len(wexpect.split_command_line(r'one two')), 2)
self.assertEqual(len(wexpect.split_command_line(r'one two')), 2)
self.assertEqual(len(wexpect.split_command_line(r'one two')), 2)
self.assertEqual(len(wexpect.split_command_line(r'one^ one')), 1)
self.assertEqual(len(wexpect.split_command_line('\'one one\'')), 1)
self.assertEqual(len(wexpect.split_command_line(r'one\"one')), 1)
self.assertEqual(len(wexpect.split_command_line(r"This^' is a^'^ test")), 3)
def test_join_args(self):
def testJoinArgs(self):
cmd = 'foo bar "b a z"'
cmd2 = wexpect.join_args(wexpect.split_command_line(cmd))
self.assertEqual(cmd2, cmd)

View File

@ -1655,10 +1655,8 @@ class Wtty:
try:
mode = self.__consin.GetConsoleMode()
ret = (mode & 0x0004) > 0
finally:
self.switchBack()
except:
self.switchBack()
raise
return ret
def getwinsize(self):
@ -1668,10 +1666,8 @@ class Wtty:
self.switchTo()
try:
size = self.__consout.GetConsoleScreenBufferInfo()['Size']
finally:
self.switchBack()
except:
self.switchBack()
raise
return (size.Y, size.X)
def setwinsize(self, r, c):
@ -1680,10 +1676,8 @@ class Wtty:
self.switchTo()
try:
self.__consout.SetConsoleScreenBufferSize(win32console.PyCOORDType(c, r))
except:
finally:
self.switchBack()
raise
self.switchBack()
def interact(self):
"""Displays the child console for interaction."""