Skip to content

Commit

Permalink
chore(release): version 2.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ddkasa committed Nov 5, 2024
2 parents f11f37d + ed4a69e commit f67f9ea
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 14 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ulauncher_toggl_extension.utils import ensure_import

ensure_import("toggl_api", "toggl-api-wrapper", "1.3.1")
ensure_import("toggl_api", "toggl-api-wrapper", "1.3.2")

from ulauncher_toggl_extension.extension import TogglExtension # noqa: E402

Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

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

17 changes: 16 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ulauncher-toggl-extension"
version = "2.6.3"
version = "2.7.1"
description = "Toggl time tracker extension for Ulauncher."
authors = ["David Kasakaitis <[email protected]>"]
readme = "README.md"
Expand Down Expand Up @@ -140,6 +140,21 @@ basepython = python3.12
commands = ruff check ulauncher_toggl_extension/
"""

[tool.coverage.run]
omit = [
"*/tests/*",
"*/.venv/*",
"*/.mypy_cache/*",
"*/.ruff_cache/*",
"*/.pytest_cache/*",
"docs/*",
"scripts/*",
"*/.github/*",
"*/.tox/*",
"*/.git/*",
]


[tool.coverage.report]
exclude_also = [
"def __repr__",
Expand Down
18 changes: 17 additions & 1 deletion tests/test_commands/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING

import pytest
Expand All @@ -14,7 +15,7 @@
DeleteProjectCommand,
DeleteTagCommand,
)
from ulauncher_toggl_extension.commands.meta import Command
from ulauncher_toggl_extension.commands.meta import Command, QueryParameters

if TYPE_CHECKING:
from toggl_api.modules.models import TogglClass
Expand Down Expand Up @@ -89,3 +90,18 @@ def create_tag(dummy_ext, faker):

command = DeleteTagCommand(dummy_ext)
command.handle([], model=model)


@pytest.fixture
def dummy_query_parameters(faker, tmp_path):
def generate_params(total) -> list[QueryParameters]:
return [
QueryParameters(
Path(tmp_path),
name=faker.name(),
description=faker.name(),
)
for _ in range(total)
]

return generate_params
30 changes: 30 additions & 0 deletions tests/test_commands/test_meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest

from ulauncher_toggl_extension.commands.tracker import ListCommand


@pytest.mark.unit
@pytest.mark.parametrize(
("data", "static"),
[(12, 0), (1, 0), (10, 2), (15, 1), (0, 0), (200, 2)],
)
def test_cmd_paginator(data, static, dummy_ext, dummy_query_parameters):
params = dummy_query_parameters(data)

static_param = dummy_query_parameters(static)

cmd = ListCommand(dummy_ext)

total = 0
page = 1
per_page = dummy_ext.max_results - (static + 1)
while total < data:
paginator = cmd._paginator([], params, static_param, page=page) # noqa: SLF001
assert all(
p.name == e.name and p.description == e.description
for p, e in zip(paginator[:per_page], params[per_page * page : per_page])
)
total += min(per_page, len(paginator))
page += 1

assert total == data
12 changes: 12 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
from pathlib import Path

import pytest
from pip._vendor import tomli # noqa: PLC2701

from ulauncher_toggl_extension import __version__
from ulauncher_toggl_extension.utils import ensure_import


@pytest.mark.unit
def test_version():
with (Path.cwd() / "pyproject.toml").open("rb") as pyproject:
pyversion = tomli.load(pyproject)["tool"]["poetry"]["version"]

assert __version__ == pyversion


@pytest.mark.unit
def test_ensure_import():
with pytest.raises((ModuleNotFoundError,)):
Expand Down
2 changes: 1 addition & 1 deletion ulauncher_toggl_extension/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.7.0"
__version__ = "2.7.1"
8 changes: 6 additions & 2 deletions ulauncher_toggl_extension/commands/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import enum
import logging
import math
from abc import abstractmethod
from dataclasses import dataclass
from datetime import timedelta
Expand Down Expand Up @@ -261,8 +262,11 @@ def _paginator(
"""
page_data: list[QueryParameters] = list(static)

results_per_page = self.max_results - (len(static) + 1)
total_pages = len(data) // (self.max_results - len(static))
extra = len(page_data) + 1

results_per_page = self.max_results - extra
total_pages = math.floor(len(data) / results_per_page)

next_page = len(data) > self.max_results and page < total_pages
prev_page = page > 0

Expand Down
11 changes: 6 additions & 5 deletions ulauncher_toggl_extension/commands/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,14 @@ def increment_date(cls, day: date, *, increment: bool = True) -> date | None:
elif cls.FRAME == TimeFrame.WEEK:
next_date = day + timedelta(weeks=diff)
elif cls.FRAME == TimeFrame.MONTH:
next_date = day.replace(month=day.month + diff)
_, month = calendar.monthrange(day.year, day.month)
next_date = day + timedelta(days=month * diff)
else:
msg = "Target timeframe is not supported!"
raise NotImplementedError(msg)

if isinstance(day, datetime):
next_date = day.date()
next_date = next_date.date()

return next_date if next_date <= date.today() else None # noqa: DTZ011

Expand Down Expand Up @@ -348,7 +349,7 @@ class WeeklyReportCommand(ReportCommand):
OPTIONS = (">", "~")

def preview(self, query: list[str], **kwargs) -> list[QueryParameters]:
start = kwargs.get("start", datetime.now(tz=timezone.utc))
start = kwargs.get("start") or datetime.now(tz=timezone.utc)
kwargs["start"] = start
self.amend_query(query)
return [
Expand Down Expand Up @@ -412,7 +413,7 @@ def summary(self, day: date) -> list[QueryParameters]:
return result

def view(self, query: list[str], **kwargs) -> list[QueryParameters]:
start = kwargs.get("start", datetime.now(tz=timezone.utc))
start = kwargs.get("start") or datetime.now(tz=timezone.utc)
kwargs["start"] = start
suffix = kwargs.get("format", self.report_format)
kwargs["format"] = suffix
Expand Down Expand Up @@ -458,7 +459,7 @@ class MonthlyReportCommand(ReportCommand):
OPTIONS = (">", "~")

def preview(self, query: list[str], **kwargs) -> list[QueryParameters]:
start = kwargs.get("start", datetime.now(tz=timezone.utc))
start = kwargs.get("start") or datetime.now(tz=timezone.utc)
kwargs["start"] = start
self.amend_query(query)
return [
Expand Down

0 comments on commit f67f9ea

Please sign in to comment.