diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9f13c7c..a47c6e8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,21 +16,12 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - name: Install dependencies + - name: Run tests run: | - sudo apt-get update sudo apt-get install -y python3 python3-venv python3-pip - python3 -m pip install --upgrade pip python3 -m venv .venv source .venv/bin/activate - pip install ".[test]" - - - name: Run Pytest - shell: 'script -q -e -c "bash {0}"' # work around tty issues - env: - TERM: linux # fix tput for tty issue work around - run: | - source .venv/bin/activate - python3 -m pytest + python3 -m pip install ".[test]" + python3 -m pytest --log-level=DEBUG diff --git a/pyproject.toml b/pyproject.toml index e78b379..04f2e98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ dependencies = [ "vdirsyncer", "orgparse" ] -version = "0.0.0" +version = "0.0.1" [project.optional-dependencies] debug = ["ipdb", "ipython"] diff --git a/src/khalorg/commands.py b/src/khalorg/commands.py index 4489fbd..c3ec105 100644 --- a/src/khalorg/commands.py +++ b/src/khalorg/commands.py @@ -13,7 +13,7 @@ def list_command( calendar: str, - khalorg_format: str = get_khalorg_format(), + khalorg_format: str | None = None, start: str = 'today', stop: str = '1d', **_) -> str: @@ -31,6 +31,7 @@ def list_command( stdout of the `khal list` command after post processing """ + khalorg_format = khalorg_format or get_khalorg_format() args: KhalArgs = KhalArgs() args['-a'] = calendar args['-f'] = get_khal_format() diff --git a/src/khalorg/khal/calendar.py b/src/khalorg/khal/calendar.py index 77397dd..8a363d5 100644 --- a/src/khalorg/khal/calendar.py +++ b/src/khalorg/khal/calendar.py @@ -84,8 +84,8 @@ def __init__(self, name: str): """ path_config: Union[str, None] = find_configuration_file() - new_item_args: list = ['khal', 'new'] - list_args: list = ['khal', 'list', '-df', ''] + new_item_args: list = ["python3", "-m", "khal", "new"] + list_args: list = ["python3", "-m", "khal", "list", "-df", ""] self._collection: CalendarCollection self._new_item: Callable = subprocess_callback(new_item_args) diff --git a/src/khalorg/khal/helpers.py b/src/khalorg/khal/helpers.py index 00ae0a9..249afbc 100644 --- a/src/khalorg/khal/helpers.py +++ b/src/khalorg/khal/helpers.py @@ -1,4 +1,5 @@ import logging +import sys from datetime import date, datetime from subprocess import STDOUT, CalledProcessError, check_output from typing import Callable @@ -35,11 +36,18 @@ def is_future(timestamp: datetime | date) -> bool: True if the `timestamp` is in the future """ + logging.debug( + "Check if timestamp %s (type: %s) is in the future", + timestamp, + type(timestamp), + ) if isinstance(timestamp, datetime): - now: datetime = datetime.now(timestamp.tzinfo) - return timestamp >= now + now = datetime.now(timestamp.tzinfo) else: - return timestamp >= datetime.now().date() + now = datetime.now().date() + + logging.debug("Now is %s", now) + return timestamp >= now def subprocess_callback(cmd: list) -> Callable: @@ -56,6 +64,7 @@ def subprocess_callback(cmd: list) -> Callable: callback function """ + def callback(args: list) -> str: return try_check_output([*cmd, *args]).decode() @@ -64,12 +73,13 @@ def callback(args: list) -> str: def try_check_output(args: list) -> bytes: try: - return check_output(args, stderr=STDOUT) + return check_output(args, stderr=STDOUT, executable=sys.executable) except CalledProcessError as error: error_message: str = ( f"The following arguments were sent to khal:\n\n{' '.join(args)}" "\n\nNext, the following error was received from khal:\n\n" - f"{error.output.decode()}\n\n") + f"{error.output.decode()}\n\n" + ) logging.critical(error_message) raise Exception(error_message) from error diff --git a/tests/helpers.py b/tests/helpers.py index 238fb92..588cfd6 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -413,7 +413,7 @@ def get_start_end(delta: timedelta = timedelta(hours=1), """ # must be in the future - start: datetime = datetime.now() + timedelta(minutes=1) + start: datetime = datetime.now() + timedelta(minutes=2) end: datetime = start + delta if all_day: diff --git a/tests/test_commands.py b/tests/test_commands.py index 24ca8e8..ffcc953 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1,4 +1,5 @@ from datetime import date, datetime, timedelta +import logging from os.path import join from tests import static from tests.helpers import ( @@ -84,8 +85,12 @@ def _list_test(runner, expected: OrgAgendaItem): expected.properties['UID'] = actual.properties['UID'] expected.properties['CALENDAR'] = actual.properties['CALENDAR'] expected.properties['RRULE'] = actual.properties['RRULE'] - assert str(expected) == str(actual), f'Org item: {expected}' + logging.debug("khalorg_format: %s", khalorg_format) + logging.debug("Stdout: %s", stdout) + logging.debug("Expected: %s", expected) + logging.debug("Actual: %s", actual) + assert str(expected) == str(actual) # A recurring item should have a non empty rrule assert bool(actual.properties['RRULE']) == bool(expected.first_timestamp._repeater) # noqa