def test_modes():
 try:
  x = file('test_file', 'w')
  AreEqual(x.mode, 'w')
  x.close()
  AssertErrorWithMessage(ValueError, 'empty mode string', file, 'abc', '')
  AssertErrorWithMessage(ValueError, "mode string must begin with one of 'r', 'w', 'a' or 'U', not 'p'", file, 'abc', 'p')
  AssertErrorWithMessage(ValueError, "universal newline mode can only be used with modes starting with 'r'", file, 'abc', 'Uw')
  AssertErrorWithMessage(ValueError, "universal newline mode can only be used with modes starting with 'r'", file, 'abc', 'Ua')
  AssertErrorWithMessage(ValueError, "universal newline mode can only be used with modes starting with 'r'", file, 'abc', 'Uw+')
  AssertErrorWithMessage(ValueError, "universal newline mode can only be used with modes starting with 'r'", file, 'abc', 'Ua+')
  AssertError(ValueError, file, 'test_file', 'pU')
  AssertError(ValueError, file, 'test_file', 'pU+')
  AssertError(ValueError, file, 'test_file', 'rFOOBAR')
 finally:
  os.unlink('test_file')

def test_modes ( ) : try : x = file ( 'test_file' , 'w' ) AreEqual ( x . mode , 'w' ) x . close ( ) AssertErrorWithMessage ( ValueError , 'empty mode string' , file , 'abc' , '' ) AssertErrorWithMessage ( ValueError , "mode string must begin with one of 'r', 'w', 'a' or 'U', not 'p'" , file , 'abc' , 'p' ) AssertErrorWithMessage ( ValueError , "universal newline mode can only be used with modes starting with 'r'" , file , 'abc' , 'Uw' ) AssertErrorWithMessage ( ValueError , "universal newline mode can only be used with modes starting with 'r'" , file , 'abc' , 'Ua' ) AssertErrorWithMessage ( ValueError , "universal newline mode can only be used with modes starting with 'r'" , file , 'abc' , 'Uw+' ) AssertErrorWithMessage ( ValueError , "universal newline mode can only be used with modes starting with 'r'" , file , 'abc' , 'Ua+' ) AssertError ( ValueError , file , 'test_file' , 'pU' ) AssertError ( ValueError , file , 'test_file' , 'pU+' ) AssertError ( ValueError , file , 'test_file' , 'rFOOBAR' ) finally : os . unlink ( 'test_file' )
test various strange mode combinations and error reporting .