mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 00:14:41 +01:00

To have clear `./xonsh` directory with the list of components we need to move common packages that are not components of xonsh to lib directory. cc #5538 I see that `lib.os` and `lib.subprocess` have a bit different intention. I think more clearer will be put them to `xonsh.api`. This is the first step to #5383. ## 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>
45 lines
1.3 KiB
Text
45 lines
1.3 KiB
Text
import os
|
|
import tempfile
|
|
|
|
from xonsh.api.os import indir, rmtree
|
|
|
|
import pytest
|
|
|
|
from xonsh.pytest.tools import ON_WINDOWS
|
|
|
|
|
|
def test_indir():
|
|
if ON_WINDOWS:
|
|
pytest.skip("On Windows")
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
assert $(pwd).strip() != tmpdir
|
|
with indir(tmpdir):
|
|
assert $(pwd).strip() == tmpdir
|
|
assert $(pwd).strip() != tmpdir
|
|
try:
|
|
with indir(tmpdir):
|
|
raise Exception
|
|
except Exception:
|
|
assert $(pwd).strip() != tmpdir
|
|
|
|
|
|
def test_rmtree():
|
|
if ON_WINDOWS:
|
|
pytest.skip("On Windows")
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
with indir(tmpdir):
|
|
mkdir rmtree_test
|
|
pushd rmtree_test
|
|
git init
|
|
git config user.email "test@example.com"
|
|
git config user.name "Code Monkey"
|
|
touch thing.txt
|
|
git add thing.txt
|
|
git commit -a --no-gpg-sign -m "add thing"
|
|
popd
|
|
assert os.path.exists('rmtree_test')
|
|
assert os.path.exists('rmtree_test/thing.txt')
|
|
rmtree('rmtree_test', force=True)
|
|
assert not os.path.exists('rmtree_test')
|
|
assert not os.path.exists('rmtree_test/thing.txt')
|
|
|