aboutsummaryrefslogtreecommitdiff
path: root/minishell_test/suite/suite.py
diff options
context:
space:
mode:
Diffstat (limited to 'minishell_test/suite/suite.py')
-rw-r--r--minishell_test/suite/suite.py53
1 files changed, 36 insertions, 17 deletions
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: