xonsh/tests/api/test_os.xsh

46 lines
1.3 KiB
Text
Raw Normal View History

2018-07-03 11:22:58 -04:00
import os
import tempfile
2018-12-06 09:19:08 -05:00
from xonsh.api.os import indir, rmtree
2018-06-28 11:28:28 -04:00
import pytest
2022-03-24 00:09:28 +05:30
from xonsh.pytest.tools import ON_WINDOWS
2018-12-05 20:17:38 -05:00
2018-07-03 11:22:58 -04:00
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
2018-07-27 22:55:14 -04:00
try:
with indir(tmpdir):
raise Exception
except Exception:
assert $(pwd).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():
if ON_WINDOWS:
pytest.skip("On Windows")
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
git commit -a --no-gpg-sign -m "add thing"
2018-07-17 11:31:09 -04:00
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')