mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 00:14:41 +01:00
refactoring: fix test_main on mac (#5570)
<!--- Thanks for opening a PR on xonsh! Please do this: 1. Include a news file with your PR (https://xon.sh/devguide.html#changelog). 2. Add the documentation for your feature into `/docs`. 3. Add the example of usage or before-after behavior. 4. Mention the issue that this PR is addressing e.g. `#1234`. --> ## For community ⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍 comment** --------- Co-authored-by: a <1@1.1> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
61a77ac3ce
commit
c638fbbc71
2 changed files with 24 additions and 7 deletions
|
@ -6,6 +6,7 @@ import os
|
|||
import os.path
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -353,7 +354,9 @@ def test_force_interactive_custom_rc_with_script(shell, tmpdir, monkeypatch, xes
|
|||
monkeypatch.setitem(os.environ, "XONSH_CACHE_SCRIPTS", "False")
|
||||
f = tmpdir.join("wakkawakka")
|
||||
f.write("print('hi')")
|
||||
args = xonsh.main.premain(["-i", "--rc", f.strpath, "tests/sample.xsh"])
|
||||
args = xonsh.main.premain(
|
||||
["-i", "--rc", f.strpath, str(Path(__file__).parent / "sample.xsh")]
|
||||
)
|
||||
assert args.mode == XonshMode.interactive
|
||||
assert f.strpath in xession.rc_files
|
||||
|
||||
|
@ -364,7 +367,9 @@ def test_force_interactive_custom_rc_with_script_and_no_rc(
|
|||
monkeypatch.setitem(os.environ, "XONSH_CACHE_SCRIPTS", "False")
|
||||
f = tmpdir.join("wakkawakka")
|
||||
f.write("print('hi')")
|
||||
args = xonsh.main.premain(["-i", "--no-rc", "--rc", f.strpath, "tests/sample.xsh"])
|
||||
args = xonsh.main.premain(
|
||||
["-i", "--no-rc", "--rc", f.strpath, str(Path(__file__).parent / "sample.xsh")]
|
||||
)
|
||||
assert args.mode == XonshMode.interactive
|
||||
assert len(xession.rc_files) == 0
|
||||
|
||||
|
@ -375,7 +380,9 @@ def test_custom_rc_with_script(shell, tmpdir, xession):
|
|||
"""
|
||||
f = tmpdir.join("wakkawakka")
|
||||
f.write("print('hi')")
|
||||
args = xonsh.main.premain(["--rc", f.strpath, "tests/sample.xsh"])
|
||||
args = xonsh.main.premain(
|
||||
["--rc", f.strpath, str(Path(__file__).parent / "sample.xsh")]
|
||||
)
|
||||
assert not (args.mode == XonshMode.interactive)
|
||||
assert f.strpath in xession.rc_files
|
||||
|
||||
|
@ -386,7 +393,9 @@ def test_custom_rc_with_script_and_no_rc(shell, tmpdir, xession):
|
|||
"""
|
||||
f = tmpdir.join("wakkawakka")
|
||||
f.write("print('hi')")
|
||||
args = xonsh.main.premain(["--no-rc", "--rc", f.strpath, "tests/sample.xsh"])
|
||||
args = xonsh.main.premain(
|
||||
["--no-rc", "--rc", f.strpath, str(Path(__file__).parent / "sample.xsh")]
|
||||
)
|
||||
assert not (args.mode == XonshMode.interactive)
|
||||
assert len(xession.rc_files) == 0
|
||||
|
||||
|
|
|
@ -103,9 +103,17 @@ def _xh_bash_hist_parser(location=None, **kwargs):
|
|||
os.path.join("~", ".bash_history"),
|
||||
)
|
||||
if location:
|
||||
with open(location, errors="backslashreplace") as bash_hist:
|
||||
for ind, line in enumerate(bash_hist):
|
||||
yield {"inp": line.rstrip(), "ts": 0.0, "ind": ind}
|
||||
try:
|
||||
with open(location, errors="backslashreplace") as bash_hist:
|
||||
for ind, line in enumerate(bash_hist):
|
||||
yield {"inp": line.rstrip(), "ts": 0.0, "ind": ind}
|
||||
except PermissionError:
|
||||
print(f"Bash history permission error in {location!r}", file=sys.stderr)
|
||||
yield {
|
||||
"inp": f"# Bash history permission error in {location!r}",
|
||||
"ts": 0.0,
|
||||
"ind": 0,
|
||||
}
|
||||
else:
|
||||
print("No bash history file", file=sys.stderr)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue