aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-01-31 02:38:49 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-01-31 02:38:49 +0100
commit4a4f6b5b01bd6d23c141d51dd9399c36d12d29d9 (patch)
tree6cc08bd49decda6f91c8464b95cafc4945214b50 /src/test
parent19c93b393853d5ba052904914356147e27813ad0 (diff)
downloadminishell_test-4a4f6b5b01bd6d23c141d51dd9399c36d12d29d9.tar.gz
minishell_test-4a4f6b5b01bd6d23c141d51dd9399c36d12d29d9.tar.bz2
minishell_test-4a4f6b5b01bd6d23c141d51dd9399c36d12d29d9.zip
Fixing some type error, Added travis ci
Diffstat (limited to 'src/test')
-rw-r--r--src/test/captured.py8
-rw-r--r--src/test/result.py9
-rw-r--r--src/test/test.py13
3 files changed, 17 insertions, 13 deletions
diff --git a/src/test/captured.py b/src/test/captured.py
index 4401ddb..9488149 100644
--- a/src/test/captured.py
+++ b/src/test/captured.py
@@ -6,7 +6,7 @@
# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/09/11 12:16:25 by charles #+# #+# #
-# Updated: 2021/01/11 22:20:29 by charles ### ########.fr #
+# Updated: 2021/01/31 02:01:30 by charles ### ########.fr #
# #
# ############################################################################ #
@@ -14,7 +14,7 @@ import config
class Captured:
- def __init__(self, output: str, status: int, files_content: [str], is_timeout: bool = False):
+ def __init__(self, output: str, status: int, files_content: list[str], is_timeout: bool = False):
"""Captured class
output: captured content
status: command status
@@ -34,7 +34,9 @@ class Captured:
self.files_content = files_content
self.is_timeout = is_timeout
- def __eq__(self, other: 'Captured') -> bool:
+ def __eq__(self, other: object) -> bool:
+ if not isinstance(other, Captured):
+ raise NotImplementedError
if self.is_timeout:
return self.is_timeout == other.is_timeout
return (self.output == other.output
diff --git a/src/test/result.py b/src/test/result.py
index 2ae5e15..3cc268d 100644
--- a/src/test/result.py
+++ b/src/test/result.py
@@ -6,12 +6,13 @@
# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/09/11 12:17:34 by charles #+# #+# #
-# Updated: 2021/01/10 15:25:45 by cacharle ### ########.fr #
+# Updated: 2021/01/31 02:28:58 by charles ### ########.fr #
# #
# ############################################################################ #
import sys
import re
+from typing import Match
import config
from test.captured import Captured
@@ -27,7 +28,7 @@ class Result:
def __init__(
self,
cmd: str,
- file_names: [str],
+ file_names: list[str],
expected: Captured,
actual: Captured,
leak_output: str = None
@@ -49,9 +50,9 @@ class Result:
@staticmethod
def leak(cmd: str, captured: Captured):
- return Result(cmd, None, None, captured, captured.output)
+ return Result(cmd, [], None, captured, captured.output)
- def _search_leak_kind(self, kind: str) -> int:
+ def _search_leak_kind(self, kind: str) -> Match:
match = re.search(
r"==\d+==\s+" + kind + r" lost: (?P<bytes>[0-9,]+) bytes in [0-9,]+ blocks",
self.leak_output
diff --git a/src/test/test.py b/src/test/test.py
index 51389ca..527b435 100644
--- a/src/test/test.py
+++ b/src/test/test.py
@@ -6,13 +6,14 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/06/16 21:48:50 by charles #+# #+# #
-# Updated: 2021/01/10 15:20:38 by cacharle ### ########.fr #
+# Updated: 2021/01/31 02:21:17 by charles ### ########.fr #
# #
# ############################################################################ #
import os
import sys
import subprocess
+from typing import Optional
import config
from test.captured import Captured
@@ -24,8 +25,8 @@ class Test:
def __init__(self,
cmd: str,
setup: str = "",
- files: [str] = [],
- exports: {str: str} = {},
+ files: list[str] = [],
+ exports: dict[str, str] = {},
timeout: float = config.TIMEOUT,
signal=None,
hook=[],
@@ -44,7 +45,7 @@ class Test:
self.setup = setup
self.files = files
self.exports = exports
- self.result = None
+ self.result: Optional[Result] = None
self.timeout = timeout
self.signal = signal
self.hook = hook
@@ -72,7 +73,7 @@ class Test:
self.result = Result(self.full_cmd, self.files, expected, actual)
self.result.put(index)
- def _run_sandboxed(self, shell_cmd: [str]) -> Captured:
+ def _run_sandboxed(self, shell_cmd: list[str]) -> Captured:
""" Run the command in a sandbox environment """
with sandbox.context():
if self.setup != "":
@@ -94,7 +95,7 @@ class Test:
sys.exit(1)
return self._run_capture(shell_cmd)
- def _run_capture(self, shell_cmd: [str]) -> Captured:
+ def _run_capture(self, shell_cmd: list[str]) -> Captured:
""" Capture the output (stdout and stderr)
Capture the content of the watched files after the command is run
"""