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

Method test_print

Lib/test/test_print.py:63–101  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

61 self.assertEqual(t.getvalue(), expected)
62
63 def test_print(self):
64 def x(expected, args, sep=NotDefined, end=NotDefined):
65 # Run the test 2 ways: not using file, and using
66 # file directed to a StringIO.
67
68 self.check(expected, args, sep=sep, end=end)
69
70 # When writing to a file, stdout is expected to be empty
71 o = StringIO()
72 self.check('', args, sep=sep, end=end, file=o)
73
74 # And o will contain the expected output
75 self.assertEqual(o.getvalue(), expected)
76
77 x('\n', ())
78 x('a\n', ('a',))
79 x('None\n', (None,))
80 x('1 2\n', (1, 2))
81 x('1 2\n', (1, ' ', 2))
82 x('1*2\n', (1, 2), sep='*')
83 x('1 s', (1, 's'), end='')
84 x('a\nb\n', ('a', 'b'), sep='\n')
85 x('1.01', (1.0, 1), sep='', end='')
86 x('1*a*1.3+', (1, 'a', 1.3), sep='*', end='+')
87 x('a\n\nb\n', ('a\n', 'b'), sep='\n')
88 x('\0+ +\0\n', ('\0', ' ', '\0'), sep='+')
89
90 x('a\n b\n', ('a\n', 'b'))
91 x('a\n b\n', ('a\n', 'b'), sep=None)
92 x('a\n b\n', ('a\n', 'b'), end=None)
93 x('a\n b\n', ('a\n', 'b'), sep=None, end=None)
94
95 x('*\n', (ClassWith__str__('*'),))
96 x('abc 1\n', (ClassWith__str__('abc'), 1))
97
98 # errors
99 self.assertRaises(TypeError, print, '', sep=3)
100 self.assertRaises(TypeError, print, '', end=3)
101 self.assertRaises(AttributeError, print, '', file='')
102
103 def test_print_flush(self):
104 # operation of the flush flag

Callers

nothing calls this directly

Calls 3

ClassWith__str__Class · 0.85
xFunction · 0.50
assertRaisesMethod · 0.45

Tested by

no test coverage detected