xonsh/tests/test_replay.py

59 lines
1.3 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
2016-06-22 23:20:37 +03:00
import pytest
2015-08-23 16:50:54 -04:00
from xonsh.tools import swap
from xonsh.shell import Shell
from xonsh.replay import Replayer
2016-06-28 13:16:12 +03:00
from tools import skip_if_on_darwin
2015-10-20 17:53:12 -04:00
2016-06-28 13:47:35 +03:00
SHELL = Shell({'PATH': []})
HISTDIR = os.path.join(os.path.dirname(__file__), 'histories')
def run_replay(re_file):
with swap(builtins, '__xonsh_shell__', SHELL):
with swap(builtins, '__xonsh_exit__', False):
r = Replayer(re_file)
hist = r.replay()
return hist
2015-08-23 16:50:54 -04:00
def cleanup_replay(hist):
2015-08-23 16:50:54 -04:00
fname = hist.filename
del hist
if os.path.isfile(fname):
os.remove(fname)
2015-08-23 17:00:26 -04:00
@contextmanager
def a_replay(re_file):
hist = run_replay(re_file)
yield hist
cleanup_replay(hist)
2015-08-23 16:50:54 -04:00
@skip_if_on_darwin
def test_echo():
f = os.path.join(HISTDIR, 'echo.json')
with a_replay(f) as hist:
assert 2 == len(hist)
2015-08-23 16:50:54 -04:00
2015-08-23 17:00:26 -04:00
@skip_if_on_darwin
def test_reecho():
f = os.path.join(HISTDIR, 'echo.json')
with a_replay(f) as hist:
assert 2 == len(hist)
2015-08-23 16:50:54 -04:00
@skip_if_on_darwin
def test_simple_python():
f = os.path.join(HISTDIR, 'simple-python.json')
with a_replay(f) as hist:
assert 4 == len(hist)
assert "print('The Turtles')" == hist.inps[0].strip()