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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CommandTest(unittest.TestCase):
def test_ls_home(self):
command_result = aurornis.run(["ls", "-l", "$HOME"], environment={"HOME": "/home/deuchnord"})
# You can check quickly the command was successful:
self.assertTrue(command_result.is_successful())
self.assertTrue(command_result.successful)
# Or if you expected a more specific return value:
self.assertEqual(2, command_result.return_code) # ls returns 2 if the file does not exist

Expand Down
8 changes: 4 additions & 4 deletions aurornis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def run(
If you need to run the tests on both UNIX and Windows, it is recommended to set the `normalize_carriage_return` to True.
This way, all the "\r\n" in standard output and standard error will be converted to "\n".

If the command returns a non-zero code, the is_successful() method returns false:
If the command returns a non-zero code, the successful property is false:
>>> c = run(["python3", "-c", r"import sys; print('Oops, it didn\\'t work!', file=sys.stderr); exit(1)"], normalize_carriage_return=True)
>>> c.is_successful()
>>> c.successful
False

You can also check the execution time of your command.
Expand Down Expand Up @@ -67,15 +67,15 @@ def run(
It is a list of strings, which are joined with the end-of-line character ("\n") at execution.
Remember that the text written in standard input does not appear in the standard output.
>>> c = run(["python3", "-c", "who = input('Who are you? '); print(f'Hello {who}!')"], stdin=["World"], normalize_carriage_return=True)
>>> c.is_successful()
>>> c.successful
True
>>> c.stdout
'Who are you? Hello World!\\n'

The number of elements given in `stdin` is not verified by Aurornis, it is up to you to verify that the command
has the expected behavior.
>>> c = run(["python3", "-c", "who = input('Who are you? '); print(f'Hello {who}!')"], normalize_carriage_return=True)
>>> c.is_successful()
>>> c.successful
False
>>> c.stdout
'Who are you? '
Expand Down
21 changes: 18 additions & 3 deletions aurornis/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from deprecation import deprecated


class CommandResult:
"""An object containing the result of a command"""
Expand Down Expand Up @@ -28,6 +30,15 @@ def return_code(self) -> int:
"""The code returned by the command. Usually a number between 0 and 255 (0 meaning successful)"""
return self._return_code

@property
def successful(self) -> bool:
"""Return true if and only if the command has been successful (i.e. its return code is zero)

This property is a facilitator for ``return_code == 0``.
It does not verify the command has actually correctly done its job, you still need to write your own tests to check it did.
"""
return self.return_code == 0

@property
def stdout(self) -> str:
"""The text that has been returned by the command in the standard output"""
Expand Down Expand Up @@ -56,13 +67,17 @@ def exec_time_ms(self) -> int:
"""
return int(self._exec_time_microseconds / 1000)

@deprecated(
deprecated_in="1.5.0",
removed_in="2.0.0",
details="Use the `successful` property instead.",
)
def is_successful(self) -> bool:
"""Return true if and only if the command has been successful (i.e. its return code is zero)

This is just a facilitator for `return_code == 0`.
This does not verify the command has actually correctly done its job, you still need to write your own tests to check this.
**Deprecated:** use the ``successful`` property instead.
"""
return self.return_code == 0
return self.successful

def __repr__(self) -> str:
return (
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ classifiers = [

[tool.poetry.dependencies]
python = "^3.7"
deprecation = "^2.1.0"

[tool.poetry.dev-dependencies]
black = "^23.1.0"
Expand Down
3 changes: 3 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import doctest
import aurornis
import warnings


if __name__ == "__main__":
warnings.filterwarnings("default", category=DeprecationWarning)

(f, t) = doctest.testmod(aurornis)
failures = f
tests = t
Expand Down