surimi 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- surimi/__init__.py +3 -0
- surimi/cli.py +20 -0
- surimi/data.py +13 -0
- surimi/decorators/__init__.py +3 -0
- surimi/decorators/test.py +47 -0
- surimi/formater.py +39 -0
- surimi/registration.py +32 -0
- surimi/runner.py +70 -0
- surimi-0.0.0.dist-info/METADATA +14 -0
- surimi-0.0.0.dist-info/RECORD +14 -0
- surimi-0.0.0.dist-info/WHEEL +5 -0
- surimi-0.0.0.dist-info/entry_points.txt +2 -0
- surimi-0.0.0.dist-info/licenses/LICENSE +7 -0
- surimi-0.0.0.dist-info/top_level.txt +1 -0
surimi/__init__.py
ADDED
surimi/cli.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import click
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
from .registration import discover_tests
|
|
5
|
+
from .runner import run_tests
|
|
6
|
+
|
|
7
|
+
@click.command()
|
|
8
|
+
@click.option('-v', '--verbose', default=0, nargs=1, type=int)
|
|
9
|
+
@click.argument('directory', default='.', nargs=1, type=str)
|
|
10
|
+
def test(verbose, directory):
|
|
11
|
+
root = os.path.abspath(directory)
|
|
12
|
+
sys.path.insert(0, root)
|
|
13
|
+
import surimi
|
|
14
|
+
tests = surimi.Test()
|
|
15
|
+
surimi.test = tests
|
|
16
|
+
discover_tests(directory)
|
|
17
|
+
run_tests(tests, verbose=verbose)
|
|
18
|
+
|
|
19
|
+
if __name__ == '__main__':
|
|
20
|
+
test()
|
surimi/data.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from rich.console import Console
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import Any, Callable
|
|
4
|
+
|
|
5
|
+
@dataclass
|
|
6
|
+
class TestInfos:
|
|
7
|
+
function: Callable[[], None]
|
|
8
|
+
name: str
|
|
9
|
+
location: str
|
|
10
|
+
fail_with: Exception
|
|
11
|
+
|
|
12
|
+
def __call__(self):
|
|
13
|
+
self.function()
|
|
14
|
+
|
|
15
|
+
class Test:
|
|
16
|
+
def __init__(self):
|
|
17
|
+
self.registered_tests: list[TestInfos] = {}
|
|
18
|
+
|
|
19
|
+
def add_function(self, fun, **kwargs):
|
|
20
|
+
fail_with = kwargs.get('fail_with')
|
|
21
|
+
test = TestInfos(fun, fun.__name__, fun.__globals__['__file__'], fail_with)
|
|
22
|
+
module_name = fun.__globals__['__name__']
|
|
23
|
+
if module_name not in self.registered_tests:
|
|
24
|
+
self.registered_tests[module_name] = []
|
|
25
|
+
self.registered_tests[module_name].append(test)
|
|
26
|
+
|
|
27
|
+
def __call__(self, *args, **kwargs):
|
|
28
|
+
#@test
|
|
29
|
+
if args and callable(args[0]):
|
|
30
|
+
self.add_function(args[0], **kwargs)
|
|
31
|
+
return args[0]
|
|
32
|
+
|
|
33
|
+
#@test(...)
|
|
34
|
+
def register(function):
|
|
35
|
+
self.add_function(function, **kwargs)
|
|
36
|
+
return function
|
|
37
|
+
|
|
38
|
+
return register
|
|
39
|
+
|
|
40
|
+
def proxy_test_decorator(*args, **kwargs):
|
|
41
|
+
if args and callable(args[0]):
|
|
42
|
+
function = args[0]
|
|
43
|
+
return function
|
|
44
|
+
|
|
45
|
+
def register(function):
|
|
46
|
+
return function
|
|
47
|
+
return register
|
surimi/formater.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import traceback
|
|
2
|
+
from rich.console import Console
|
|
3
|
+
from rich.panel import Panel
|
|
4
|
+
from rich.syntax import Syntax
|
|
5
|
+
from rich.text import Text
|
|
6
|
+
from .data import TestResult
|
|
7
|
+
|
|
8
|
+
def format_module_result(console: Console, num_module: int, total_modules: int, module: str, failed: bool, execution_time: float):
|
|
9
|
+
if not failed : status = Text("[bold][green]PASSED[/green][/bold]")
|
|
10
|
+
else: status = Text("[bold][red]FAILED[/red][/bold]")
|
|
11
|
+
time_str = f"{execution_time:.2f}s"
|
|
12
|
+
module = module.replace('.', '/')
|
|
13
|
+
console.print(f"{num_module}/{total_modules} {module:<35} {status} {time_str:>8}")
|
|
14
|
+
|
|
15
|
+
def format_failed(console: Console, test_result: TestResult, verbose: int):
|
|
16
|
+
error_name = type(test_result.exception).__name__
|
|
17
|
+
error = f'[red]{error_name}[/red]' if test_result.exception else "[green]No error[/green]"
|
|
18
|
+
expected = f', expected [red]{test_result.fail_with.__name__}[/red]' if test_result.fail_with else ''
|
|
19
|
+
|
|
20
|
+
console.print(f" -> [red]Test [bold]{test_result.name}[/bold] failed[/red]: got {error}{expected}")
|
|
21
|
+
|
|
22
|
+
if verbose >= 1:
|
|
23
|
+
if test_result.stdout:
|
|
24
|
+
console.print(f" [yellow]stdout:[/yellow]")
|
|
25
|
+
for line in test_result.stdout.strip().split('\n'):
|
|
26
|
+
console.print(f" {line}")
|
|
27
|
+
|
|
28
|
+
if test_result.stderr:
|
|
29
|
+
console.print(f" [yellow]stderr:[/yellow]")
|
|
30
|
+
for line in test_result.stderr.strip().split('\n'):
|
|
31
|
+
console.print(f" {line}")
|
|
32
|
+
|
|
33
|
+
if verbose >= 2:
|
|
34
|
+
if test_result.exception and test_result.exception.__traceback__:
|
|
35
|
+
console.print(f" [yellow]traceback:[/yellow]")
|
|
36
|
+
tb_lines = traceback.format_tb(test_result.exception.__traceback__)
|
|
37
|
+
for line in tb_lines:
|
|
38
|
+
for tb_line in line.strip().split('\n'):
|
|
39
|
+
console.print(f" {tb_line}")
|
surimi/registration.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import importlib
|
|
2
|
+
import sys
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
def discover_tests(dir: str = '.'):
|
|
7
|
+
test_locations = [
|
|
8
|
+
dir,
|
|
9
|
+
os.path.join(dir, 'src'),
|
|
10
|
+
os.path.join(dir, 'tests'),
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
for test_location in test_locations:
|
|
14
|
+
if not os.path.isdir(test_location):
|
|
15
|
+
continue
|
|
16
|
+
|
|
17
|
+
for root, dirs, files in os.walk(test_location):
|
|
18
|
+
dirs[:] = [
|
|
19
|
+
d for d in dirs
|
|
20
|
+
if os.path.exists(os.path.join(root, d, "__init__.py"))
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
for file in files:
|
|
24
|
+
if file.endswith(".py"):
|
|
25
|
+
rel_path = os.path.relpath(os.path.join(root, file), dir)
|
|
26
|
+
module_name = rel_path.replace(os.sep, ".").replace(".py", "")
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
importlib.import_module(module_name)
|
|
30
|
+
except ImportError as e:
|
|
31
|
+
print(f"[red]Error importing {module_name}: {e}[/red]")
|
|
32
|
+
|
surimi/runner.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
import sys
|
|
3
|
+
from io import StringIO
|
|
4
|
+
import time
|
|
5
|
+
from .data import TestResult
|
|
6
|
+
from .decorators import TestInfos, Test
|
|
7
|
+
from rich.console import Console
|
|
8
|
+
from .formater import format_module_result, format_failed
|
|
9
|
+
|
|
10
|
+
def run_single_test(test_info: TestInfos) -> TestResult:
|
|
11
|
+
old_stdout = sys.stdout
|
|
12
|
+
old_stderr = sys.stderr
|
|
13
|
+
captured_stdout = StringIO()
|
|
14
|
+
captured_stderr = StringIO()
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
sys.stdout = captured_stdout
|
|
18
|
+
sys.stderr = captured_stderr
|
|
19
|
+
|
|
20
|
+
start_time = time.time()
|
|
21
|
+
test_info()
|
|
22
|
+
execution_time = time.time() - start_time
|
|
23
|
+
|
|
24
|
+
return TestResult(
|
|
25
|
+
name=test_info.name,
|
|
26
|
+
fail_with=test_info.fail_with,
|
|
27
|
+
location=test_info.location,
|
|
28
|
+
failed=test_info.fail_with != None,
|
|
29
|
+
stdout=captured_stdout.getvalue(),
|
|
30
|
+
stderr=captured_stderr.getvalue(),
|
|
31
|
+
execution_time=execution_time,
|
|
32
|
+
exception=None
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
except Exception as e:
|
|
36
|
+
execution_time = time.time() - start_time
|
|
37
|
+
return TestResult(
|
|
38
|
+
name=test_info.name,
|
|
39
|
+
fail_with=test_info.fail_with,
|
|
40
|
+
location=test_info.location,
|
|
41
|
+
failed=type(e) != test_info.fail_with,
|
|
42
|
+
stdout=captured_stdout.getvalue(),
|
|
43
|
+
stderr=captured_stderr.getvalue(),
|
|
44
|
+
execution_time=execution_time,
|
|
45
|
+
exception=e
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
finally:
|
|
49
|
+
sys.stdout = old_stdout
|
|
50
|
+
sys.stderr = old_stderr
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def run_tests(test: Test, verbose):
|
|
54
|
+
console = Console()
|
|
55
|
+
for num_module, module in enumerate(test.registered_tests):
|
|
56
|
+
tests = test.registered_tests[module]
|
|
57
|
+
results = []
|
|
58
|
+
failed = False
|
|
59
|
+
total_time = 0
|
|
60
|
+
for t in tests:
|
|
61
|
+
res = run_single_test(t)
|
|
62
|
+
if not res.failed: failed = True
|
|
63
|
+
total_time += res.execution_time
|
|
64
|
+
results.append(res)
|
|
65
|
+
|
|
66
|
+
format_module_result(console, num_module+1, len(test.registered_tests), module, not failed, total_time)
|
|
67
|
+
|
|
68
|
+
first = True
|
|
69
|
+
for res in results:
|
|
70
|
+
if res.failed: format_failed(console, res, verbose)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: surimi
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Simple test library fully written in python
|
|
5
|
+
Author-email: Nicolas Beuve <nicolas@beuve.net>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: click
|
|
11
|
+
Requires-Dist: rich
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+

|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
surimi/__init__.py,sha256=1z93OJDVn3LaJD2LYz0DqFZ6r8xITvOGUqKKGHrm2XM,134
|
|
2
|
+
surimi/cli.py,sha256=5u9-icy1Yv3p9R25piL6tQHwrH1GmqwReYbUiIHRS1s,503
|
|
3
|
+
surimi/data.py,sha256=Wbvl9no6QA9O45nZM726Iy4Gq3b0Pw0PP_7LXYUXX40,235
|
|
4
|
+
surimi/formater.py,sha256=zz0Ydx4HvYNyIUp18OmF-RH_jCHyi9OxwRvID7ywuRU,1748
|
|
5
|
+
surimi/registration.py,sha256=K6ZvRGHl27JEpFVvkmrpI3ACknju9Kq9YojR_Ng-5EQ,863
|
|
6
|
+
surimi/runner.py,sha256=Hki-IU767bW5N-aZqRTdaGLMpXabdguD6Bcx7Y5pqeA,1935
|
|
7
|
+
surimi/decorators/__init__.py,sha256=7bNWJzyTV_ncMYCfOyN3aK43p4A6EJqTx3OLHTRZ9gQ,85
|
|
8
|
+
surimi/decorators/test.py,sha256=NXG3wH03M9gcxsxA1VrbuqKHPDbG-4LzGRsDmNsq6lo,1175
|
|
9
|
+
surimi-0.0.0.dist-info/licenses/LICENSE,sha256=D4Faj9KdjajDDawPHgitaDXWJHLJMfekogEojpOwHhc,1064
|
|
10
|
+
surimi-0.0.0.dist-info/METADATA,sha256=AaBHexiddoQOQtvaDe7y7oEaSgKEEmr_uQpKt3svGL8,351
|
|
11
|
+
surimi-0.0.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
12
|
+
surimi-0.0.0.dist-info/entry_points.txt,sha256=bNaGrLlNoi-OlecfJEN5YiexryK_gzRy6ISHHK4jI-0,43
|
|
13
|
+
surimi-0.0.0.dist-info/top_level.txt,sha256=cXDvYflcNDn4ox5aWNzhAzoUjvvjKxvKGFeMaaa8-NA,7
|
|
14
|
+
surimi-0.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright © 2026 Nicolas Beuve
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
surimi
|