From aa79c9db6674deb205c7741e11d5520c76217b8d Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Mon, 1 Mar 2021 16:26:03 +0100 Subject: Added tests for test/captured --- README.md | 12 +++++----- docs/README.rst | 4 ++-- docs/gettingstarted.rst.inc | 2 +- minishell_test/test/captured.py | 7 ++---- tests/test/test_captured.py | 50 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 tests/test/test_captured.py diff --git a/README.md b/README.md index 7d4cb21..a9723b0 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,11 @@ ![preview](https://i.imgur.com/98xh2xY.gif) +## Documentation + +The full documentation for this project is available at +[minishell-test.readthedocs.io](https://minishell-test.readthedocs.io). + ## Getting Started ### Installation @@ -18,7 +23,7 @@ $ pip3 install --user minishell-test # if you don't have root access ### Compatibility Your executable **must** support the `-c` option which allow to pass -command as string. +command as an argument. ``` $ bash -c 'echo bonjour je suis | cat -e' @@ -61,8 +66,3 @@ If you get `command not found`, do either of those things: - Run `$ python3 -m minishell_test` instead of `$ minishell_test` - -## Documentation - -The full documentation for this project is available at -[minishell-test.readthedocs.io](https://minishell-test.readthedocs.io). diff --git a/docs/README.rst b/docs/README.rst index 6609610..54c0f31 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -16,9 +16,9 @@ minishell_test .. image:: https://i.imgur.com/98xh2xY.gif :alt: preview -.. include:: gettingstarted.rst.inc - Documentation ------------- The full documentation for this project is available at `minishell-test.readthedocs.io `_. + +.. include:: gettingstarted.rst.inc diff --git a/docs/gettingstarted.rst.inc b/docs/gettingstarted.rst.inc index f1dce9c..1293f66 100644 --- a/docs/gettingstarted.rst.inc +++ b/docs/gettingstarted.rst.inc @@ -19,7 +19,7 @@ Your executable **must** support the ``-c`` option which allow to pass command a .. code-block:: $ bash -c 'echo bonjour je suis | cat -e' - bonjour he suis$ + bonjour je suis$ $ ./minishell -c 'echo bonjour je suis | cat -e' bonjour je suis$ diff --git a/minishell_test/test/captured.py b/minishell_test/test/captured.py index c55b38e..6481dcf 100644 --- a/minishell_test/test/captured.py +++ b/minishell_test/test/captured.py @@ -6,15 +6,12 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 12:16:25 by charles #+# #+# # -# Updated: 2021/03/01 16:02:26 by cacharle ### ########.fr # +# Updated: 2021/03/01 16:15:31 by cacharle ### ########.fr # # # # ############################################################################ # -import re from typing import List, Optional -from minishell_test.config import Config - class Captured: def __init__( @@ -38,7 +35,7 @@ class Captured: def __eq__(self, other: object) -> bool: if not isinstance(other, Captured): - raise NotImplementedError + return False if self.is_timeout: return self.is_timeout == other.is_timeout return (self.output == other.output and diff --git a/tests/test/test_captured.py b/tests/test/test_captured.py new file mode 100644 index 0000000..2c085c6 --- /dev/null +++ b/tests/test/test_captured.py @@ -0,0 +1,50 @@ +# ############################################################################ # +# # +# ::: :::::::: # +# test_captured.py :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2021/03/01 15:55:11 by cacharle #+# #+# # +# Updated: 2021/03/01 16:19:23 by cacharle ### ########.fr # +# # +# ############################################################################ # + +import pytest +import copy + +from minishell_test.test.captured import Captured + + +@pytest.fixture +def captured(): + return Captured("foo", 0, ["file1", "file2"], False) + + +def test_init(captured): + assert "foo" == captured.output + assert 0 == captured.status + assert ["file1", "file2"] == captured.files_content + assert not captured.is_timeout + + +def test_eq(captured): + assert captured != 42 + assert captured != "bonjour" + assert captured == captured + c2 = copy.deepcopy(captured) + assert captured == c2 + c2.output = "bar" + assert captured != c2 + c2 = copy.deepcopy(captured) + c2.status = 42 + assert captured != c2 + c2 = copy.deepcopy(captured) + c2.files_content = ["asdfasdf"] + assert captured != c2 + assert captured != Captured.timeout() + assert Captured.timeout() == Captured.timeout() + + +def test_timeout(): + assert Captured.timeout().is_timeout -- cgit