xonsh/tests/test_lib/test_os.xsh

37 lines
1.1 KiB
Text
Raw Normal View History

2018-07-03 11:22:58 -04:00
import os
import tempfile
2018-07-17 11:31:09 -04:00
from xonsh.lib.os import indir, rmtree
2018-06-28 11:28:28 -04:00
2018-07-03 11:22:58 -04:00
def test_indir():
with tempfile.TemporaryDirectory() as tmpdir:
assert ![pwd].output.strip() != tmpdir
with indir(tmpdir):
assert ![pwd].output.strip() == tmpdir
assert ![pwd].output.strip() != tmpdir
2018-07-27 22:55:14 -04:00
try:
with indir(tmpdir):
raise Exception
except Exception:
assert ![pwd].output.strip() != tmpdir
2018-07-17 11:31:09 -04:00
2018-10-11 11:22:57 -04:00
2018-07-17 11:31:09 -04:00
def test_rmtree():
2018-07-17 11:57:09 -04:00
with tempfile.TemporaryDirectory() as tmpdir:
2018-07-17 11:31:09 -04:00
with indir(tmpdir):
mkdir rmtree_test
pushd rmtree_test
git init
2018-10-11 11:33:53 -04:00
git config user.email "test@example.com"
git config user.name "Code Monkey"
2018-07-17 11:31:09 -04:00
touch thing.txt
2018-10-11 11:22:57 -04:00
git add thing.txt
2018-07-17 11:31:09 -04:00
git commit -am "add thing"
popd
assert os.path.exists('rmtree_test')
assert os.path.exists('rmtree_test/thing.txt')
2018-10-11 11:22:57 -04:00
rmtree('rmtree_test', force=True)
2018-07-17 11:31:09 -04:00
assert not os.path.exists('rmtree_test')
assert not os.path.exists('rmtree_test/thing.txt')