From 596e7465fbe830be0586b06c58c1ee3b7dee955a Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Thu, 28 Apr 2022 11:34:48 +0100 Subject: [PATCH] add pre-commit hook keep tests random print kind.name to pytest output add genbadge to dev dependencies add test badges to readme --- README.md | 3 +++ setup.py | 19 ++++++------------- tests/__init__.py | 5 +++-- tests/pre-commit.ps1 | 31 +++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 tests/pre-commit.ps1 diff --git a/README.md b/README.md index 3a9f78c..1c3a256 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/onyx-and-iris/vban-cmd-python/blob/dev/LICENSE) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) +![Tests Status](./tests/basic.svg?dummy=8484744) +![Tests Status](./tests/banana.svg?dummy=8484744) +![Tests Status](./tests/potato.svg?dummy=8484744) # VBAN CMD diff --git a/setup.py b/setup.py index 70db8d8..8ea0cb6 100644 --- a/setup.py +++ b/setup.py @@ -1,17 +1,10 @@ from setuptools import setup setup( - name='vbancmd', - version='0.0.1', - description='VBAN CMD Python API', - packages=['vbancmd'], - install_requires=[ - 'toml' - ], - extras_require={ - 'development': [ - "pytest", - "pytest-randomly", - ] - } + name="vbancmd", + version="0.0.1", + description="VBAN CMD Python API", + packages=["vbancmd"], + install_requires=["toml"], + extras_require={"development": ["pytest", "pytest-randomly", "genbadge[tests]"]}, ) diff --git a/tests/__init__.py b/tests/__init__.py index b3d3340..d9a72e9 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,10 +2,10 @@ from dataclasses import dataclass import vbancmd from vbancmd import kinds import random +import sys # let's keep things random -# kind_id = random.choice(("basic", "banana", "potato")) -kind_id = "banana" +kind_id = random.choice(("basic", "banana", "potato")) opts = { "ip": "codey.local", @@ -39,6 +39,7 @@ data = Data() def setup_module(): + print(f"\nRunning tests for kind [{data.name}]\n", file=sys.stdout) tests.login() tests.apply_profile("blank") diff --git a/tests/pre-commit.ps1 b/tests/pre-commit.ps1 new file mode 100644 index 0000000..deb12b0 --- /dev/null +++ b/tests/pre-commit.ps1 @@ -0,0 +1,31 @@ +Function RunTests { + $coverage = "./tests/pytest_coverage.log" + $run_tests = "pytest -v --capture=tee-sys --junitxml=./tests/.coverage.xml" + $match_pattern = "^=|^\s*$|^Running|^Using|^plugins|^collecting|^tests" + + Clear-Content $coverage + + ForEach ($line in $(Invoke-Expression $run_tests)) { + If ( $line -Match $match_pattern ) { + if ( $line -Match "^Running tests for kind \[(\w+)\]" ) { $kind = $Matches[1] } + $line | Tee-Object -FilePath $coverage -Append + } + } + Write-Output "$(Get-TimeStamp)" | Out-file $coverage -Append + + Invoke-Expression "genbadge tests -t 90 -i ./tests/.coverage.xml -o ./tests/$kind.svg" +} + +Function Get-TimeStamp { + + return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date) + +} + +if ($MyInvocation.InvocationName -ne ".") { + Invoke-Expression ".\venv\Scripts\Activate.ps1" + + RunTests + + Invoke-Expression "deactivate" +}