Skip to content

Commit e4dcd93

Browse files
committed
picnixz suggestions
1 parent 730f8bc commit e4dcd93

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Lib/test/test_getpass.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
except ImportError:
1515
pwd = None
1616

17+
try:
18+
import msvcrt
19+
20+
except ImportError:
21+
mscvrt = None
22+
1723
@mock.patch('os.environ')
1824
class GetpassGetuserTest(unittest.TestCase):
1925

@@ -162,15 +168,8 @@ def test_falls_back_to_stdin(self):
162168
self.assertIn('Password:', stderr.getvalue())
163169

164170

165-
try:
166-
import msvcrt
167-
except ImportError:
168-
msvcrt_available = False
169-
else:
170-
msvcrt_available = True
171-
171+
@unittest.skipIf(msvcrt is None, 'tests require system with msvcrt (Windows)')
172172
@unittest.skipUnless(support.MS_WINDOWS, "Windows-specific tests")
173-
@unittest.skipUnless(msvcrt_available, 'tests require system with msvcrt (Windows)')
174173
class WinGetpassTest(unittest.TestCase):
175174

176175
def test_uses_msvcrt_directly(self):
@@ -187,8 +186,10 @@ def test_uses_msvcrt_directly(self):
187186
mock_stream.flush.assert_called()
188187

189188
def test_handles_backspace(self):
190-
with mock.patch('msvcrt.getch') as getch, \
191-
mock.patch('msvcrt.putch') as putch:
189+
with (
190+
mock.patch('msvcrt.getch') as getch,
191+
mock.patch('msvcrt.putch') as putch,
192+
):
192193
getch.side_effect = [b'a', b'b', b'\b', b'c', b'\r']
193194
result = getpass.win_getpass()
194195
self.assertEqual(result, 'ac')

0 commit comments

Comments
 (0)