diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index ebcf246..7f17dd0 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -54,11 +54,7 @@ jobs: - name: Install dependencies run: pip3 install -r requirements.txt -r requirements-dev.txt - name: Run Pytest - run: | - coverage run -m pytest - coverage xml - - name: Upload coverage report to CodeCov - uses: codecov/codecov-action@v3 + run: pytest tests linting: needs: [dependencies] runs-on: ubuntu-latest diff --git a/codecov.yaml b/codecov.yaml deleted file mode 100644 index 6ce17c3..0000000 --- a/codecov.yaml +++ /dev/null @@ -1,14 +0,0 @@ -comment: - layout: "reach, diff, flags, files" - behavior: default - require_changes: false # if true: only post the comment if coverage changes - require_base: no # [yes :: must have a base report to post] - require_head: yes # [yes :: must have a head report to post] - -coverage: - round: down - precision: 5 - -ignore: - - "./tests/*" - - "./didier/cogs/*" # Cogs can't really be tested properly diff --git a/didier/utils/types/datetime.py b/didier/utils/types/datetime.py index 73d9072..6e5c88e 100644 --- a/didier/utils/types/datetime.py +++ b/didier/utils/types/datetime.py @@ -1,3 +1,3 @@ -def int_to_weekday(number: int) -> str: # pragma: no cover # it's useless to write a test for this +def int_to_weekday(number: int) -> str: """Get the Dutch name of a weekday from the number""" return ["Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"][number] diff --git a/didier/utils/types/string.py b/didier/utils/types/string.py index eddfff8..773890a 100644 --- a/didier/utils/types/string.py +++ b/didier/utils/types/string.py @@ -1,10 +1,9 @@ -import math from typing import Optional def leading(character: str, string: str, target_length: Optional[int] = 2) -> str: """Add a leading [character] to [string] to make it length [target_length] - Pass None to target length to always do it (once), no matter the length + Pass None to target length to always do it, no matter the length """ # Cast to string just in case string = str(string) @@ -17,6 +16,6 @@ def leading(character: str, string: str, target_length: Optional[int] = 2) -> st if len(string) >= target_length: return string - frequency = math.ceil((target_length - len(string)) / len(character)) + frequency = (target_length - len(string)) // len(character) return (frequency * character) + string diff --git a/pyproject.toml b/pyproject.toml index c97a7dd..5263a7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,22 +1,6 @@ [tool.black] line-length = 120 -[tool.coverage.run] -concurrency = [ - "greenlet" -] -source = [ - "didier", - "database" -] -omit = [ - "./tests/*", - "./database/migrations.py", - "./didier/cogs/*", - "./didier/didier.py", - "./didier/data/*" -] - [tool.mypy] plugins = [ "sqlalchemy.ext.mypy.plugin" diff --git a/requirements-dev.txt b/requirements-dev.txt index 646f5e6..aa657e0 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,4 @@ black==22.3.0 -coverage[toml]==6.4.1 mypy==0.961 pylint==2.14.1 pytest==7.1.2 diff --git a/tests/test_database/test_crud/test_ufora_announcements.py b/tests/test_database/test_crud/test_ufora_announcements.py deleted file mode 100644 index ba6564a..0000000 --- a/tests/test_database/test_crud/test_ufora_announcements.py +++ /dev/null @@ -1,67 +0,0 @@ -import datetime - -import pytest -from sqlalchemy.ext.asyncio import AsyncSession - -from database.crud import ufora_announcements as crud -from database.models import UforaAnnouncement, UforaCourse - - -@pytest.fixture -async def course(database_session: AsyncSession) -> UforaCourse: - """Fixture to create a course""" - course = UforaCourse(name="test", code="code", year=1, log_announcements=True) - database_session.add(course) - await database_session.commit() - return course - - -@pytest.fixture -async def announcement(course: UforaCourse, database_session: AsyncSession) -> UforaAnnouncement: - """Fixture to create an announcement""" - announcement = UforaAnnouncement(course_id=course.course_id, publication_date=datetime.datetime.now()) - database_session.add(announcement) - await database_session.commit() - return announcement - - -async def test_get_courses_with_announcements_none(database_session: AsyncSession): - """Test getting all courses with announcements when there are none""" - results = await crud.get_courses_with_announcements(database_session) - assert len(results) == 0 - - -async def test_get_courses_with_announcements(database_session: AsyncSession): - """Test getting all courses with announcements""" - course_1 = UforaCourse(name="test", code="code", year=1, log_announcements=True) - course_2 = UforaCourse(name="test2", code="code2", year=1, log_announcements=False) - database_session.add_all([course_1, course_2]) - await database_session.commit() - - results = await crud.get_courses_with_announcements(database_session) - assert len(results) == 1 - assert results[0] == course_1 - - -async def test_create_new_announcement(course: UforaCourse, database_session: AsyncSession): - """Test creating a new announcement""" - await crud.create_new_announcement(database_session, 1, course=course, publication_date=datetime.datetime.now()) - await database_session.refresh(course) - assert len(course.announcements) == 1 - - -async def test_remove_old_announcements(announcement: UforaAnnouncement, database_session: AsyncSession): - """Test removing all stale announcements""" - course = announcement.course - announcement.publication_date -= datetime.timedelta(weeks=2) - announcement_2 = UforaAnnouncement(course_id=announcement.course_id, publication_date=datetime.datetime.now()) - database_session.add_all([announcement, announcement_2]) - await database_session.commit() - await database_session.refresh(course) - assert len(course.announcements) == 2 - - await crud.remove_old_announcements(database_session) - - await database_session.refresh(course) - assert len(course.announcements) == 1 - assert announcement_2.course.announcements[0] == announcement_2 diff --git a/tests/test_didier/test_utils/test_types/__init__.py b/tests/test_didier/test_utils/test_types/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_didier/test_utils/test_types/test_string.py b/tests/test_didier/test_utils/test_types/test_string.py deleted file mode 100644 index c3826df..0000000 --- a/tests/test_didier/test_utils/test_types/test_string.py +++ /dev/null @@ -1,22 +0,0 @@ -from didier.utils.types.string import leading - - -def test_leading(): - """Test leading() when it actually does something""" - assert leading("0", "5") == "05" - assert leading("0", "5", target_length=3) == "005" - - -def test_leading_not_necessary(): - """Test leading() when the input is already long enough""" - assert leading("0", "05") == "05" - - -def test_leading_no_exact(): - """Test leading() when adding would bring you over the required length""" - assert leading("ab", "c", target_length=6) == "abababc" - - -def test_leading_no_target_length(): - """Test leading() when target_length is None""" - assert leading("0", "05", target_length=None) == "005"