aboutsummaryrefslogtreecommitdiff
path: root/minishell_test/suite
diff options
context:
space:
mode:
Diffstat (limited to 'minishell_test/suite')
-rw-r--r--minishell_test/suite/__init__.py4
-rw-r--r--minishell_test/suite/decorator.py8
-rw-r--r--minishell_test/suite/suite.py53
3 files changed, 42 insertions, 23 deletions
diff --git a/minishell_test/suite/__init__.py b/minishell_test/suite/__init__.py
index 6f7f321..e7677b6 100644
--- a/minishell_test/suite/__init__.py
+++ b/minishell_test/suite/__init__.py
@@ -1,2 +1,2 @@
-from suite.suite import Suite # noqa: F401
-from suite.decorator import suite # noqa: F401
+from minishell_test.suite.suite import Suite # noqa: F401
+# from minishell_test.suite.decorator import suite # noqa: F401
diff --git a/minishell_test/suite/decorator.py b/minishell_test/suite/decorator.py
index fdc7fb6..45f96b6 100644
--- a/minishell_test/suite/decorator.py
+++ b/minishell_test/suite/decorator.py
@@ -6,15 +6,15 @@
# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/09/11 12:28:00 by charles #+# #+# #
-# Updated: 2021/02/04 16:18:11 by charles ### ########.fr #
+# Updated: 2021/02/05 17:44:25 by charles ### ########.fr #
# #
# ############################################################################ #
import inspect
from typing import List
-from suite import Suite
-from test import Test
+from minishell_test.suite import Suite
+from minishell_test.test import Test
def suite(groups: List[str] = [], bonus: bool = False): # type: ignore
@@ -26,7 +26,7 @@ def suite(groups: List[str] = [], bonus: bool = False): # type: ignore
mod = inspect.getmodule(origin)
if mod is None:
raise NotImplementedError
- mod_name = mod.__name__[len("suites."):]
+ mod_name = mod.__name__[len("minishell_test.suites."):]
name = "{}/{}".format(mod_name, origin.__name__[len("suite_"):])
description = origin.__doc__
if description is None:
diff --git a/minishell_test/suite/suite.py b/minishell_test/suite/suite.py
index 836cac0..8c57633 100644
--- a/minishell_test/suite/suite.py
+++ b/minishell_test/suite/suite.py
@@ -6,15 +6,40 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/07/15 18:24:29 by charles #+# #+# #
-# Updated: 2021/02/04 16:13:08 by charles ### ########.fr #
+# Updated: 2021/02/05 18:15:26 by charles ### ########.fr #
# #
# ############################################################################ #
-import sys
from typing import List, Tuple, Optional, Callable
-import config
-from test import Test
+import minishell_test.config as config
+from minishell_test.test import Test
+
+
+class SuiteException(Exception):
+ """ Base exception for suite """
+ pass
+
+
+class AmbiguousNameException(SuiteException):
+ def __init__(self, name: str, matches: List[str]):
+ self.name = name
+ self.matches = matches
+
+ def __str__(self) -> str:
+ return (("Ambiguous name `{}` match the following suites\n\t{}\n"
+ "Try to run with -l to see the available suites")
+ .format(self.name, ', '.join(self.matches)))
+
+
+class NoMatchException(SuiteException):
+ def __init__(self, name: str):
+ self.name = name
+
+ def __str__(self) -> str:
+ return (("Name `{}` doesn't match any suite/group name\n\t"
+ "Try to run with -l to see the available suites")
+ .format(self.name))
class Suite:
@@ -44,27 +69,21 @@ class Suite:
names.append(name)
continue
matches = [n for n in suite_names
- if n.find("/") != -1
- and n[n.find("/") + 1:].startswith(name)
- or n.startswith(name)]
+ if n.find("/") != -1 and
+ n[n.find("/") + 1:].startswith(name) or
+ n.startswith(name)]
if len(matches) == 1:
names.append(matches[0])
elif len(matches) != 0 and all(n.startswith(name) for n in matches):
names.extend(matches)
elif len(matches) > 2:
- print(("Ambiguous name `{}` match the following suites\n\t{}\n"
- "Try to run with -l to see the available suites")
- .format(name, ', '.join(matches)))
- sys.exit(1)
+ raise AmbiguousNameException(name, matches)
elif len(matches) == 0:
- print(("Name `{}` doesn't match any suite/group name\n\t"
- "Try to run with -l to see the available suites")
- .format(name))
- sys.exit(1)
+ raise NoMatchException(name)
cls.available = list(set(
- [s for s in cls.available if s.name in names]
- + [s for s in cls.available if any(g for g in s.groups if g in names)]
+ [s for s in cls.available if s.name in names] +
+ [s for s in cls.available if any(g for g in s.groups if g in names)]
))
cls.available.sort(key=lambda s: s.name)
for s in cls.available: