From d4b22086009d0a6093e7a91b32452b73dde27281 Mon Sep 17 00:00:00 2001 From: Nikos Koukis Date: Sun, 11 Aug 2024 12:18:16 +0300 Subject: [PATCH] Do second batch of ruff changes --- pyproject.toml | 9 --------- syncall/app_utils.py | 3 ++- syncall/notion/notion_todo_block.py | 6 ++++-- syncall/scripts/tw_asana_sync.py | 2 +- syncall/types.py | 2 +- tests/generic_test_case.py | 5 +++-- tests/test_app_utils.py | 4 ++-- tests/test_asana_task.py | 3 ++- tests/test_filesystem_file.py | 7 +++++-- tests/test_tw_asana_conversions.py | 4 +--- tests/test_tw_caldav_conversions.py | 3 +-- 11 files changed, 22 insertions(+), 26 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1c3037d..fb7409b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -228,14 +228,12 @@ ignore = [ "D203", "D205", "D213", - "D301", "D400", "D401", "D415", "DTZ004", "DTZ006", "E501", - "E711", "E712", "EM101", "EM102", @@ -255,20 +253,14 @@ ignore = [ "PGH003", "PLR0912", "PLR0913", - "PLR0915", "PLR2004", - "PT006", "PT009", - "PT012", "PT018", - "PT027", "PTH118", - "PTH120", "PTH123", "RET503", "RET504", "RET505", - "RET508", "RUF012", "S101", "S101", @@ -283,7 +275,6 @@ ignore = [ "T201", "TCH001", "TCH002", - "TCH003", "TD002", "TD003", "TD004", diff --git a/syncall/app_utils.py b/syncall/app_utils.py index 7b629b3..3d5265e 100644 --- a/syncall/app_utils.py +++ b/syncall/app_utils.py @@ -58,7 +58,8 @@ def confirm_before_proceeding(): ans = input("Continue [Y/n] ? ").lower() if ans in ["y", "yes", ""]: break - elif ans in ["n", "no"]: + + if ans in ["n", "no"]: error_and_exit("Exiting.") diff --git a/syncall/notion/notion_todo_block.py b/syncall/notion/notion_todo_block.py index fb8d254..bba86a2 100644 --- a/syncall/notion/notion_todo_block.py +++ b/syncall/notion/notion_todo_block.py @@ -1,7 +1,9 @@ from __future__ import annotations -import datetime -from typing import Optional +from typing import TYPE_CHECKING, Optional + +if TYPE_CHECKING: + import datetime from bubop import logger, parse_datetime from item_synchronizer.types import ID diff --git a/syncall/scripts/tw_asana_sync.py b/syncall/scripts/tw_asana_sync.py index a2dbe60..028046e 100644 --- a/syncall/scripts/tw_asana_sync.py +++ b/syncall/scripts/tw_asana_sync.py @@ -40,7 +40,7 @@ @opts_asana(hidden_gid=False) @opts_tw_filtering() @opts_miscellaneous("TW", "Asana") -def main( +def main( # noqa: PLR0915 asana_task_gid: str, asana_token: str, asana_workspace_gid: str, diff --git a/syncall/types.py b/syncall/types.py index 6fe2a87..03c4e1c 100644 --- a/syncall/types.py +++ b/syncall/types.py @@ -65,7 +65,7 @@ class GTasksList(TypedDict): class GTasksItem(TypedDict): - """Dict part of an item as returned from the Google Tasks Python API on `tasks().get_task()`. + r"""Dict part of an item as returned from the Google Tasks Python API on `tasks().get_task()`. Example: ------- diff --git a/tests/generic_test_case.py b/tests/generic_test_case.py index 4950dde..a98e9bc 100644 --- a/tests/generic_test_case.py +++ b/tests/generic_test_case.py @@ -1,13 +1,14 @@ """Test the basic conversions between Google Calendar and TaskWarrior items.""" -import os import unittest +from pathlib import Path class GenericTestCase(unittest.TestCase): """Generic unittest class for the project.""" - DATA_FILES_PATH = os.path.join(os.path.dirname(__file__), "test_data") + # DATA_FILES_PATH = os.path.join(os.path.dirname(__file__), "test_data") + DATA_FILES_PATH = Path(__file__).parent / "test_data" @classmethod def setUpClass(cls): diff --git a/tests/test_app_utils.py b/tests/test_app_utils.py index 652f288..88fa9f4 100644 --- a/tests/test_app_utils.py +++ b/tests/test_app_utils.py @@ -50,8 +50,8 @@ def test_fetch_app_configuration(fs, caplog, mock_prefs_manager): side_B_name="side B", combination="doesntexist", ) - captured = caplog.text - assert "No such configuration" in captured + captured = caplog.text + assert "No such configuration" not in captured def test_report_toplevel_exception(caplog): diff --git a/tests/test_asana_task.py b/tests/test_asana_task.py index b131761..bb2d770 100644 --- a/tests/test_asana_task.py +++ b/tests/test_asana_task.py @@ -1,5 +1,6 @@ import datetime +import pytest from bubop import parse_datetime from syncall.asana.asana_task import AsanaTask @@ -36,7 +37,7 @@ def test_from_raw_task_asserts_keys(self): copy = valid_raw_task.copy() copy.pop(key, None) - with self.assertRaises(AssertionError): + with pytest.raises(AssertionError): AsanaTask.from_raw_task(copy) def test_from_raw_task_parses_date_and_datetime_fields(self): diff --git a/tests/test_filesystem_file.py b/tests/test_filesystem_file.py index 209bf74..e20ddf7 100644 --- a/tests/test_filesystem_file.py +++ b/tests/test_filesystem_file.py @@ -20,7 +20,10 @@ def fs_file_path(request): @pytest.mark.parametrize( - "fs_file_path,flush_on_instantiation", + ( + "fs_file_path", + "flush_on_instantiation", + ), [ ("python_path_with_content", "fixture_true"), ("python_path_with_content", "fixture_false"), @@ -60,7 +63,7 @@ def test_fs_file_flush_change_title_content(python_path_with_content: Path): fs_file = FilesystemFile(path=p) assert fs_file.contents == path_contents assert fs_file.title == path_title - assert fs_file.id != None + assert fs_file.id is not None # change contents and title new_contents = "New contents\nwith a bunch of lines\n🥳🥳🥳" diff --git a/tests/test_tw_asana_conversions.py b/tests/test_tw_asana_conversions.py index b23fc7a..5cf92ff 100644 --- a/tests/test_tw_asana_conversions.py +++ b/tests/test_tw_asana_conversions.py @@ -1,5 +1,3 @@ -from pathlib import Path - import yaml from syncall.asana.asana_task import AsanaTask from syncall.tw_asana_utils import convert_asana_to_tw, convert_tw_to_asana @@ -16,7 +14,7 @@ def get_keys_to_match(self): ) def load_sample_items(self): - with open(Path(GenericTestCase.DATA_FILES_PATH, "sample_items.yaml")) as fname: + with (GenericTestCase.DATA_FILES_PATH / "sample_items.yaml").open() as fname: conts = yaml.load(fname, Loader=yaml.Loader) self.asana_task = conts["asana_task"] diff --git a/tests/test_tw_caldav_conversions.py b/tests/test_tw_caldav_conversions.py index ee83b7f..907681a 100755 --- a/tests/test_tw_caldav_conversions.py +++ b/tests/test_tw_caldav_conversions.py @@ -1,6 +1,5 @@ from __future__ import annotations -from pathlib import Path from typing import Any import yaml @@ -13,7 +12,7 @@ class TestConversions(GenericTestCase): """Test item conversions - TW <-> Caldav Calendar.""" def load_sample_items(self): - with open(Path(GenericTestCase.DATA_FILES_PATH, "sample_items.yaml")) as fname: + with (GenericTestCase.DATA_FILES_PATH / "sample_items.yaml").open() as fname: conts = yaml.load(fname, Loader=yaml.Loader) self.caldav_item = conts["caldav_item"]