Skip to content

Commit

Permalink
pre-commit run --all
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyNotHugo committed Sep 24, 2023
1 parent dcd3b7a commit 301aa0e
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 112 deletions.
6 changes: 2 additions & 4 deletions tests/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ async def test_recurring_events(self, s, item_type):
uid = str(uuid.uuid4())
item = Item(
textwrap.dedent(
"""
f"""
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
Expand Down Expand Up @@ -417,9 +417,7 @@ async def test_recurring_events(self, s, item_type):
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
""".format(
uid=uid
)
"""
).strip()
)

Expand Down
4 changes: 2 additions & 2 deletions tests/storage/dav/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def test_xml_utilities():
def test_xml_specialchars(char):
x = _parse_xml(
'<?xml version="1.0" encoding="UTF-8" ?>'
"<foo>ye{}s\r\n"
"hello</foo>".format(chr(char)).encode("ascii")
f"<foo>ye{chr(char)}s\r\n"
"hello</foo>".encode("ascii")
)

if char in _BAD_XML_CHARS:
Expand Down
20 changes: 8 additions & 12 deletions tests/system/cli/test_discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,21 @@ def test_discover_direct_path(tmpdir, runner):
def test_null_collection_with_named_collection(tmpdir, runner):
runner.write_with_general(
dedent(
"""
f"""
[pair foobar]
a = "foo"
b = "bar"
collections = [["baz", "baz", null]]
[storage foo]
type = "filesystem"
path = "{base}/foo/"
path = "{str(tmpdir)}/foo/"
fileext = ".txt"
[storage bar]
type = "singlefile"
path = "{base}/bar.txt"
""".format(
base=str(tmpdir)
)
path = "{str(tmpdir)}/bar.txt"
"""
)
)

Expand Down Expand Up @@ -221,22 +219,20 @@ async def list(self) -> List[tuple]:

runner.write_with_general(
dedent(
"""
f"""
[pair foobar]
a = "foo"
b = "bar"
collections = null
[storage foo]
type = "test"
require_collection = {a}
require_collection = {json.dumps(a_requires)}
[storage bar]
type = "test"
require_collection = {b}
""".format(
a=json.dumps(a_requires), b=json.dumps(b_requires)
)
require_collection = {json.dumps(b_requires)}
"""
)
)

Expand Down
10 changes: 4 additions & 6 deletions tests/system/cli/test_fetchparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@
def test_get_password_from_command(tmpdir, runner):
runner.write_with_general(
dedent(
"""
f"""
[pair foobar]
a = "foo"
b = "bar"
collections = ["a", "b", "c"]
[storage foo]
type.fetch = ["shell", "echo filesystem"]
path = "{base}/foo/"
path = "{str(tmpdir)}/foo/"
fileext.fetch = ["command", "echo", ".txt"]
[storage bar]
type = "filesystem"
path = "{base}/bar/"
path = "{str(tmpdir)}/bar/"
fileext.fetch = ["prompt", "Fileext for bar"]
""".format(
base=str(tmpdir)
)
"""
)
)

Expand Down
56 changes: 22 additions & 34 deletions tests/system/cli/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,24 +280,22 @@ def get_cfg():
def test_create_collections(collections, tmpdir, runner):
runner.write_with_general(
dedent(
"""
f"""
[pair foobar]
a = "foo"
b = "bar"
collections = {colls}
collections = {json.dumps(list(collections))}
[storage foo]
type = "filesystem"
path = "{base}/foo/"
path = "{str(tmpdir)}/foo/"
fileext = ".txt"
[storage bar]
type = "filesystem"
path = "{base}/bar/"
path = "{str(tmpdir)}/bar/"
fileext = ".txt"
""".format(
base=str(tmpdir), colls=json.dumps(list(collections))
)
"""
)
)

Expand All @@ -315,24 +313,22 @@ def test_create_collections(collections, tmpdir, runner):
def test_ident_conflict(tmpdir, runner):
runner.write_with_general(
dedent(
"""
f"""
[pair foobar]
a = "foo"
b = "bar"
collections = null
[storage foo]
type = "filesystem"
path = "{base}/foo/"
path = "{str(tmpdir)}/foo/"
fileext = ".txt"
[storage bar]
type = "filesystem"
path = "{base}/bar/"
path = "{str(tmpdir)}/bar/"
fileext = ".txt"
""".format(
base=str(tmpdir)
)
"""
)
)

Expand Down Expand Up @@ -371,19 +367,17 @@ def test_ident_conflict(tmpdir, runner):
def test_unknown_storage(tmpdir, runner, existing, missing):
runner.write_with_general(
dedent(
"""
f"""
[pair foobar]
a = "foo"
b = "bar"
collections = null
[storage {existing}]
type = "filesystem"
path = "{base}/{existing}/"
path = "{str(tmpdir)}/{existing}/"
fileext = ".txt"
""".format(
base=str(tmpdir), existing=existing
)
"""
)
)

