2015-11-16 14:04:32 -08:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-08-23 16:50:54 -04:00
|
|
|
"""Tests the xonsh replay functionality."""
|
|
|
|
import os
|
|
|
|
import builtins
|
|
|
|
|
2016-06-22 23:20:37 +03:00
|
|
|
import pytest
|
2015-08-23 16:50:54 -04:00
|
|
|
|
|
|
|
from xonsh.shell import Shell
|
2017-02-13 00:25:38 -05:00
|
|
|
from xonsh.execer import Execer
|
2015-08-23 16:50:54 -04:00
|
|
|
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
|
|
|
|
2015-08-23 16:50:54 -04:00
|
|
|
|
2018-08-30 09:18:49 -05:00
|
|
|
HISTDIR = os.path.join(os.path.dirname(__file__), "histories")
|
2015-08-23 16:50:54 -04:00
|
|
|
|
2015-08-23 17:00:26 -04:00
|
|
|
|
2018-11-19 20:22:18 -05:00
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
2016-10-16 16:44:55 +03:00
|
|
|
def ctx():
|
|
|
|
"""Create a global Shell instance to use in all the test."""
|
2018-08-30 09:18:49 -05:00
|
|
|
ctx = {"PATH": []}
|
2017-02-13 00:25:38 -05:00
|
|
|
execer = Execer(xonsh_ctx=ctx)
|
2018-09-13 14:03:35 -04:00
|
|
|
builtins.__xonsh__.shell = Shell(execer=execer, ctx=ctx, shell_type="none")
|
2016-10-16 16:44:55 +03:00
|
|
|
yield
|
2018-10-29 16:27:49 +01:00
|
|
|
builtins.__xonsh__.shell = None
|
2015-08-23 16:50:54 -04:00
|
|
|
|
|
|
|
|
2016-07-01 21:52:37 +03:00
|
|
|
@skip_if_on_darwin
|
|
|
|
def test_echo():
|
2018-08-30 09:18:49 -05:00
|
|
|
histfile = os.path.join(HISTDIR, "echo.json")
|
2016-10-16 16:44:55 +03:00
|
|
|
hist = Replayer(histfile).replay()
|
|
|
|
assert len(hist) == 2
|
2015-08-23 16:50:54 -04:00
|
|
|
|
2015-08-23 17:00:26 -04:00
|
|
|
|
2016-07-01 21:52:37 +03:00
|
|
|
@skip_if_on_darwin
|
|
|
|
def test_reecho():
|
2018-08-30 09:18:49 -05:00
|
|
|
histfile = os.path.join(HISTDIR, "echo.json")
|
2016-10-16 16:44:55 +03:00
|
|
|
hist = Replayer(histfile).replay()
|
|
|
|
assert len(hist) == 2
|
|
|
|
|
2015-08-23 16:50:54 -04:00
|
|
|
|
2016-07-01 21:52:37 +03:00
|
|
|
@skip_if_on_darwin
|
|
|
|
def test_simple_python():
|
2018-08-30 09:18:49 -05:00
|
|
|
histfile = os.path.join(HISTDIR, "simple-python.json")
|
2016-10-16 16:44:55 +03:00
|
|
|
hist = Replayer(histfile).replay()
|
|
|
|
assert len(hist) == 4
|
|
|
|
assert hist.inps[0].strip() == "print('The Turtles')"
|