Skip to content

Commit

Permalink
Fix coverage, add vermin check step
Browse files Browse the repository at this point in the history
  • Loading branch information
finalduty committed Apr 1, 2024
1 parent 4c10b9e commit ab422e8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/ci-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.6']
python-versions: ['3.6']

steps:
- uses: actions/checkout@v4 # https://github.com/actions/cache/releases

- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python ${{ matrix.python-versions }}
uses: actions/setup-python@v5 # https://github.com/actions/setup-python/releases
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python-versions }}

- name: Install Pipenv
run: |
Expand All @@ -33,23 +33,25 @@ jobs:
run: |
pipenv install --deploy --dev
- name: Check minimum required Python version
run: |
vermin -q -t=${{ matrix.python-versions }}- --violations cis_audit.py
- name: Lint with flake8
run: |
pipenv run flake8 *.py
pipenv run flake8 tests/*/*.py
pipenv run flake8 *.py tests/*/*.py
- name: Format with black
run: |
pipenv run black --check cis_audit.py
pipenv run black --check tests/*/*.py
pipenv run black --check cis_audit.py tests/*/*.py
- name: Test with pytest
run: |
pipenv run pytest tests/unit
pipenv run coverage xml
#- name: Codecov
# uses: codecov/codecov-action@v3 # https://github.com/codecov/codecov-action/releases
# uses: codecov/codecov-action@v4 # https://github.com/codecov/codecov-action/releases
#
# with:
# files: coverage.xml
Expand All @@ -64,7 +66,7 @@ jobs:
if: ${{ false }} # disable for now

steps:
- uses: actions/checkout@v4 # https://github.com/actions/cache/releases
- uses: actions/checkout@v4 # https://github.com/actions/checkout/releases

- name: Cache Vagrant boxes
uses: actions/cache@v4 # https://github.com/actions/cache/releases
Expand Down
4 changes: 2 additions & 2 deletions cis_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2377,15 +2377,15 @@ def output_text(results, host_os, benchmark_version, stats):
print(f'Passed {passed} of {total} tests in {duration} seconds ({skipped} Skipped, {errors} Errors)')


def result_stats(results: dict, start_time, end_time) -> dict:
def result_stats(results: "list[dict]", start_time, end_time) -> dict:
passed = 0
failed = 0
skipped = 0
errors = 0

time_delta = (end_time - start_time).total_seconds()
if time_delta >= 10:
duration = round(time_delta, 0)
duration = round(time_delta, None)
else:
duration = round(time_delta, 2)

Expand Down
44 changes: 44 additions & 0 deletions tests/unit/test_result_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3

from datetime import datetime

import pytest

from cis_audit import result_stats


@pytest.mark.parametrize(
"end_time_str,expected_duration",
[
pytest.param("1970-01-01T00:01:00+0000", "60", id="slow"),
pytest.param("1970-01-01T00:00:05+0000", "5.0", id="fast"),
],
)
def test_result_stats(end_time_str, expected_duration):
results = [
{'result': "Error"},
{'result': "Fail"},
{'result': "Fail"},
{'result': "Not Implemented"},
{'result': "Pass"},
{'result': "Pass"},
{'result': "Pass"},
{'result': "Skipped"},
]
datefmt = "%Y-%m-%dT%H:%M:%S%z"
start_time = datetime.strptime("1970-01-01T00:00:00+0000", datefmt)
end_time = datetime.strptime(end_time_str, datefmt)

stats = result_stats(results=results, start_time=start_time, end_time=end_time)

assert str(stats['duration']) == expected_duration
assert stats['errors'] == 1
assert stats['failed'] == 2
assert stats['passed'] == 3
assert stats['skipped'] == 1

# assert stats is None


if __name__ == "__main__":
pytest.main([__file__, "--no-cov"])

0 comments on commit ab422e8

Please sign in to comment.