def test_logging():
 assert_raises(ValueError, set_log_level, 'foo')
 tempdir = _TempDir()
 test_name = op.join(tempdir, 'test.log')
 with open(fname_log, 'r') as old_log_file:
  old_lines = clean_lines(old_log_file.readlines())
  old_lines.pop((-1))
 with open(fname_log_2, 'r') as old_log_file_2:
  old_lines_2 = clean_lines(old_log_file_2.readlines())
  old_lines_2.pop(14)
  old_lines_2.pop((-1))
 if op.isfile(test_name):
  os.remove(test_name)
 set_log_file(test_name)
 set_log_level('WARNING')
 evoked = read_evokeds(fname_evoked, condition=1)
 with open(test_name) as fid:
  assert_true((fid.readlines() == []))
 evoked = read_evokeds(fname_evoked, condition=1, verbose=False)
 with open(test_name) as fid:
  assert_true((fid.readlines() == []))
 evoked = read_evokeds(fname_evoked, condition=1, verbose='WARNING')
 with open(test_name) as fid:
  assert_true((fid.readlines() == []))
 evoked = read_evokeds(fname_evoked, condition=1, verbose=True)
 with open(test_name, 'r') as new_log_file:
  new_lines = clean_lines(new_log_file.readlines())
 assert_equal(new_lines, old_lines)
 set_log_file(None)
 os.remove(test_name)
 set_log_file(test_name)
 set_log_level('INFO')
 evoked = read_evokeds(fname_evoked, condition=1, verbose='WARNING')
 with open(test_name) as fid:
  assert_true((fid.readlines() == []))
 evoked = read_evokeds(fname_evoked, condition=1, verbose=False)
 with open(test_name) as fid:
  assert_true((fid.readlines() == []))
 evoked = read_evokeds(fname_evoked, condition=1)
 with open(test_name, 'r') as new_log_file:
  new_lines = clean_lines(new_log_file.readlines())
 assert_equal(new_lines, old_lines)
 with warnings.catch_warnings(record=True) as w:
  warnings.simplefilter('always')
  set_log_file(test_name, overwrite=False)
  assert_equal(len(w), 0)
  set_log_file(test_name)
 assert_equal(len(w), 1)
 assert_true(('test_utils.py' in w[0].filename))
 evoked = read_evokeds(fname_evoked, condition=1)
 with open(test_name, 'r') as new_log_file:
  new_lines = clean_lines(new_log_file.readlines())
 assert_equal(new_lines, old_lines_2)
 set_log_file(test_name, overwrite=True)
 evoked = read_evokeds(fname_evoked, condition=1)
 del evoked
 with open(test_name, 'r') as new_log_file:
  new_lines = clean_lines(new_log_file.readlines())
 assert_equal(new_lines, old_lines)

def test_logging ( ) : assert_raises ( ValueError , set_log_level , 'foo' ) tempdir = _TempDir ( ) test_name = op . join ( tempdir , 'test.log' ) with open ( fname_log , 'r' ) as old_log_file : old_lines = clean_lines ( old_log_file . readlines ( ) ) old_lines . pop ( ( - 1 ) ) with open ( fname_log_2 , 'r' ) as old_log_file_2 : old_lines_2 = clean_lines ( old_log_file_2 . readlines ( ) ) old_lines_2 . pop ( 14 ) old_lines_2 . pop ( ( - 1 ) ) if op . isfile ( test_name ) : os . remove ( test_name ) set_log_file ( test_name ) set_log_level ( 'WARNING' ) evoked = read_evokeds ( fname_evoked , condition = 1 ) with open ( test_name ) as fid : assert_true ( ( fid . readlines ( ) == [ ] ) ) evoked = read_evokeds ( fname_evoked , condition = 1 , verbose = False ) with open ( test_name ) as fid : assert_true ( ( fid . readlines ( ) == [ ] ) ) evoked = read_evokeds ( fname_evoked , condition = 1 , verbose = 'WARNING' ) with open ( test_name ) as fid : assert_true ( ( fid . readlines ( ) == [ ] ) ) evoked = read_evokeds ( fname_evoked , condition = 1 , verbose = True ) with open ( test_name , 'r' ) as new_log_file : new_lines = clean_lines ( new_log_file . readlines ( ) ) assert_equal ( new_lines , old_lines ) set_log_file ( None ) os . remove ( test_name ) set_log_file ( test_name ) set_log_level ( 'INFO' ) evoked = read_evokeds ( fname_evoked , condition = 1 , verbose = 'WARNING' ) with open ( test_name ) as fid : assert_true ( ( fid . readlines ( ) == [ ] ) ) evoked = read_evokeds ( fname_evoked , condition = 1 , verbose = False ) with open ( test_name ) as fid : assert_true ( ( fid . readlines ( ) == [ ] ) ) evoked = read_evokeds ( fname_evoked , condition = 1 ) with open ( test_name , 'r' ) as new_log_file : new_lines = clean_lines ( new_log_file . readlines ( ) ) assert_equal ( new_lines , old_lines ) with warnings . catch_warnings ( record = True ) as w : warnings . simplefilter ( 'always' ) set_log_file ( test_name , overwrite = False ) assert_equal ( len ( w ) , 0 ) set_log_file ( test_name ) assert_equal ( len ( w ) , 1 ) assert_true ( ( 'test_utils.py' in w [ 0 ] . filename ) ) evoked = read_evokeds ( fname_evoked , condition = 1 ) with open ( test_name , 'r' ) as new_log_file : new_lines = clean_lines ( new_log_file . readlines ( ) ) assert_equal ( new_lines , old_lines_2 ) set_log_file ( test_name , overwrite = True ) evoked = read_evokeds ( fname_evoked , condition = 1 ) del evoked with open ( test_name , 'r' ) as new_log_file : new_lines = clean_lines ( new_log_file . readlines ( ) ) assert_equal ( new_lines , old_lines )
test logging context manager .