Skip to content

Commit

Permalink
Fix Windows CI (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
crusaderky committed Jan 11, 2024
1 parent 2309db5 commit ff10eee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
4 changes: 2 additions & 2 deletions pshell/tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ def test_backup(str_or_path, tmpdir):
# Manual extension
new_fname = sh.backup(fname_env, suffix="bak", action="copy")
assert os.path.exists(f"{tmpdir}/test.bak")
assert str(new_fname) == "$UNITTEST_BASH/test.bak"
assert str(new_fname) == str(str_or_path("$UNITTEST_BASH/test.bak"))
assert isinstance(new_fname, str_or_path)

# Collisions in the backup name will generate a unique new name
new_fname = sh.backup(fname_env, suffix="bak", action="copy")
assert os.path.exists(f"{tmpdir}/test.bak.2")
assert str(new_fname) == "$UNITTEST_BASH/test.bak.2"
assert str(new_fname) == str(str_or_path("$UNITTEST_BASH/test.bak.2"))
assert isinstance(new_fname, str_or_path)

# action='move'
Expand Down
41 changes: 15 additions & 26 deletions pshell/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,52 +40,41 @@ def test_glob_iglob(str_or_path, tmpdir):
)

# glob exceptions
f = str_or_path("$UNITTEST_BASH/test*.txt")
with pytest.raises(sh.FileMatchError) as e:
sh.glob(str_or_path("$UNITTEST_BASH/test*.txt"), min_results=4)
assert (
str(e.value) == "File match '$UNITTEST_BASH/test*.txt' produced "
"3 results; expected at least 4"
)
sh.glob(f, min_results=4)
assert str(e.value) == f"File match '{f}' produced 3 results; expected at least 4"

with pytest.raises(sh.FileMatchError) as e:
sh.glob(str_or_path("$UNITTEST_BASH/test*.txt"), max_results=2)
assert (
str(e.value) == "File match '$UNITTEST_BASH/test*.txt' produced "
"3 results; expected up to 2"
)
sh.glob(f, max_results=2)
assert str(e.value) == f"File match '{f}' produced 3 results; expected up to 2"

with pytest.raises(sh.FileMatchError) as e:
sh.glob(str_or_path("$UNITTEST_BASH/test*.txt"), min_results=1, max_results=2)
sh.glob(f, min_results=1, max_results=2)
assert (
str(e.value) == "File match '$UNITTEST_BASH/test*.txt' produced "
"3 results; expected between 1 and 2"
str(e.value) == f"File match '{f}' produced 3 results; expected between 1 and 2"
)

with pytest.raises(sh.FileMatchError) as e:
sh.glob(str_or_path("$UNITTEST_BASH/test*.txt"), min_results=2, max_results=2)
assert (
str(e.value) == "File match '$UNITTEST_BASH/test*.txt' produced "
"3 results; expected exactly 2"
)
sh.glob(f, min_results=2, max_results=2)
assert str(e.value) == f"File match '{f}' produced 3 results; expected exactly 2"

# iglob exceptions
it = sh.iglob(str_or_path("$UNITTEST_BASH/test*.txt"), max_results=1)
it = sh.iglob(f, max_results=1)
# Make no assumption about the order
assert next(it) in results
with pytest.raises(sh.FileMatchError) as e:
next(it)
assert (
str(e.value) == "File match '$UNITTEST_BASH/test*.txt' produced at least 2 "
"results; expected up to 1"
str(e.value)
== f"File match '{f}' produced at least 2 results; expected up to 1"
)

it = sh.iglob(str_or_path("$UNITTEST_BASH/notfound"), min_results=1)
f = str_or_path("$UNITTEST_BASH/notfound.txt")
it = sh.iglob(f, min_results=1)
with pytest.raises(sh.FileMatchError) as e:
next(it)
assert (
str(e.value) == "File match '$UNITTEST_BASH/notfound' produced 0 results; "
"expected at least 1"
)
assert str(e.value) == f"File match '{f}' produced 0 results; expected at least 1"


def test_glob_iglob_recursive(tmpdir):
Expand Down

0 comments on commit ff10eee

Please sign in to comment.