2018-07-03 11:22:58 -04:00
|
|
|
import os
|
2018-07-06 23:36:44 -04:00
|
|
|
import tempfile
|
2018-12-06 09:19:08 -05:00
|
|
|
|
2024-06-29 11:58:11 +02:00
|
|
|
from xonsh.api.os import indir, rmtree
|
2018-06-28 11:28:28 -04:00
|
|
|
|
2018-12-06 13:52:46 -05:00
|
|
|
import pytest
|
|
|
|
|
2022-03-24 00:09:28 +05:30
|
|
|
from xonsh.pytest.tools import ON_WINDOWS
|
2018-07-03 12:48:57 -04:00
|
|
|
|
2018-12-05 20:17:38 -05:00
|
|
|
|
2018-07-03 11:22:58 -04:00
|
|
|
def test_indir():
|
2018-12-06 13:52:46 -05:00
|
|
|
if ON_WINDOWS:
|
|
|
|
pytest.skip("On Windows")
|
2018-07-06 23:36:44 -04:00
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
2021-06-21 19:36:37 +03:00
|
|
|
assert $(pwd).strip() != tmpdir
|
2018-07-06 23:36:44 -04:00
|
|
|
with indir(tmpdir):
|
2021-06-21 19:36:37 +03:00
|
|
|
assert $(pwd).strip() == tmpdir
|
|
|
|
assert $(pwd).strip() != tmpdir
|
2018-07-27 22:55:14 -04:00
|
|
|
try:
|
|
|
|
with indir(tmpdir):
|
|
|
|
raise Exception
|
|
|
|
except Exception:
|
2021-06-21 19:36:37 +03:00
|
|
|
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():
|
2020-08-10 13:24:10 +02:00
|
|
|
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
|
2019-04-19 14:34:20 +02:00
|
|
|
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')
|
|
|
|
|