mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00

* Add uname support * Changelog addition * Migration to platform module * Update uptime.py for the last version Merge the original uptime module to a single file Change the bootime() return be stay compatible with xonsh Add support for Haiku , suppose to close #3882 Add dependency from uptime to support to MacOS 10.10 by add _posix.c file. * Update uptime.py for the last version Merge the original uptime module to a single file Change the bootime() return be stay compatible with xonsh Add support for Haiku , suppose to close #3882 Add dependency from uptime to support to MacOS 10.10 by add _posix.c file. * typo fix * black reformat * remove usage of print * black is black * add original test for uptime convert original test via 2to3 black reformat tests * strange syntaxe fixe for flaske8 * black the incredible tool it stop a bug fixe just because it THE tool it want a return for make less readable code * flake8 the famous tool it permit to stop a big fixe without any information's about the trouble * workaround about xonsh CI don't respect docstring specs * RISC OS only comment thing * black is a good jock in a CI * black is a good jock in a CI * roll back uptime.py * look if we can make it work * fixe all i understand * add command in corutils alias * reformat uptime.py with black * fixe version * try with xonsh xp.LIBC lib * black in a CI is a stupid thing * stupid Windows and it \r * use os.linestep * use newline simple wrapper * use newline simple wrapper * use newline simple wrapper * use newline simple wrapper * try osx rollback method * fixe * fixe * a test on window via the CI because i haven't the OS * a test on window via the CI because i haven't the OS * a test on window via the CI because i haven't the OS * fix: black: format * refactor: update uname command now has auto-completions * docs: update news item and fix qa error * refactor: remove unused file * fix: qa imports * refactor: update getting boottime fallback to monotonic time on unix * fix: update haiku compatibility in uptime * refactor: add uptime to aliases * refactor: move xoreutils tests * fix: call aliases using xonsh Co-authored-by: Tuux <tuxa@rtnp.org> Co-authored-by: Noortheen Raja <jnoortheen@gmail.com>
87 lines
3.1 KiB
Python
87 lines
3.1 KiB
Python
import os
|
|
import tempfile
|
|
|
|
from xonsh.tools import ON_WINDOWS
|
|
from xonsh.xoreutils import _which
|
|
|
|
|
|
class TestWhich:
|
|
# Tests for the _whichgen function which is the only thing we
|
|
# use from the _which.py module.
|
|
def setup(self):
|
|
# Setup two folders with some test files.
|
|
self.testdirs = [tempfile.TemporaryDirectory(), tempfile.TemporaryDirectory()]
|
|
if ON_WINDOWS:
|
|
self.testapps = ["whichtestapp1.exe", "whichtestapp2.wta"]
|
|
self.exts = [".EXE"]
|
|
else:
|
|
self.testapps = ["whichtestapp1"]
|
|
self.exts = None
|
|
for app in self.testapps:
|
|
for d in self.testdirs:
|
|
path = os.path.join(d.name, app)
|
|
with open(path, "wb") as f:
|
|
f.write(b"")
|
|
os.chmod(path, 0o755)
|
|
|
|
def teardown_module(self):
|
|
for d in self.testdirs:
|
|
d.cleanup()
|
|
|
|
def test_whichgen(self):
|
|
testdir = self.testdirs[0].name
|
|
arg = "whichtestapp1"
|
|
matches = list(_which.whichgen(arg, path=[testdir], exts=self.exts))
|
|
assert len(matches) == 1
|
|
assert self._file_match(matches[0][0], os.path.join(testdir, arg))
|
|
|
|
def test_whichgen_failure(self):
|
|
testdir = self.testdirs[0].name
|
|
arg = "not_a_file"
|
|
matches = list(_which.whichgen(arg, path=[testdir], exts=self.exts))
|
|
assert len(matches) == 0
|
|
|
|
def test_whichgen_verbose(self):
|
|
testdir = self.testdirs[0].name
|
|
arg = "whichtestapp1"
|
|
matches = list(
|
|
_which.whichgen(arg, path=[testdir], exts=self.exts, verbose=True)
|
|
)
|
|
assert len(matches) == 1
|
|
match, from_where = matches[0]
|
|
assert self._file_match(match, os.path.join(testdir, arg))
|
|
assert from_where == "from given path element 0"
|
|
|
|
def test_whichgen_multiple(self):
|
|
testdir0 = self.testdirs[0].name
|
|
testdir1 = self.testdirs[1].name
|
|
arg = "whichtestapp1"
|
|
matches = list(_which.whichgen(arg, path=[testdir0, testdir1], exts=self.exts))
|
|
assert len(matches) == 2
|
|
assert self._file_match(matches[0][0], os.path.join(testdir0, arg))
|
|
assert self._file_match(matches[1][0], os.path.join(testdir1, arg))
|
|
|
|
if ON_WINDOWS:
|
|
|
|
def test_whichgen_ext_failure(self):
|
|
testdir = self.testdirs[0].name
|
|
arg = "whichtestapp2"
|
|
matches = list(_which.whichgen(arg, path=[testdir], exts=self.exts))
|
|
assert len(matches) == 0
|
|
|
|
def test_whichgen_ext_success(self):
|
|
testdir = self.testdirs[0].name
|
|
arg = "whichtestapp2"
|
|
matches = list(_which.whichgen(arg, path=[testdir], exts=[".wta"]))
|
|
assert len(matches) == 1
|
|
assert self._file_match(matches[0][0], os.path.join(testdir, arg))
|
|
|
|
def _file_match(self, path1, path2):
|
|
if ON_WINDOWS:
|
|
path1 = os.path.normpath(os.path.normcase(path1))
|
|
path2 = os.path.normpath(os.path.normcase(path2))
|
|
path1 = os.path.splitext(path1)[0]
|
|
path2 = os.path.splitext(path2)[0]
|
|
return path1 == path2
|
|
else:
|
|
return os.path.samefile(path1, path2)
|