Commit Graph

15 Commits

Author SHA1 Message Date
Dan Čermák
48817a6441
Refactor Command class
Command.run() currently has a bit of a confusing behavior: if raise_on_error is
False and the executable is not found, then a weird CommandT is returned (return
code is -1 and stdout+stderr is None). This makes it possible to hanlde command
not found errors separately, but it makes that needlessly verbose. So instead,
let's just return None in *this* special case.

That in turn uncovered, that in most cases when we set `raise_on_error=True`, we
actually want an error if the command is not present but no error if the command
fails to execute (e.g. because it returns -1 if you run `$cmd --version`). Hence we
introduce the flag `raise_on_command_not_found`, which causes an exception to
be raised if the command is not found. This makes it independent of the
`raise_on_error` flag.

Additionally, we add a small optimization: if command starts with /, then we
assume it's a full path and we omit the call to which (and just check whether it
exists).

Co-authored-by: Marcus Schäfer <marcus.schaefer@gmail.com>
2024-02-19 16:33:24 +01:00
Alexandre Detiste
fb69627ad3
Use unittest.mock from core python everywhere
mock was an independent module that has been merged into the Python standard library.
2024-02-18 22:15:30 +01:00
David Cassany
82f6053e83
Do not return default stdout if it is no raising on failure
This commit prevents the use of a default stdout and stderr in case
return code reports errors and it is not raising an exception.

If we are not raising an exception there is no specific need to
artificially append some stdout and stderr default message, we just
behave as if there was no error.
2021-05-20 16:29:52 +02:00
Marcus Schäfer
e200abc278
Better error reporting if jing is missing
On validation error we use jing to report detailed error
messages. However if jing is not present no validation
errors are displayed. There is a error_log variable as
part of the relaxNG object which holds the library error
log. This information is not as good as the jing report
but better than nothing
2020-11-17 16:26:55 +01:00
Marcus Schäfer
f8bc05fd42
Refactor use of raises in unit tests
Use raises as context manager instead of a method decorator.
This clearly identifies which code part is expected to raise
an exception. Related to Issue #1128
2019-09-29 19:42:43 +02:00
Dan Čermák
b015b91679
Stop inheriting from object
This is no longer required in Python3
2019-08-22 15:43:27 +02:00
Marcus Schäfer
6cc0b2085d Flake cleanup for unit tests 2017-03-07 13:03:10 +01:00
Marcus Schäfer
f1e7984a82
Fixup Command.run if called with raise_on_error set to False 2016-08-10 21:25:04 +02:00
David Cassany
0c4256e719 Updated Command to use Path.which
Command.run and Command.call now make use of Path.which in order
to test if the command is available or not. Also Path.which has
been extended in order to support custom environments and to be
able to test file permissions (read. write, execute)
2016-08-10 16:38:33 +02:00
David Cassany
0fdd209e73 Command validation
This commit includes a validation in Command.run and Command.call
in order to verify the existance of the command before running it.
It case it is not found in the specified environment it raises a
KiwiCommandNotFound Exception.
2016-08-05 18:38:27 +02:00
Marcus Schäfer
e6cc5bfa09 Move from nose to pytest
nose is no longer maintained, thus we have to move to another
testing system. This commit updates the tox setup and all tests
to use pytest instead of nose.
2016-03-14 12:23:14 +01:00
Marcus Schäfer
f173d5a7c9 Better error response in debug output
If a Command.run fails with an error code != 0 but not data was
produced on the stderr channel, we provide this as information
to the caller
2016-02-19 11:05:04 +01:00
Marcus Schäfer
40e6308aa9 Port application from python 2.7 to 3.4
For new applications like this kiwi version and its use cases
it is better to base it on a more recent python version
2016-02-17 22:38:38 +01:00
Marcus Schäfer
5322eb9d79
landscape: fix dangerous defaults 2015-12-05 21:15:43 +01:00
Marcus Schäfer
09daca60c0
KIWI - appliance builder next generation
a rewrite of the current kiwi from https://github.com/openSUSE/kiwi
2015-12-05 16:17:10 +01:00