Skip to content

Commit

Permalink
v9.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
GitRon authored Feb 28, 2024
1 parent 8984333 commit 39222f0
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 13 deletions.
1 change: 1 addition & 0 deletions .ambient-package-update/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"dev": [
*DEV_DEPENDENCIES,
"gevent~=23.9",
"httpx~=0.27",
],
"drf": [
"djangorestframework>=3.8.2",
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

- name: Run pre-commit hooks
run: pre-commit run --all-files --hook-stage push

validate_migrations:
name: Validate migrations
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
with:
name: coverage-data

- name: Combine coverage and fail if it's <100%
- name: Combine coverage and fail if it's too low
run: |
python -m coverage html --skip-covered --skip-empty
python -m coverage report --fail-under=96.52
python -m coverage html --skip-covered
python -m coverage report --fail-under=87.64
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
rev: v0.1.14
hooks:
# Run the Ruff linter.
- id: ruff
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

**9.5.1** (2024-02-28)
* Fixed bug in coverage script that a set `GITLAB_CI_DISABLE_COVERAGE` would always skip coverage check
* Bugfix in `number_to_string` for more recent Django versions

**9.5.0** (2024-02-02)
* Added django message test helper method `assert_message_not_in_request`

Expand Down
2 changes: 1 addition & 1 deletion ambient_toolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Python toolbox of Ambient Digital containing an abundance of useful tools and gadgets."""

__version__ = "9.5.0"
__version__ = "9.5.1"
18 changes: 16 additions & 2 deletions ambient_toolbox/gitlab/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
from difflib import ndiff
from http import HTTPStatus
from typing import Optional

import httpx

Expand All @@ -30,7 +31,20 @@ def __init__(self) -> None:
)
self.pipelines_url_with_token = f"{self.pipelines_url}&private_token={self.token}"

self.disable_coverage: bool = os.environ.get("GITLAB_CI_DISABLE_COVERAGE", False)
self.disable_coverage: bool = self.get_disable_coverage(os.environ.get("GITLAB_CI_DISABLE_COVERAGE", "0"))

@staticmethod
def get_disable_coverage(disable_env: str) -> bool:
disable_coverage = disable_env

if disable_coverage.lower() == "true":
return True
elif disable_coverage.lower() == "false":
return False
elif disable_coverage.isdigit():
return bool(int(disable_coverage))
else:
return bool(disable_coverage)

def get_latest_target_branch_commit_sha(self) -> str:
"""
Expand All @@ -42,7 +56,7 @@ def get_latest_target_branch_commit_sha(self) -> str:
)
return result.stdout.decode("utf-8").strip()

def get_pipeline_id_by_commit_sha(self, sha: str) -> int | None:
def get_pipeline_id_by_commit_sha(self, sha: str) -> Optional[int]:
pipeline_url = f"{self.pipelines_url_with_token}&sha={sha}"
response = httpx.get(pipeline_url)
status_code = response.status_code
Expand Down
2 changes: 1 addition & 1 deletion ambient_toolbox/utils/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def number_to_string(value: Optional[Union[int, float]], decimal_digits: int = 0
If the passed "value" is None, it will return `replacement`.
Attention: Will not localise the return value!
"""
return intcomma(floatformat(value, decimal_digits)) if value is not None else replacement
return intcomma(floatformat(value, decimal_digits)).strip(",") if value is not None else replacement


def string_or_none_to_string(value: Optional[any], replacement: str = "-") -> str:
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# -- Project information -----------------------------------------------------

project = "ambient-toolbox"
copyright = "2023, Ambient Innovation: GmbH" # noqa: A001
copyright = "2024, Ambient Innovation: GmbH" # noqa: A001
author = "Ambient Innovation: GmbH <[email protected]>"
version = __version__
release = __version__
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ dev = [
'sphinx-rtd-theme~=2.0',
'm2r2==0.3.3.post2',
'mistune<2.0.0',
'ambient-package-update~=23.12.3',
'flit~=3.9',
'ambient-package-update~=23.12.4',
'gevent~=23.9',
'httpx~=0.27',
]
drf = [
'djangorestframework>=3.8.2',
Expand Down
2 changes: 0 additions & 2 deletions pytest.init

This file was deleted.

Empty file added tests/gitlab/__init__.py
Empty file.
43 changes: 43 additions & 0 deletions tests/gitlab/test_coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from unittest import mock

from django.test import SimpleTestCase

from ambient_toolbox.gitlab.coverage import CoverageService


@mock.patch.dict("os.environ", {"CI_PIPELINE_ID": "17", "CI_PROJECT_ID": "27"})
class CoverageServiceTest(SimpleTestCase):
def test_get_disable_coverage_integer_false(self):
service = CoverageService()
result = service.get_disable_coverage(disable_env="0")

self.assertIsInstance(result, bool)
self.assertFalse(result)

def test_get_disable_coverage_integer_true(self):
service = CoverageService()
result = service.get_disable_coverage(disable_env="1")

self.assertIsInstance(result, bool)
self.assertTrue(result)

def test_get_disable_coverage_string_var_bool_false(self):
service = CoverageService()
result = service.get_disable_coverage(disable_env="False")

self.assertIsInstance(result, bool)
self.assertFalse(result)

def test_get_disable_coverage_string_var_bool_true(self):
service = CoverageService()
result = service.get_disable_coverage(disable_env="True")

self.assertIsInstance(result, bool)
self.assertTrue(result)

def test_get_disable_coverage_string_var_random(self):
service = CoverageService()
result = service.get_disable_coverage(disable_env="Wololo")

self.assertIsInstance(result, bool)
self.assertTrue(result)

0 comments on commit 39222f0

Please sign in to comment.