MCPcopy Index your code
hub / github.com/python/cpython / test_input

Method test_input

Lib/test/test_builtin.py:1828–1861  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1826 self.assertEqual(mod10(exp=6, base=2), 4)
1827
1828 def test_input(self):
1829 self.write_testfile()
1830 fp = open(TESTFN, encoding="utf-8")
1831 savestdin = sys.stdin
1832 savestdout = sys.stdout # Eats the echo
1833 try:
1834 sys.stdin = fp
1835 sys.stdout = BitBucket()
1836 self.assertEqual(input(), "1+1")
1837 self.assertEqual(input(), 'The quick brown fox jumps over the lazy dog.')
1838 self.assertEqual(input('testing\n'), 'Dear John')
1839
1840 # SF 1535165: don't segfault on closed stdin
1841 # sys.stdout must be a regular file for triggering
1842 sys.stdout = savestdout
1843 sys.stdin.close()
1844 self.assertRaises(ValueError, input)
1845
1846 sys.stdout = BitBucket()
1847 sys.stdin = io.StringIO("NULL\0")
1848 self.assertRaises(TypeError, input, 42, 42)
1849 sys.stdin = io.StringIO(" 'whitespace'")
1850 self.assertEqual(input(), " 'whitespace'")
1851 sys.stdin = io.StringIO()
1852 self.assertRaises(EOFError, input)
1853
1854 del sys.stdout
1855 self.assertRaises(RuntimeError, input, 'prompt')
1856 del sys.stdin
1857 self.assertRaises(RuntimeError, input, 'prompt')
1858 finally:
1859 sys.stdin = savestdin
1860 sys.stdout = savestdout
1861 fp.close()
1862
1863 def test_input_gh130163(self):
1864 class X(io.StringIO):

Callers

nothing calls this directly

Calls 7

write_testfileMethod · 0.95
BitBucketClass · 0.85
inputFunction · 0.85
openFunction · 0.50
assertEqualMethod · 0.45
closeMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected