Skip to content

Commit

Permalink
[v2.0.3] Release v2.0.3
Browse files Browse the repository at this point in the history
    izitest is now able to resolve a command's path so you don't have to
    give it an absolute path anymore
  • Loading branch information
Nhqml committed May 15, 2020
1 parent 5aa05e2 commit b929245
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 33 deletions.
4 changes: 2 additions & 2 deletions examples/basic-test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: 'Command option'
desc: 'Test bash ''-c'' option'
- name: 'Command option' # Name of the test
desc: 'Test bash ''-c'' option' # An optional description

# Args to APPEND before execution (which means that args
# passed through CLI WILL NOT be replaced)
Expand Down
44 changes: 20 additions & 24 deletions izitest/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,44 @@
from .betterprint import printerror

__all__ = [
"check_file",
"check_exec",
"check_dir"
"which",
"check_dir",
]


def check_file(path: Path):
"""Check if given path points to a regular file.
def which(command: str) -> str:
"""Return the absolute path to the command.
Args:
path (Path): path to check
command (str): command to resolve
Returns:
str: absolute path
Raises:
Exception: if not a regular file
Exception: if the path cannot be resolved
"""
if not path.is_file():
printerror(f"{path} is not a valid file!")
raise Exception


def check_exec(path: Path):
"""Check if given path points to a regular file.
abs_path = Path(command).absolute()
if Path(command).exists():
return str(abs_path)

Args:
path (Path): path to check
for path in os.getenv("PATH").split(os.pathsep):
abs_path = Path(path, command)
if abs_path.is_file() and os.access(abs_path, os.X_OK):
return str(abs_path)

Raises:
Exception: if not a regular file
"""
if not os.access(path, os.X_OK):
printerror(f"{path} is not executable!")
raise Exception
printerror(f"{command} is not a valid command!")
raise Exception


def check_dir(path: Path):
"""Check if given path points to a regular file.
"""Check if given path points to a directory.
Args:
path (Path): path to check
Raises:
Exception: if not a regular file
Exception: if not a directory
"""
if not path.is_dir():
printerror(f"{path} is not a valid directory!")
Expand Down
10 changes: 4 additions & 6 deletions izitest/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,13 @@ def init_testsuite() -> Testsuite:

args = parser.parse_args()

check_dir(args.testdir)

args.exec = args.exec.split(' ')
execpath: Path = Path(args.exec[0])
check_file(execpath) and check_exec(execpath)
args.exec[0] = which(args.exec[0])

if args.ref is not None:
args.ref = args.ref.split(' ')
refpath: Path = Path(args.ref[0])
check_file(refpath) and check_exec(refpath)

check_dir(args.testdir)
args.ref[0] = which(args.ref[0])

return Testsuite(args.exec, args.testdir, args.ref, args.quiet, args.memcheck, args.cat, args.report)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name="izitest",
version="2.0.2",
version="2.0.3",
author="Kenji 'Nhqml' Gaillac",
author_email="kenji.gaillac@epita.fr",
license="GNU GPLv3",
Expand Down

0 comments on commit b929245

Please sign in to comment.