diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-03-06 16:01:24 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-03-06 16:01:24 +0100 |
| commit | fc7a0425a1e19807ec2819bdb73dc6aa14d0e197 (patch) | |
| tree | 142225b152d462dcf903cb45523565671a65a0b4 /tests | |
| parent | 2a854b36624fb1c108a56d317aa54ca630864288 (diff) | |
| download | minishell_test-fc7a0425a1e19807ec2819bdb73dc6aa14d0e197.tar.gz minishell_test-fc7a0425a1e19807ec2819bdb73dc6aa14d0e197.tar.bz2 minishell_test-fc7a0425a1e19807ec2819bdb73dc6aa14d0e197.zip | |
Added test for half of Suitedev
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/conftest.py | 11 | ||||
| -rw-r--r-- | tests/suite/test_decorator.py | 0 | ||||
| -rw-r--r-- | tests/suite/test_suite.py | 121 | ||||
| -rw-r--r-- | tests/test/test_result.py | 6 | ||||
| -rw-r--r-- | tests/test/test_test.py | 10 | ||||
| -rw-r--r-- | tests/test_config.py | 5 | ||||
| -rw-r--r-- | tests/test_hooks.py | 5 | ||||
| -rw-r--r-- | tests/test_sandbox.py | 4 |
8 files changed, 136 insertions, 26 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 5e64fd1..137a024 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1 +1,10 @@ -# do not remove, used by pytest +import pytest + +from minishell_test.config import Config +from minishell_test import colors + + +@pytest.fixture(autouse=True) +def config_init(): + colors.disable() + Config.init([]) diff --git a/tests/suite/test_decorator.py b/tests/suite/test_decorator.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/suite/test_decorator.py diff --git a/tests/suite/test_suite.py b/tests/suite/test_suite.py new file mode 100644 index 0000000..925558f --- /dev/null +++ b/tests/suite/test_suite.py @@ -0,0 +1,121 @@ +# ############################################################################ # +# # +# ::: :::::::: # +# test_suite.py :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2021/03/06 11:20:47 by cacharle #+# #+# # +# Updated: 2021/03/06 16:01:03 by cacharle ### ########.fr # +# # +# ############################################################################ # + +import pytest +from pathlib import Path + +from minishell_test.suite.suite import Suite, NoMatchException, SuiteExitFirstException +from minishell_test.config import Config + + +class TestSuite: + @pytest.fixture + def available_suite_names(self, monkeypatch): + s = [ + Suite(None, 'bonjour', 'grouped', False, 'nice description'), + Suite(None, 'aurevoir', 'notgrouped', False, 'not nice description'), + Suite(None, 'ft', 'yes', False, 'no'), + Suite(None, 'ft_strlen', 'yes', False, 'no'), + Suite(None, 'charles', 'cabergs', False, 'est super'), + Suite(None, 'guillaume', 'cabergs', False, 'est super'), + Suite(None, 'bonus', 'yes', True, 'est super'), + ] + monkeypatch.setattr(Suite, '_available', s) + + def test_list(self, monkeypatch, available_suite_names): + assert """\ +grouped/bonjour ....... nice description +notgrouped/aurevoir ... not nice description +yes/ft ................ no +yes/ft_strlen ......... no +cabergs/charles ....... est super +cabergs/guillaume ..... est super +yes/bonus ............. est super +""" == Suite.list() + + def test_asked_names(self, monkeypatch, available_suite_names): + def suite_names_set(suites): + return {s._name for s in suites} + monkeypatch.setattr(Config, "bonus", False) + assert {"charles"} == suite_names_set(Suite._asked_suites(["charl"])) + assert {"guillaume"} == suite_names_set(Suite._asked_suites(["gui"])) + assert {"charles", "guillaume"} == suite_names_set(Suite._asked_suites(["cab"])) + assert {"ft", "ft_strlen"} == suite_names_set(Suite._asked_suites(["ft"])) + assert {"ft_strlen"} == suite_names_set(Suite._asked_suites(["ft_"])) + assert {"ft", "ft_strlen"} == suite_names_set(Suite._asked_suites(["yes"])) + assert {"ft", "ft_strlen", "charles", "guillaume", "bonjour", "aurevoir"} == suite_names_set(Suite._asked_suites([])) + monkeypatch.setattr(Config, "bonus", True) + assert {"ft", "ft_strlen", "bonus"} == suite_names_set(Suite._asked_suites(["yes"])) + assert {"ft", "ft_strlen", "charles", "guillaume", "bonjour", "aurevoir", "bonus"} == suite_names_set(Suite._asked_suites([])) + with pytest.raises(NoMatchException) as e: + Suite._asked_suites(["notanavailablename"]) + assert "notanavailablename" == e.value._name + assert (f"Name `notanavailablename` doesn't match any suite/group name\n\t" + "Try to run with -l to see the available suites") == e.value.__str__() + + @pytest.fixture + def runnable_suite(self): + def suite_func(test): + test("echo bonjour") + monkeypatch.setattr( + Suite, + '_available', + [Suite(suite_func, "suite_name", "suite_group", False, "suite_description")] + ) + + def test_instance_run(self, monkeypatch, capsys): + def suite_func(test): + test("echo bonjour") + test("echo foo") + test("echo bar") + s = Suite(suite_func, "suite_name", "suite_group", False, "suite_description") + monkeypatch.setattr(Config, 'minishell_exec_path', Path("/bin/bash")) + s._register() + assert len(s._tests) == 3 + assert "echo bonjour" == s._tests[0]._cmd + assert "echo foo" == s._tests[1]._cmd + assert "echo bar" == s._tests[2]._cmd + monkeypatch.setattr(Config, 'term_cols', 20) + s._run() + output = capsys.readouterr() + output_lines = output.out.splitlines() + assert len(output_lines) == 4 + assert '#### suite_name ####' == output_lines[0] + assert len(s._results) == 3 + assert all(r.passed for r in s._results) + + s = Suite(suite_func, "suite_name", "suite_group", False, "suite_description") + s._register() + monkeypatch.setattr(Config, 'range', (1, 2)) + s._run() + output = capsys.readouterr() + output_lines = output.out.splitlines() + assert len(output_lines) == 3 + assert '#### suite_name ####' == output_lines[0] + assert len(s._results) == 2 + assert all(r.passed for r in s._results) + + monkeypatch.setattr(Config, 'exit_first', True) + monkeypatch.setattr(Config, 'minishell_exec_path', Path("/usr/bin/cat")) + s = Suite(suite_func, "suite_name", "suite_group", False, "suite_description") + s._register() + with pytest.raises(SuiteExitFirstException): + s._run() + output = capsys.readouterr() + output_lines = output.out.splitlines() + assert len(output_lines) == 2 + assert '#### suite_name ####' == output_lines[0] + assert len(s._results) == 1 + assert all(r.failed for r in s._results) + + def test_summarize(self): + assert False diff --git a/tests/test/test_result.py b/tests/test/test_result.py index 2e3afdb..bf23626 100644 --- a/tests/test/test_result.py +++ b/tests/test/test_result.py @@ -6,7 +6,7 @@ # By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/03/01 16:26:34 by cacharle #+# #+# # -# Updated: 2021/03/06 10:01:04 by cacharle ### ########.fr # +# Updated: 2021/03/06 15:39:03 by cacharle ### ########.fr # # # # ############################################################################ # @@ -19,10 +19,6 @@ from minishell_test.test.result import BaseResult, Result, LeakResult, LeakResul from minishell_test.test.captured import CapturedCommand, CapturedTimeout -colors.disable() -Config.init([]) - - class TestBaseResult: @pytest.fixture def base_result(self): diff --git a/tests/test/test_test.py b/tests/test/test_test.py index 11255c0..f106cd1 100644 --- a/tests/test/test_test.py +++ b/tests/test/test_test.py @@ -6,7 +6,7 @@ # By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/03/02 18:48:57 by cacharle #+# #+# # -# Updated: 2021/03/06 10:07:07 by cacharle ### ########.fr # +# Updated: 2021/03/06 15:38:12 by cacharle ### ########.fr # # # # ############################################################################ # @@ -22,15 +22,7 @@ from minishell_test.test.captured import CapturedCommand, CapturedTimeout from minishell_test.test.test import Test, TestSetupException -colors.disable() -Config.init([]) - - class TestTest: - @pytest.fixture(autouse=True) - def reset_config(self): - Config.init([]) - def test_init_timeout(self, monkeypatch): assert Config.timeout_test == Test("")._timeout assert Config.timeout_test == Test("", timeout=0)._timeout diff --git a/tests/test_config.py b/tests/test_config.py index deb9761..304103b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -6,7 +6,7 @@ # By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/03/03 12:25:29 by cacharle #+# #+# # -# Updated: 2021/03/06 10:11:30 by cacharle ### ########.fr # +# Updated: 2021/03/06 15:38:41 by cacharle ### ########.fr # # # # ############################################################################ # @@ -27,9 +27,6 @@ from minishell_test.config import ( ) -Config.init([]) - - class TestConfigParser: @pytest.fixture def config(self): diff --git a/tests/test_hooks.py b/tests/test_hooks.py index 2df31d2..75375a4 100644 --- a/tests/test_hooks.py +++ b/tests/test_hooks.py @@ -6,7 +6,7 @@ # By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/02/27 20:03:52 by cacharle #+# #+# # -# Updated: 2021/03/06 09:56:09 by cacharle ### ########.fr # +# Updated: 2021/03/06 15:38:22 by cacharle ### ########.fr # # # # ############################################################################ # @@ -27,9 +27,6 @@ from minishell_test.hooks import ( ) -Config.init([]) - - def test_sort_lines(): assert "a\nb\nc" == sort_lines("a\nb\nc") assert "a\nb\nc" == sort_lines("c\nb\na") diff --git a/tests/test_sandbox.py b/tests/test_sandbox.py index bb2ea98..cfd67e5 100644 --- a/tests/test_sandbox.py +++ b/tests/test_sandbox.py @@ -6,7 +6,7 @@ # By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/03/03 08:09:00 by cacharle #+# #+# # -# Updated: 2021/03/06 09:58:17 by cacharle ### ########.fr # +# Updated: 2021/03/06 15:38:49 by cacharle ### ########.fr # # # # ############################################################################ # @@ -17,8 +17,6 @@ from pathlib import Path from minishell_test import sandbox from minishell_test.config import Config -Config.init([]) - @pytest.fixture def sandbox_dirs(): |
