Skip to content

Commit

Permalink
Improve tests (#152)
Browse files Browse the repository at this point in the history
* Add pytest-cov, improve coverage

* fix
  • Loading branch information
inverse authored Feb 3, 2025
1 parent 3436d8e commit 86eb216
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
__pycache__/
/dist/
/assets/*.gif
/.coverage
/htmlcov/
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ repos:
- id: isort
additional_dependencies: [toml]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
rev: v1.14.1
hooks:
- id: mypy
additional_dependencies: [types-requests]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.7.4'
rev: 'v0.9.4'
hooks:
- id: ruff
args:
Expand Down
100 changes: 97 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pytest = "^8.3.4"
pytest-socket = "^0.7.0"
vcrpy = "^7.0.0"

[tool.poetry.group.dev.dependencies]
pytest-cov = "^6.0.0"

[tool.ruff]
lint.ignore = ["E501"]

Expand Down
24 changes: 23 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest import TestCase

from cert_host_scraper.utils import strip_url
from cert_host_scraper.utils import divide_chunks, strip_url


class TestStripUrl(TestCase):
Expand All @@ -16,3 +16,25 @@ def test_strip_www(self):
def test_strip_path(self):
self.assertEqual("example.com", strip_url("example.com/"))
self.assertEqual("example.com", strip_url("example.com/hello"))


class TestDivideChunks(TestCase):
def test_even_chunks(self):
self.assertEqual(
list(divide_chunks(["a", "b", "c", "d"], 2)), [["a", "b"], ["c", "d"]]
)

def test_uneven_chunks(self):
self.assertEqual(list(divide_chunks(["a", "b", "c"], 2)), [["a", "b"], ["c"]])

def test_single_element_chunks(self):
self.assertEqual(list(divide_chunks(["a", "b", "c"], 1)), [["a"], ["b"], ["c"]])

def test_chunk_size_larger_than_list(self):
self.assertEqual(list(divide_chunks(["a", "b"], 5)), [["a", "b"]])

def test_empty_list(self):
self.assertEqual(list(divide_chunks([], 3)), [])

def test_chunk_size_one(self):
self.assertEqual(list(divide_chunks(["a"], 1)), [["a"]])

0 comments on commit 86eb216

Please sign in to comment.