1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
import os
import tempfile
from xonsh.lib.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')
|