aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml14
-rw-r--r--requirements.txt2
-rw-r--r--src/config.py4
-rw-r--r--src/suite/decorator.py4
-rw-r--r--src/suite/suite.py18
-rw-r--r--src/test/captured.py8
-rw-r--r--src/test/result.py9
-rw-r--r--src/test/test.py13
8 files changed, 47 insertions, 25 deletions
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..83ec84c
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,14 @@
+language: python
+python:
+ - "3.5"
+ - "3.6"
+ - "3.7"
+ - "3.8"
+ - "3.9"
+
+install:
+ - pip install -r requirements.txt
+
+script:
+ - python -m mypy src
+ - python -m flake8
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..6c214d7
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,2 @@
+flake8==3.8.3
+mypy==0.800
diff --git a/src/config.py b/src/config.py
index 03893d1..95600c6 100644
--- a/src/config.py
+++ b/src/config.py
@@ -6,7 +6,7 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/07/15 18:24:19 by charles #+# #+# #
-# Updated: 2021/01/11 22:19:59 by charles ### ########.fr #
+# Updated: 2021/01/31 01:59:00 by charles ### ########.fr #
# #
# ############################################################################ #
@@ -35,7 +35,7 @@ MINISHELL_MAKE = True
# has to support the -c option (sh, bash and zsh support it)
REFERENCE_PATH = "/bin/bash"
# can be changed with `export MINISHELL_TEST_ARGS=--poxix,--otherarg`
-REFERENCE_ARGS = [] # ["--posix"]
+REFERENCE_ARGS: list[str] = [] # ["--posix"]
# pager to use with --pager option
# can be changed with `export MINISHELL_TEST_PAGER=yourpager`
diff --git a/src/suite/decorator.py b/src/suite/decorator.py
index 45599fa..e9f9efa 100644
--- a/src/suite/decorator.py
+++ b/src/suite/decorator.py
@@ -6,7 +6,7 @@
# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/09/11 12:28:00 by charles #+# #+# #
-# Updated: 2020/10/09 10:59:09 by cacharle ### ########.fr #
+# Updated: 2021/01/31 02:13:40 by charles ### ########.fr #
# #
# ############################################################################ #
@@ -15,7 +15,7 @@ from test import Test
import inspect
-def suite(groups: [str] = [], bonus: bool = False):
+def suite(groups: list[str] = [], bonus: bool = False):
"""Decorator generator for suites arguments"""
def suite_wrapper(origin):
diff --git a/src/suite/suite.py b/src/suite/suite.py
index a3cc8c0..6acdd27 100644
--- a/src/suite/suite.py
+++ b/src/suite/suite.py
@@ -6,17 +6,19 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/07/15 18:24:29 by charles #+# #+# #
-# Updated: 2020/10/10 13:47:48 by cacharle ### ########.fr #
+# Updated: 2021/01/31 02:24:35 by charles ### ########.fr #
# #
# ############################################################################ #
import sys
+from typing import List
import config
+from test import Test
class Suite:
- available = []
+ available: list['Suite'] = []
@classmethod
def run_all(cls):
@@ -26,7 +28,7 @@ class Suite:
break
@classmethod
- def setup(cls, asked_names: [str]):
+ def setup(cls, asked_names: list[str]):
""" Remove not asked suite from available suites
Tries to autocomplete the asked names
"""
@@ -69,7 +71,7 @@ class Suite:
s.generator_func()
@classmethod
- def available_names(cls) -> [str]:
+ def available_names(cls) -> list[str]:
"""List of available suites names"""
return [s.name for s in cls.available]
@@ -92,7 +94,7 @@ class Suite:
def __init__(
self,
name: str,
- groups: [str],
+ groups: List[str],
bonus: bool = False,
description: str = "no description",
):
@@ -106,7 +108,7 @@ class Suite:
self.description = description
self.bonus = bonus
self.generator_func = None
- self.tests = []
+ self.tests: list[Test] = []
def add(self, test):
"""Append a test to the suite"""
@@ -137,7 +139,7 @@ class Suite:
print()
return True
- def total(self) -> (int, int):
+ def total(self) -> tuple[int, int]:
"""Returns the total of passed and failed tests"""
passed_total = 0
for t in self.tests:
@@ -145,7 +147,7 @@ class Suite:
return (-1, -1)
if t.result.passed:
passed_total += 1
- return (passed_total, len(self.tests) - passed_total)
+ return passed_total, len(self.tests) - passed_total
@classmethod
def summarize(cls):
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
"""