Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions reframe/utility/sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import collections.abc
import glob as pyglob
import itertools
import os
import re
import sys

Expand Down Expand Up @@ -776,3 +777,39 @@ def iglob(pathname, recursive=False):
'''Replacement for the :func:`glob.iglob() <python:glob.iglob>`
function.'''
return pyglob.iglob(pathname, recursive=recursive)


@deferrable
def path_exists(path):
'''Replacement for the :func:`os.path.exists` function.

.. versionadded:: 3.4
'''
return os.path.exists(path)


@deferrable
def path_isdir(path):
'''Replacement for the :func:`os.path.isdir` function.

.. versionadded:: 3.4
'''
return os.path.isdir(path)


@deferrable
def path_isfile(path):
'''Replacement for the :func:`os.path.isfile` function.

.. versionadded:: 3.4
'''
return os.path.isfile(path)


@deferrable
def path_islink(path):
'''Replacement for the :func:`os.path.islink` function.

.. versionadded:: 3.4
'''
return os.path.islink(path)
39 changes: 39 additions & 0 deletions unittests/test_sanity_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,3 +817,42 @@ def test_avg():
# Check with empty container
with pytest.raises(SanityError):
sn.evaluate(sn.avg([]))


def test_path_exists(tmp_path):
valid_dir = tmp_path / 'foo'
valid_dir.touch()
invalid_dir = tmp_path / 'bar'

assert sn.evaluate(sn.path_exists(valid_dir))
assert not sn.evaluate(sn.path_exists(invalid_dir))


def test_path_isdir(tmp_path):
test_dir = tmp_path / 'bar'
test_dir.mkdir()
test_file = tmp_path / 'foo'
test_file.touch()

assert sn.evaluate(sn.path_isdir(test_dir))
assert not sn.evaluate(sn.path_isdir(test_file))


def test_path_isfile(tmp_path):
test_file = tmp_path / 'foo'
test_file.touch()
test_dir = tmp_path / 'bar'
test_dir.mkdir()

assert sn.evaluate(sn.path_isfile(test_file))
assert not sn.evaluate(sn.path_isfile(test_dir))


def test_path_islink(tmp_path):
test_file = tmp_path / 'foo'
test_file.touch()
test_link = tmp_path / 'bar'
test_link.symlink_to(test_file)

assert sn.evaluate(sn.path_islink(test_link))
assert not sn.evaluate(sn.path_islink(test_file))