aboutsummaryrefslogtreecommitdiff
path: root/src/suite
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-09-11 12:33:34 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-09-11 12:33:34 +0200
commit46ba2708f83bf46186c33bf84975d39e87f467c1 (patch)
tree8275c80bba98d63e81e3af9a1df8be62e0419003 /src/suite
parentc0b1a90cf9c52a0c9b1623ac695516031d5ccdba (diff)
downloadminishell_test-46ba2708f83bf46186c33bf84975d39e87f467c1.tar.gz
minishell_test-46ba2708f83bf46186c33bf84975d39e87f467c1.tar.bz2
minishell_test-46ba2708f83bf46186c33bf84975d39e87f467c1.zip
Refactoring files, splited test.py and suite.py in packages
Diffstat (limited to 'src/suite')
-rw-r--r--src/suite/__init__.py2
-rw-r--r--src/suite/decorator.py27
-rw-r--r--src/suite/suite.py94
3 files changed, 123 insertions, 0 deletions
diff --git a/src/suite/__init__.py b/src/suite/__init__.py
new file mode 100644
index 0000000..55beb35
--- /dev/null
+++ b/src/suite/__init__.py
@@ -0,0 +1,2 @@
+from suite.suite import Suite
+from suite.decorator import suite
diff --git a/src/suite/decorator.py b/src/suite/decorator.py
new file mode 100644
index 0000000..55c9de6
--- /dev/null
+++ b/src/suite/decorator.py
@@ -0,0 +1,27 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# decorator.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/09/11 12:28:00 by charles #+# #+# #
+# Updated: 2020/09/11 12:28:14 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+from suite import Suite
+from test import Test
+
+def suite(origin):
+ """ decorator for a suite function (fmt: suite_[name]) """
+
+ name = origin.__name__[len("suite_"):]
+ s = Suite(name)
+ def test_generator():
+ def test(*args, **kwargs):
+ s.add(Test(*args, **kwargs))
+ origin(test)
+ s.add_generator(test_generator)
+ Suite.available.append(s)
+ return test_generator
diff --git a/src/suite/suite.py b/src/suite/suite.py
new file mode 100644
index 0000000..fee4aa9
--- /dev/null
+++ b/src/suite/suite.py
@@ -0,0 +1,94 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# suite.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:29 by charles #+# #+# #
+# Updated: 2020/09/11 12:27:47 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+import config
+from test import Test
+
+
+class Suite:
+ available = []
+
+ @classmethod
+ def run_all(cls):
+ for s in cls.available:
+ s.run()
+
+ @classmethod
+ def setup(cls, asked_names: [str]):
+ if len(asked_names) == 0:
+ asked_names = [s.name for s in cls.available]
+ cls.available = [s for s in cls.available if s.name in asked_names]
+ for s in cls.available:
+ s.generate()
+
+ @classmethod
+ def available_names(cls) -> [str]:
+ return [s.name for s in cls.available]
+
+ def __init__(self, name: str):
+ self.name = name
+ self.generator_func = None
+ self.tests = []
+
+ def add(self, test):
+ self.tests.append(test)
+
+ def add_generator(self, generator):
+ self.generator_func = generator
+
+ def run(self):
+ if config.VERBOSE_LEVEL == 0:
+ print(self.name + ": ", end="")
+ else:
+ print("{} {:#<41}".format("#" * 39, self.name + " "))
+ for t in self.tests:
+ t.run()
+ if config.VERBOSE_LEVEL == 0:
+ print()
+
+ def generate(self):
+ self.generator_func()
+
+ def total(self) -> (int, int):
+ passed_total = 0
+ for t in self.tests:
+ if t.result is None:
+ return (-1, -1)
+ if t.result.passed:
+ passed_total += 1
+ return (passed_total, len(self.tests) - passed_total)
+
+ @classmethod
+ def summarize(cls):
+ pass_sum = 0
+ fail_sum = 0
+ print("\nSummary:")
+ for s in cls.available:
+ (pass_total, fail_total) = s.total()
+ if pass_total == -1:
+ continue
+ pass_sum += pass_total
+ fail_sum += fail_total
+ print("{:<15} \033[32m{:3} [PASS]\033[0m \033[31m{:3} [FAIL]\033[0m"
+ .format(s.name, pass_total, fail_total))
+ print("{:<15} \033[32m{:3} [PASS]\033[0m \033[31m{:3} [FAIL]\033[0m"
+ .format("TOTAL", pass_sum, fail_sum))
+
+ @classmethod
+ def save_log(cls):
+ with open(config.LOG_PATH, "w") as log_file:
+ for s in cls.available:
+ for t in s.tests:
+ if t.result is not None and t.result.failed:
+ t.result.colored = False
+ t.result.set_colors()
+ log_file.write(t.result.full_diff() + '\n')