def test_hist_flush_with_hist_control(hist, xonsh_builtins):
 hf = hist.flush()
 assert (hf is None)
 xonsh_builtins.__xonsh_env__['HISTCONTROL'] = 'ignoredups,ignoreerr'
 hist.append({'inp': 'ls foo1', 'rtn': 0})
 hist.append({'inp': 'ls foo1', 'rtn': 1})
 hist.append({'inp': 'ls foo1', 'rtn': 0})
 hist.append({'inp': 'ls foo2', 'rtn': 2})
 hist.append({'inp': 'ls foo3', 'rtn': 0})
 hf = hist.flush()
 assert (hf is not None)
 while hf.is_alive():
  pass
 assert (len(hist.buffer) == 0)
 with LazyJSON(hist.filename) as lj:
  cmds = list(lj['cmds'])
  assert (len(cmds) == 2)
  assert ([x['inp'] for x in cmds] == ['ls foo1', 'ls foo3'])
  assert ([x['rtn'] for x in cmds] == [0, 0])

def test_hist_flush_with_hist_control ( hist , xonsh_builtins ) : hf = hist . flush ( ) assert ( hf is None ) xonsh_builtins . __xonsh_env__ [ 'HISTCONTROL' ] = 'ignoredups,ignoreerr' hist . append ( { 'inp' : 'ls foo1' , 'rtn' : 0 } ) hist . append ( { 'inp' : 'ls foo1' , 'rtn' : 1 } ) hist . append ( { 'inp' : 'ls foo1' , 'rtn' : 0 } ) hist . append ( { 'inp' : 'ls foo2' , 'rtn' : 2 } ) hist . append ( { 'inp' : 'ls foo3' , 'rtn' : 0 } ) hf = hist . flush ( ) assert ( hf is not None ) while hf . is_alive ( ) : pass assert ( len ( hist . buffer ) == 0 ) with LazyJSON ( hist . filename ) as lj : cmds = list ( lj [ 'cmds' ] ) assert ( len ( cmds ) == 2 ) assert ( [ x [ 'inp' ] for x in cmds ] == [ 'ls foo1' , 'ls foo3' ] ) assert ( [ x [ 'rtn' ] for x in cmds ] == [ 0 , 0 ] )
verify explicit flushing of the history works .