"""
try:
sys.ps1
+ delete_ps1_after = False
except AttributeError:
sys.ps1 = ">>> "
+ delete_ps1_after = True
try:
- sys.ps2
+ _ps2 = sys.ps2
+ delete_ps2_after = False
except AttributeError:
sys.ps2 = "... "
+ delete_ps2_after = True
+
cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
if banner is None:
self.write("Python %s on %s\n%s\n(%s)\n" %
if _quit is not None:
builtins.quit = _quit
+ if delete_ps1_after:
+ del sys.ps1
+
+ if delete_ps2_after:
+ del sys.ps2
+
if exitmsg is None:
self.write('now exiting %s...\n' % self.__class__.__name__)
elif exitmsg != '':
self.mock_sys()
def test_ps1(self):
- self.infunc.side_effect = EOFError('Finished')
+ self.infunc.side_effect = [
+ "import code",
+ "code.sys.ps1",
+ EOFError('Finished')
+ ]
self.console.interact()
- self.assertEqual(self.sysmod.ps1, '>>> ')
+ output = ''.join(''.join(call[1]) for call in self.stdout.method_calls)
+ self.assertIn('>>> ', output)
+ self.assertNotHasAttr(self.sysmod, 'ps1')
+
+ self.infunc.side_effect = [
+ "import code",
+ "code.sys.ps1",
+ EOFError('Finished')
+ ]
self.sysmod.ps1 = 'custom1> '
self.console.interact()
+ output = ''.join(''.join(call[1]) for call in self.stdout.method_calls)
+ self.assertIn('custom1> ', output)
self.assertEqual(self.sysmod.ps1, 'custom1> ')
def test_ps2(self):
- self.infunc.side_effect = EOFError('Finished')
+ self.infunc.side_effect = [
+ "import code",
+ "code.sys.ps2",
+ EOFError('Finished')
+ ]
self.console.interact()
- self.assertEqual(self.sysmod.ps2, '... ')
+ output = ''.join(''.join(call[1]) for call in self.stdout.method_calls)
+ self.assertIn('... ', output)
+ self.assertNotHasAttr(self.sysmod, 'ps2')
+
+ self.infunc.side_effect = [
+ "import code",
+ "code.sys.ps2",
+ EOFError('Finished')
+ ]
self.sysmod.ps2 = 'custom2> '
self.console.interact()
+ output = ''.join(''.join(call[1]) for call in self.stdout.method_calls)
+ self.assertIn('custom2> ', output)
self.assertEqual(self.sysmod.ps2, 'custom2> ')
def test_console_stderr(self):