mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
use os_indir to simulate indir behavior
This commit is contained in:
parent
d20d79bf38
commit
1e9d8e70d8
1 changed files with 21 additions and 10 deletions
|
@ -1,10 +1,21 @@
|
|||
from os import chdir
|
||||
from contextlib import contextmanager
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from xonsh.lib.os import indir
|
||||
from xonsh.lib.subprocess import run, check_call, check_output
|
||||
|
||||
|
||||
@contextmanager
|
||||
def osindir(d):
|
||||
"""Context manager for temporarily entering into a directory."""
|
||||
# Copyright (c) 2018, The Regro Developers
|
||||
old_d = os.getcwd()
|
||||
os.chdir(d)
|
||||
yield
|
||||
os.chdir(old_d)
|
||||
|
||||
|
||||
def test_run():
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
with indir(tmpdir):
|
||||
|
@ -18,7 +29,7 @@ def test_run():
|
|||
|
||||
def test_run_os():
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
chdir(tmpdir)
|
||||
with osindir(tmpdir):
|
||||
run(['touch', 'hello.txt'])
|
||||
assert 'hello.txt' in g`*.txt`
|
||||
out = ![readlink -f hello.txt].out.strip()
|
||||
|
|
Loading…
Add table
Reference in a new issue