xonsh/tests/test_replay.py

65 lines
1.4 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2015-08-23 16:50:54 -04:00
"""Tests the xonsh replay functionality."""
from __future__ import unicode_literals, print_function
import os
import builtins
from contextlib import contextmanager
import nose
from nose.tools import assert_equal, assert_true
from xonsh.tools import swap
from xonsh.shell import Shell
from xonsh.replay import Replayer
2015-10-20 17:53:12 -04:00
from tools import ON_MAC, skip_if
2015-12-19 17:29:48 -05:00
SHELL = Shell({'PATH': []})
2015-08-23 17:00:26 -04:00
HISTDIR = os.path.join(os.path.dirname(__file__), 'histories')
2015-08-23 16:50:54 -04:00
def run_replay(re_file):
with swap(builtins, '__xonsh_shell__', SHELL):
r = Replayer(re_file)
hist = r.replay()
return hist
def cleanup_replay(hist):
fname = hist.filename
del hist
if os.path.isfile(fname):
os.remove(fname)
2015-08-23 17:00:26 -04:00
2015-08-23 16:50:54 -04:00
@contextmanager
def a_replay(re_file):
hist = run_replay(re_file)
yield hist
cleanup_replay(hist)
2015-10-20 17:53:12 -04:00
@skip_if(ON_MAC)
2015-08-23 16:50:54 -04:00
def test_echo():
2015-08-23 17:00:26 -04:00
f = os.path.join(HISTDIR, 'echo.json')
2015-08-23 16:50:54 -04:00
with a_replay(f) as hist:
yield assert_equal, 2, len(hist)
2015-08-23 17:00:26 -04:00
2015-10-20 17:53:12 -04:00
@skip_if(ON_MAC)
2015-08-23 16:50:54 -04:00
def test_reecho():
2015-08-23 17:00:26 -04:00
f = os.path.join(HISTDIR, 'echo.json')
2015-08-23 16:50:54 -04:00
with a_replay(f) as hist:
yield assert_equal, 2, len(hist)
2015-08-23 17:00:26 -04:00
2015-10-20 17:53:12 -04:00
@skip_if(ON_MAC)
2015-08-23 19:29:35 -04:00
def test_simple_python():
f = os.path.join(HISTDIR, 'simple-python.json')
with a_replay(f) as hist:
yield assert_equal, 4, len(hist)
yield assert_equal, "print('The Turtles')", hist.inps[0].strip()
2015-08-23 16:50:54 -04:00
if __name__ == '__main__':
nose.runmodule()