Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ main ]

jobs:
test:
code-tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -28,15 +28,15 @@ jobs:
- name: Install dependencies
run: uv sync --dev

- name: Run tests with coverage
run: uv run pytest -v --cov=src --cov-branch --cov-report=term --cov-report=xml
- name: Run tests with coverage (as defined in pyproject.toml)
run: uv run pytest

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}

lint:
code-quality:
runs-on: ubuntu-latest

steps:
Expand All @@ -52,3 +52,6 @@ jobs:

- name: Run ruff linting
run: uv run ruff check src test

- name: Run mypy type checking
run: uv run mypy src test
17 changes: 11 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "casregnum"
version = "1.1.1"
version = "1.1.2"
description = "Python class to manage, check and sort CAS Registry Numbers® (CAS RN®)"
readme = "README.md"
authors = [
Expand Down Expand Up @@ -33,11 +33,12 @@ build-backend = "hatchling.build"

[tool.uv]
dev-dependencies = [
"pytest",
"pytest-sugar",
"pytest-cov",
"ruff",
"twine",
"mypy>=1.18.1",
"pytest>=8.4.1",
"pytest-cov>=7.0.0",
"pytest-sugar>=1.1.1",
"ruff>=0.13.0",
"twine>=6.2.0",
]

[tool.pytest.ini_options]
Expand All @@ -49,6 +50,10 @@ addopts = [
"--strict-markers",
"--strict-config",
"--verbose",
"--cov=src",
"--cov-branch",
"--cov-report=term",
"--cov-report=xml",
]

[tool.ruff]
Expand Down
18 changes: 12 additions & 6 deletions src/casregnum/casregnum.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,23 @@ def __repr__(self) -> str:
return f"CAS(cas_rn='{self.cas_string}')"

# defines a string format for CAS Registry Numbers
def __format__(self, format_spec) -> str:
def __format__(self, format_spec: str) -> str:
return f"{self.cas_string:{format_spec}}"

# checks if two CAS Registry Numbers are equal
def __eq__(self, other: CAS) -> bool:
def __eq__(self, other: object) -> bool:
"""
Checks if two CAS Registry Numbers® are equal.
"""
if not isinstance(other, CAS):
raise TypeError("Comparisons can only be made between CAS objects.")
return self.cas_integer == other.cas_integer

# checks if self.cas_integer < other.cas_integer
def __lt__(self, other: CAS) -> bool:
def __lt__(self, other: object) -> bool:
"""
Checks if this CAS Registry Number® is less than another CAS Registry Number®.
"""
if not isinstance(other, CAS):
raise TypeError("Comparisons can only be made between CAS objects.")
return self.cas_integer < other.cas_integer
Expand All @@ -70,7 +76,7 @@ def __lt__(self, other: CAS) -> bool:
@property
def cas_string(self) -> str:
"""
Returns the CAS Registry Number as a formatted string (e.g. "58-08-2").
Returns the CAS Registry Number® as a formatted string (e.g. "58-08-2").
"""
return self._cas_string

Expand All @@ -95,7 +101,7 @@ def cas_string(self, cas_rn: str) -> None:
@property
def cas_integer(self) -> int:
"""
Returns the CAS Registry Number as an integer (e.g. 58082).
Returns the CAS Registry Number® as an integer (e.g. 58082).
"""
return self._cas_integer

Expand All @@ -114,7 +120,7 @@ def cas_integer(self, cas_rn: int) -> None:
@property
def check_digit(self) -> int:
"""
Returns the check digit of the CAS Registry Number (e.g. 2 for "58-08-2").
Returns the check digit of the CAS Registry Number® as an integer (e.g. 2 for "58-08-2").
"""
return self._check_digit

Expand Down
17 changes: 17 additions & 0 deletions src/casregnum/casregnum.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CAS:
def __init__(self, cas_rn: int | str) -> None: ...
def __format__(self, format_spec: str) -> str: ...
def __eq__(self, other: object) -> bool: ...
def __lt__(self, other: object) -> bool: ...
@property
def cas_string(self) -> str: ...
@cas_string.setter
def cas_string(self, cas_rn: str) -> None: ...
@property
def cas_integer(self) -> int: ...
@cas_integer.setter
def cas_integer(self, cas_rn: int) -> None: ...
@property
def check_digit(self) -> int: ...
@check_digit.setter
def check_digit(self, digit_to_test: int) -> None: ...
Empty file added src/casregnum/py.typed
Empty file.
Loading
Loading