-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add usage of Pydantic, interfaces and dedicated config holders
- Loading branch information
Showing
43 changed files
with
1,096 additions
and
556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# basic | ||
__pycache__ | ||
.vscode | ||
**/__pycache__ | ||
.coverage | ||
.pytest_cache | ||
|
||
# git subrepos | ||
android_* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# basic | ||
__pycache__ | ||
.vscode | ||
**/__pycache__ | ||
.mypy_cache | ||
.coverage | ||
.pytest_cache | ||
|
||
# git subrepos | ||
/android_* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
from pathlib import Path | ||
|
||
|
||
apath = Path(Path(__file__).absolute().parents[1]) | ||
with open(Path(apath, "pyproject.toml")) as f: | ||
print(f.read().split('version = "')[1].split('"')[0]) | ||
def main() -> None: | ||
rootpath = Path(Path(__file__).absolute().parents[1]) | ||
with open(Path(rootpath, "pyproject.toml")) as f: | ||
print(f.read().split('version = "')[1].split('"')[0]) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
import subprocess | ||
from typing import List | ||
from pathlib import Path | ||
from subprocess import CompletedProcess | ||
|
||
ROOTPATH: Path = Path(Path(__file__).absolute().parents[1]) | ||
|
||
|
||
class Tester: | ||
"""A single class for all types of tests.""" | ||
|
||
def _launch_cmd(cmd: str) -> CompletedProcess: | ||
"""Launch specified command.""" | ||
return subprocess.run(cmd, shell=True, check=True) | ||
|
||
def pytest_checks(self) -> CompletedProcess: | ||
"""Run unit tests with Pytest and coverage checks.""" | ||
os.environ["PYTHONPATH"] = ROOTPATH | ||
return self._launch_cmd("python3 -m pytest tests/ --cov") | ||
|
||
def pyright_checks(self) -> CompletedProcess: | ||
"""Run type (hint) checks with Pyright.""" | ||
return self._launch_cmd("python3 -m pyright wrapper") | ||
|
||
def bandit_checks(self) -> List[CompletedProcess]: | ||
"""Run SAST with Bandit.""" | ||
fmts = ("json", "html") | ||
cps = [] | ||
for fmt in fmts: | ||
cps.append(self._launch(f"python3 -m bandit -r -f {fmt} {ROOTPATH} -o report.{fmt}")) | ||
return cps | ||
|
||
|
||
def main() -> None: | ||
os.chdir(ROOTPATH) | ||
t = Tester() | ||
t.pytest_checks() | ||
t.pyright_checks() | ||
t.bandit_checks() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
from pathlib import Path | ||
|
||
from wrapper.modules.kernel_builder import KernelBuilder | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"config, expected_defconfig", | ||
( | ||
( | ||
{"codename": "dumpling", "base": "los", "lkv": "4.4", "clean_kernel": False, "ksu": False}, | ||
Path("lineage_oneplus5_defconfig") | ||
), | ||
( | ||
{"codename": "cheeseburger", "base": "pa", "lkv": "4.14", "clean_kernel": False, "ksu": True}, | ||
Path("vendor", "paranoid_defconfig") | ||
), | ||
( | ||
{"codename": "dumpling", "base": "x", "lkv": "4.4", "clean_kernel": True, "ksu": True}, | ||
Path("oneplus5_defconfig") | ||
) | ||
) | ||
) | ||
def test__defconfig__check(config: dict[str], expected_defconfig: Path) -> bool: | ||
"""Test defconfig path definition.""" | ||
t = KernelBuilder(**config) | ||
res_actual = t._defconfig | ||
res_expected = expected_defconfig | ||
assert res_actual == res_expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import pytest | ||
|
||
import wrapper.tools.commands as ccmd | ||
|
||
|
||
def test__launch__invalid_command(capfd) -> None: | ||
"""Test an invalid command execution handling.""" | ||
cmd = "some_invalid_command" | ||
with pytest.raises(SystemExit): | ||
ccmd.launch(cmd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pytest | ||
|
||
import wrapper.tools.messages as msg | ||
|
||
|
||
def test__message_note__validate(capfd): | ||
"""Check "note" message construction.""" | ||
m = "This is a test message." | ||
expected_result = f"[ * ] {m}" | ||
msg.note(m) | ||
out, err = capfd.readouterr() | ||
assert out.rstrip() == expected_result | ||
|
||
|
||
@pytest.mark.parametrize("dont_exit", (False, True)) | ||
def test__message_error__validate(capfd, dont_exit: bool) -> None: | ||
"""Check "error" message construction.""" | ||
m = "This is a test message." | ||
expected_result = f"[ ! ] {m}" | ||
if dont_exit is False: | ||
with pytest.raises(SystemExit): | ||
msg.error(m, dont_exit) | ||
else: | ||
msg.error(m, dont_exit) | ||
out, err = capfd.readouterr() | ||
assert err.rstrip() == expected_result | ||
|
||
|
||
def test__message_done__validate(capfd) -> None: | ||
"""Check "done" message construction.""" | ||
m = "This is a test message." | ||
expected_result = f"[ + ] {m}" | ||
msg.done(m) | ||
out, err = capfd.readouterr() | ||
assert out.rstrip() == expected_result | ||
|
||
|
||
def test__message_cancel__validate(capfd) -> None: | ||
"""Check "cancel" message construction.""" | ||
m = "This is a test message." | ||
expected_result = f"[ ~ ] {m}" | ||
# system exit with code 0 is still a SystemExit | ||
with pytest.raises(SystemExit): | ||
msg.cancel(m) | ||
out, err = capfd.readouterr() | ||
assert out.rstrip() == expected_result | ||
|
||
|
||
def test__message_debug__validate(capfd) -> None: | ||
"""Check "debug" message construction.""" | ||
m = "This is a test message." | ||
expected_result = f"[ DEBUG ] {m}" | ||
msg.debug(m) | ||
out, err = capfd.readouterr() | ||
assert out.rstrip() == expected_result |
Oops, something went wrong.