mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
tests: Run tests with the amalgamated xonsh (#4290)
* tests: Run tests with the amalgamated xonsh * tests: Test xonsh loads correctly interactively * tests: Ensure tests run from amalgamated xonsh * environ: Separate $XONSH_DEBUG and $XONSH_NO_AMALGAMATE * tests: Keep XONSH_NO_AMALGAMATE in a comment for ease of debugging * tests: Fix monkeypatch for amalgamated code
This commit is contained in:
parent
948129b7a0
commit
7f8aeefae8
16 changed files with 83 additions and 25 deletions
23
news/run-tests-amalgamated.rst
Normal file
23
news/run-tests-amalgamated.rst
Normal file
|
@ -0,0 +1,23 @@
|
|||
**Added:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Changed:**
|
||||
|
||||
* Separated between ``XONSH_DEBUG`` and ``XONSH_NO_AMALGAMATE``. Setting ``XONSH_DEBUG=1`` now acts like ``XONSH_DEBUG=2`` before (basic information like input transformation, command replacement) and ``XONSH_DEBUG=2`` like ``XONSH_DEBUG=1`` before (more debugging information presented, like PLY parsing messages).
|
||||
|
||||
**Deprecated:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Removed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Security:**
|
||||
|
||||
* <news item>
|
|
@ -11,3 +11,6 @@ coverage>=5.3.1
|
|||
black==21.5b0
|
||||
pre-commit
|
||||
mypy==0.812
|
||||
|
||||
# ensure tests run with the amalgamated (==production) xonsh
|
||||
amalgamate
|
||||
|
|
|
@ -4,8 +4,8 @@ import subprocess
|
|||
from typing import List
|
||||
|
||||
|
||||
$XONSH_DEBUG = 1
|
||||
$RAISE_SUBPROC_ERROR = True
|
||||
# $XONSH_NO_AMALGAMATE = 1
|
||||
# $XONSH_TRACE_SUBPROC = True
|
||||
|
||||
|
||||
|
@ -26,6 +26,10 @@ def test(ns: argparse.Namespace):
|
|||
|
||||
args = ns.pytest_args
|
||||
|
||||
if not $(xonsh -c "import xonsh.main; print(xonsh.main.__file__, end='')").endswith("__amalgam__.py"):
|
||||
echo "Tests need to run from the amalgamated xonsh! install with `pip install .` (without `-e`)"
|
||||
exit(1)
|
||||
|
||||
if ns.report_coverage:
|
||||
![pytest @(_replace_args(args, 0)) --cov --cov-report=xml --cov-report=term]
|
||||
else:
|
||||
|
|
2
setup.py
2
setup.py
|
@ -49,7 +49,7 @@ def amalgamate_source():
|
|||
amalgamate.main(
|
||||
[
|
||||
"amalgamate",
|
||||
"--debug=XONSH_DEBUG",
|
||||
"--debug=XONSH_NO_AMALGAMATE",
|
||||
"xonsh",
|
||||
"xonsh.completers",
|
||||
"xonsh.history",
|
||||
|
|
|
@ -3,7 +3,7 @@ from xonsh.parsers.completion_context import (
|
|||
CommandContext,
|
||||
CompletionContext,
|
||||
)
|
||||
from xonsh.completers.xompletions import complete_xonfig, complete_xontrib
|
||||
from xonsh.completers.xompletions import complete_xonfig, complete_xontrib, xt
|
||||
|
||||
|
||||
def test_xonfig():
|
||||
|
@ -15,9 +15,7 @@ def test_xonfig():
|
|||
|
||||
|
||||
def test_xonfig_colors(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"xonsh.tools.color_style_names", lambda: ["blue", "brown", "other"]
|
||||
)
|
||||
monkeypatch.setattr(xt, "color_style_names", lambda: ["blue", "brown", "other"])
|
||||
assert (
|
||||
complete_xonfig(
|
||||
CompletionContext(
|
||||
|
|
|
@ -8,6 +8,7 @@ import subprocess as sp
|
|||
|
||||
import pytest
|
||||
|
||||
import xonsh
|
||||
from xonsh.lib.os import indir
|
||||
|
||||
from tools import (
|
||||
|
@ -39,7 +40,12 @@ skip_if_no_sleep = pytest.mark.skipif(
|
|||
|
||||
|
||||
def run_xonsh(
|
||||
cmd, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.STDOUT, single_command=False
|
||||
cmd,
|
||||
stdin=sp.PIPE,
|
||||
stdout=sp.PIPE,
|
||||
stderr=sp.STDOUT,
|
||||
single_command=False,
|
||||
interactive=False,
|
||||
):
|
||||
env = dict(os.environ)
|
||||
env["PATH"] = PATH
|
||||
|
@ -48,11 +54,13 @@ def run_xonsh(
|
|||
env["RAISE_SUBPROC_ERROR"] = "0"
|
||||
env["PROMPT"] = ""
|
||||
xonsh = shutil.which("xonsh", path=PATH)
|
||||
args = [xonsh, "--no-rc"]
|
||||
if interactive:
|
||||
args.append("-i")
|
||||
if single_command:
|
||||
args = [xonsh, "--no-rc", "-c", cmd]
|
||||
args += ["-c", cmd]
|
||||
input = None
|
||||
else:
|
||||
args = [xonsh, "--no-rc"]
|
||||
input = cmd
|
||||
|
||||
proc = sp.Popen(
|
||||
|
@ -753,3 +761,22 @@ def test_single_command_return_code(cmd, exp_rtn):
|
|||
@skip_if_on_darwin
|
||||
def test_argv0():
|
||||
check_run_xonsh("checkargv0.xsh", None, "OK\n")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("interactive", [True, False])
|
||||
def test_loading_correctly(monkeypatch, interactive):
|
||||
# Ensure everything loads correctly in interactive mode (e.g. #4289)
|
||||
monkeypatch.setenv("SHELL_TYPE", "prompt_toolkit")
|
||||
monkeypatch.setenv("XONSH_LOGIN", "1")
|
||||
monkeypatch.setenv("XONSH_INTERACTIVE", "1")
|
||||
out, err, ret = run_xonsh(
|
||||
"import xonsh; echo -n AAA @(xonsh.__file__) BBB",
|
||||
interactive=interactive,
|
||||
single_command=True,
|
||||
)
|
||||
assert not err
|
||||
assert ret == 0
|
||||
our_xonsh = (
|
||||
xonsh.__file__
|
||||
) # make sure xonsh didn't fail and fallback to the system shell
|
||||
assert f"AAA {our_xonsh} BBB" in out # ignore tty warnings/prompt text
|
||||
|
|
|
@ -6,7 +6,7 @@ __version__ = "0.9.27"
|
|||
# amalgamate exclude jupyter_shell proc built_ins
|
||||
import os as _os
|
||||
|
||||
if _os.getenv("XONSH_DEBUG", ""):
|
||||
if _os.getenv("XONSH_NO_AMALGAMATE", ""):
|
||||
pass
|
||||
else:
|
||||
import sys as _sys
|
||||
|
|
|
@ -437,7 +437,7 @@ class CtxAwareTransformer(NodeTransformer):
|
|||
spline,
|
||||
mode=self.mode,
|
||||
filename=self.filename,
|
||||
debug_level=(self.debug_level > 2),
|
||||
debug_level=(self.debug_level >= 2),
|
||||
)
|
||||
newnode = newnode.body
|
||||
if not isinstance(newnode, AST):
|
||||
|
@ -445,7 +445,7 @@ class CtxAwareTransformer(NodeTransformer):
|
|||
newnode = newnode[0]
|
||||
increment_lineno(newnode, n=node.lineno - 1)
|
||||
newnode.col_offset = node.col_offset
|
||||
if self.debug_level > 1:
|
||||
if self.debug_level >= 1:
|
||||
msg = "{0}:{1}:{2}{3} - {4}\n" "{0}:{1}:{2}{3} + {5}"
|
||||
mstr = "" if maxcol is None else ":" + str(maxcol)
|
||||
msg = msg.format(self.filename, node.lineno, mincol, mstr, line, spline)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# amalgamate exclude
|
||||
import os as _os
|
||||
|
||||
if _os.getenv("XONSH_DEBUG", ""):
|
||||
if _os.getenv("XONSH_NO_AMALGAMATE", ""):
|
||||
pass
|
||||
else:
|
||||
import sys as _sys
|
||||
|
|
|
@ -998,13 +998,16 @@ class GeneralSetting(Xettings):
|
|||
bool_or_int_to_str,
|
||||
0,
|
||||
"Sets the xonsh debugging level. This may be an integer or a boolean. "
|
||||
"Setting this variable prior to stating xonsh to ``1`` or ``True`` "
|
||||
"will suppress amalgamated imports. Setting it to ``2`` will get some "
|
||||
"basic information like input transformation, command replacement. "
|
||||
"With ``3`` or a higher number will make more debugging information "
|
||||
"Setting it to ``1`` will get some basic information like input transformation, command replacement. "
|
||||
"With ``2`` or a higher number will make more debugging information "
|
||||
"presented, like PLY parsing messages.",
|
||||
is_configurable=False,
|
||||
)
|
||||
XONSH_NO_AMALGAMATE = Var.with_default(
|
||||
False,
|
||||
"Setting this variable prior to starting xonsh to a truthy value will suppress amalgamated imports.",
|
||||
is_configurable=False,
|
||||
)
|
||||
XONSH_DATA_DIR = Var.with_default(
|
||||
xonsh_data_dir,
|
||||
"This is the location where xonsh data files are stored, such as " "history.",
|
||||
|
|
|
@ -75,7 +75,7 @@ class Execer(object):
|
|||
filename = self.filename
|
||||
if not transform:
|
||||
return self.parser.parse(
|
||||
input, filename=filename, mode=mode, debug_level=(self.debug_level > 2)
|
||||
input, filename=filename, mode=mode, debug_level=(self.debug_level >= 2)
|
||||
)
|
||||
|
||||
# Parsing actually happens in a couple of phases. The first is a
|
||||
|
@ -196,7 +196,7 @@ class Execer(object):
|
|||
self, line, sbpline, last_error_line, last_error_col, maxcol=None
|
||||
):
|
||||
"""print some debugging info if asked for."""
|
||||
if self.debug_level > 1:
|
||||
if self.debug_level >= 1:
|
||||
msg = "{0}:{1}:{2}{3} - {4}\n" "{0}:{1}:{2}{3} + {5}"
|
||||
mstr = "" if maxcol is None else ":" + str(maxcol)
|
||||
msg = msg.format(
|
||||
|
@ -220,7 +220,7 @@ class Execer(object):
|
|||
input,
|
||||
filename=filename,
|
||||
mode=mode,
|
||||
debug_level=(self.debug_level > 2),
|
||||
debug_level=(self.debug_level >= 2),
|
||||
)
|
||||
parsed = True
|
||||
except IndentationError as e:
|
||||
|
|
|
@ -707,7 +707,7 @@ def load_foreign_aliases(shells):
|
|||
shaliases = {} if shaliases is None else shaliases
|
||||
for alias in set(shaliases) & set(xonsh_aliases):
|
||||
del shaliases[alias]
|
||||
if XSH.env.get("XONSH_DEBUG") > 1:
|
||||
if XSH.env.get("XONSH_DEBUG") >= 1:
|
||||
print(
|
||||
"aliases: ignoring alias {!r} of shell {!r} "
|
||||
"which tries to override xonsh alias."
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# amalgamate exclude
|
||||
import os as _os
|
||||
|
||||
if _os.getenv("XONSH_DEBUG", ""):
|
||||
if _os.getenv("XONSH_NO_AMALGAMATE", ""):
|
||||
pass
|
||||
else:
|
||||
import sys as _sys
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# amalgamate exclude
|
||||
import os as _os
|
||||
|
||||
if _os.getenv("XONSH_DEBUG", ""):
|
||||
if _os.getenv("XONSH_NO_AMALGAMATE", ""):
|
||||
pass
|
||||
else:
|
||||
import sys as _sys
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# amalgamate exclude
|
||||
import os as _os
|
||||
|
||||
if _os.getenv("XONSH_DEBUG", ""):
|
||||
if _os.getenv("XONSH_NO_AMALGAMATE", ""):
|
||||
pass
|
||||
else:
|
||||
import sys as _sys
|
||||
|
|
|
@ -106,7 +106,7 @@ def transform_command(src, show_diff=True):
|
|||
"converge."
|
||||
)
|
||||
debug_level = XSH.env.get("XONSH_DEBUG")
|
||||
if show_diff and debug_level > 1 and src != raw:
|
||||
if show_diff and debug_level >= 1 and src != raw:
|
||||
sys.stderr.writelines(
|
||||
difflib.unified_diff(
|
||||
raw.splitlines(keepends=True),
|
||||
|
|
Loading…
Add table
Reference in a new issue