Expand All @@ -393,10 +387,8 @@ def test_unknown_storage(tmpdir, runner, existing, missing):
assert result.exception

assert (
"Storage '{missing}' not found. "
"These are the configured storages: ['{existing}']".format(
missing=missing, existing=existing
)
f"Storage '{missing}' not found. "
f"These are the configured storages: ['{existing}']"
) in result.output


Expand All @@ -416,25 +408,23 @@ def test_no_configured_pairs(tmpdir, runner, cmd):
def test_conflict_resolution(tmpdir, runner, resolution, expect_foo, expect_bar):
runner.write_with_general(
dedent(
"""
f"""
[pair foobar]
a = "foo"
b = "bar"
collections = null
conflict_resolution = {val}
conflict_resolution = {json.dumps(resolution)}
[storage foo]
type = "filesystem"
fileext = ".txt"
path = "{base}/foo"
path = "{str(tmpdir)}/foo"
[storage bar]
type = "filesystem"
fileext = ".txt"
path = "{base}/bar"
""".format(
base=str(tmpdir), val=json.dumps(resolution)
)
path = "{str(tmpdir)}/bar"
"""
)
)

Expand Down Expand Up @@ -526,13 +516,11 @@ def test_fetch_only_necessary_params(tmpdir, runner):
fetch_script = tmpdir.join("fetch_script")
fetch_script.write(
dedent(
"""
f"""
set -e
touch "{}"
touch "{str(fetched_file)}"
echo ".txt"
""".format(
str(fetched_file)
)
"""
)
)

Expand Down
4 changes: 2 additions & 2 deletions vdirsyncer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
)


def _check_python_version(): # pragma: no cover
def _check_python_version():
import sys

if sys.version_info < (3, 7, 0):
if sys.version_info < (3, 7, 0): # noqa: UP036
print("vdirsyncer requires at least Python 3.7.")
sys.exit(1)

Expand Down
2 changes: 1 addition & 1 deletion vdirsyncer/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def app(ctx, config: str):
cli_logger.warning(
"Vdirsyncer currently does not support Windows. "
"You will likely encounter bugs. "
"See {}/535 for more information.".format(BUGTRACKER_HOME)
f"See {BUGTRACKER_HOME}/535 for more information."
)

if not ctx.config:
Expand Down
12 changes: 5 additions & 7 deletions vdirsyncer/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def validate_section_name(name, section_type):
if invalid:
chars_display = "".join(sorted(SECTION_NAME_CHARS))
raise exceptions.UserError(
'The {}-section "{}" contains invalid characters. Only '
f'The {section_type}-section "{name}" contains invalid characters. Only '
"the following characters are allowed for storage and "
"pair names:\n{}".format(section_type, name, chars_display)
f"pair names:\n{chars_display}"
)


Expand All @@ -51,7 +51,7 @@ def _validate_general_section(general_config: dict[str, str]):
if problems:
raise exceptions.UserError(
"Invalid general section. Copy the example "
"config from the repository and edit it: {}".format(PROJECT_HOME),
f"config from the repository and edit it: {PROJECT_HOME}",
problems=problems,
)

Expand Down Expand Up @@ -210,10 +210,8 @@ def get_storage_args(self, storage_name: str):
args = self.storages[storage_name]
except KeyError:
raise exceptions.UserError(
"Storage {!r} not found. "
"These are the configured storages: {}".format(
storage_name, list(self.storages)
)
f"Storage {storage_name!r} not found. "
f"These are the configured storages: {list(self.storages)}"
)
else:
return expand_fetch_params(args)
Expand Down
10 changes: 5 additions & 5 deletions vdirsyncer/cli/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ async def collections_for_pair(
elif rv:
raise exceptions.UserError(
"Detected change in config file, "
"please run `vdirsyncer discover {}`.".format(pair.name)
f"please run `vdirsyncer discover {pair.name}`."
)
else:
raise exceptions.UserError(
"Please run `vdirsyncer discover {}` "
" before synchronization.".format(pair.name)
f"Please run `vdirsyncer discover {pair.name}` "
" before synchronization."
)

logger.info(f"Discovering collections for pair {pair.name}")
Expand Down Expand Up @@ -271,8 +271,8 @@ async def _print_collections(

logger.debug("".join(traceback.format_tb(sys.exc_info()[2])))
logger.warning(
"Failed to discover collections for {}, use `-vdebug` "
"to see the full traceback.".format(instance_name)
f"Failed to discover collections for {instance_name}, use `-vdebug` "
"to see the full traceback."
)
return
logger.info(f"{instance_name}:")
Expand Down
3 changes: 1 addition & 2 deletions vdirsyncer/cli/fetchparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def _fetch_value(opts, key):
else:
if not rv:
raise exceptions.UserError(
"Empty value for {}, this most likely "
"indicates an error.".format(key)
f"Empty value for {key}, this most likely indicates an error."
)
password_cache[cache_key] = rv
return rv
Expand Down
Loading

0 comments on commit 301aa0e

Please sign in to comment.