Back to index

python3.2  3.2.2
Public Member Functions
test.test_print.TestPrint Class Reference

List of all members.

Public Member Functions

def check
def test_print

Detailed Description

Definition at line 51 of file test_print.py.


Member Function Documentation

def test.test_print.TestPrint.check (   self,
  expected,
  args,
  sep = NotDefined,
  end = NotDefined,
  file = NotDefined 
)

Definition at line 53 of file test_print.py.

00053 
00054             sep=NotDefined, end=NotDefined, file=NotDefined):
00055         # Capture sys.stdout in a StringIO.  Call print with args,
00056         #  and with sep, end, and file, if they're defined.  Result
00057         #  must match expected.
00058 
00059         # Look up the actual function to call, based on if sep, end, and file
00060         #  are defined
00061         fn = dispatch[(sep is not NotDefined,
00062                        end is not NotDefined,
00063                        file is not NotDefined)]
00064 
00065         with support.captured_stdout() as t:
00066             fn(args, sep, end, file)
00067 
00068         self.assertEqual(t.getvalue(), expected)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 69 of file test_print.py.

00069 
00070     def test_print(self):
00071         def x(expected, args, sep=NotDefined, end=NotDefined):
00072             # Run the test 2 ways: not using file, and using
00073             #  file directed to a StringIO
00074 
00075             self.check(expected, args, sep=sep, end=end)
00076 
00077             # When writing to a file, stdout is expected to be empty
00078             o = StringIO()
00079             self.check('', args, sep=sep, end=end, file=o)
00080 
00081             # And o will contain the expected output
00082             self.assertEqual(o.getvalue(), expected)
00083 
00084         x('\n', ())
00085         x('a\n', ('a',))
00086         x('None\n', (None,))
00087         x('1 2\n', (1, 2))
00088         x('1   2\n', (1, ' ', 2))
00089         x('1*2\n', (1, 2), sep='*')
00090         x('1 s', (1, 's'), end='')
00091         x('a\nb\n', ('a', 'b'), sep='\n')
00092         x('1.01', (1.0, 1), sep='', end='')
00093         x('1*a*1.3+', (1, 'a', 1.3), sep='*', end='+')
00094         x('a\n\nb\n', ('a\n', 'b'), sep='\n')
00095         x('\0+ +\0\n', ('\0', ' ', '\0'), sep='+')
00096 
00097         x('a\n b\n', ('a\n', 'b'))
00098         x('a\n b\n', ('a\n', 'b'), sep=None)
00099         x('a\n b\n', ('a\n', 'b'), end=None)
00100         x('a\n b\n', ('a\n', 'b'), sep=None, end=None)
00101 
00102         x('*\n', (ClassWith__str__('*'),))
00103         x('abc 1\n', (ClassWith__str__('abc'), 1))
00104 
00105 #        # 2.x unicode tests
00106 #        x(u'1 2\n', ('1', u'2'))
00107 #        x(u'u\1234\n', (u'u\1234',))
00108 #        x(u'  abc 1\n', (' ', ClassWith__str__(u'abc'), 1))
00109 
00110         # errors
00111         self.assertRaises(TypeError, print, '', sep=3)
00112         self.assertRaises(TypeError, print, '', end=3)
00113         self.assertRaises(AttributeError, print, '', file='')

Here is the call graph for this function:


The documentation for this class was generated from the following file: