Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply uncontroversial ruff format changes #459

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apport/crashdb_impl/debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
# the full text of the license.


import email.mime.text
import smtplib
import tempfile
Expand Down
2 changes: 1 addition & 1 deletion apport/crashdb_impl/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __enter__(self):

self.__authentication_data = {
"client_id": self.__client_id,
"device_code": f'{response["device_code"]}',
"device_code": f"{response['device_code']}",
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
}
self.__cooldown = response["interval"]
Expand Down
5 changes: 1 addition & 4 deletions apport/hookutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,7 @@
codec = os.path.basename(codecpath)
for name in os.listdir(codecpath):
path = os.path.join(codecpath, name)
key = (
f"Card{card}.Codecs"
f".{path_to_key(codec)}.{path_to_key(name)}"
)
key = f"Card{card}.Codecs.{path_to_key(codec)}.{path_to_key(name)}"

Check warning on line 330 in apport/hookutils.py

View check run for this annotation

Codecov / codecov/patch

apport/hookutils.py#L330

Added line #L330 was not covered by tests
attach_file(report, path, key)


Expand Down
5 changes: 1 addition & 4 deletions apport/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,10 +1446,7 @@ def _get_python_exception_title(self) -> str | None:
if len(trace) < 1:
return None
if len(trace) < 3:
return (
f"{os.path.basename(self['ExecutablePath'])}"
f" crashed with {trace[0]}"
)
return f"{os.path.basename(self['ExecutablePath'])} crashed with {trace[0]}"

trace_re = re.compile(r'^\s*File\s*"(\S+)".* in (.+)$')
i = len(trace) - 1
Expand Down
3 changes: 1 addition & 2 deletions apport/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@ def __init__(self, argv: list[str]) -> None:
except ImportError as error:
# this can happen while upgrading python packages
apport.logging.fatal(
"Could not import module, is a package upgrade in progress?"
" Error: %s",
"Could not import module, is a package upgrade in progress? Error: %s",
str(error),
)
except KeyError:
Expand Down
6 changes: 2 additions & 4 deletions bin/apport-retrace
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
"--dynamic-origins",
action="store_true",
help=_(
"Create and use third-party repositories from origins specified"
" in reports"
"Create and use third-party repositories from origins specified in reports"
),
)
argparser.add_argument(
Expand Down Expand Up @@ -683,8 +682,7 @@ Thank you for your understanding, and sorry for the inconvenience!
crashdb.mark_retrace_failed(crashid, invalid_msg)
else:
apport.log(
"Report has no crash signature,"
" so retrace is flawed",
"Report has no crash signature, so retrace is flawed",
options.timestamps,
)
crashdb.mark_retrace_failed(crashid)
Expand Down
9 changes: 3 additions & 6 deletions data/apport
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,7 @@ def forward_crash_to_container(
with open("uid_map", "r", encoding="utf-8", opener=proc_host_pid_opener) as fd:
if not apport.fileutils.search_map(fd, task_uid):
logger.error(
"host pid %s crashed in a container"
" with no access to the binary",
"host pid %s crashed in a container with no access to the binary",
options.global_pid,
)
return
Expand All @@ -567,8 +566,7 @@ def forward_crash_to_container(
with open("gid_map", "r", encoding="utf-8", opener=proc_host_pid_opener) as fd:
if not apport.fileutils.search_map(fd, task_gid):
logger.error(
"host pid %s crashed in a container"
" with no access to the binary",
"host pid %s crashed in a container with no access to the binary",
options.global_pid,
)
return
Expand Down Expand Up @@ -925,8 +923,7 @@ def process_crash_from_kernel(options: argparse.Namespace) -> int:
return process_crash_from_kernel_with_proc_pid(options, proc_pid)
except FileNotFoundError as error:
logging.getLogger().error(
"%s not found. "
"Cannot collect crash information for process %i any more.",
"%s not found. Cannot collect crash information for process %i any more.",
error.filename,
options.pid,
)
Expand Down
3 changes: 1 addition & 2 deletions data/general-hooks/parse_segv.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,7 @@ def report(self):
# Handle I/O port operations
if self.insn in {"out", "in"} and not understood:
msg = (
f"disallowed I/O port operation"
f" on port {self.register_value(self.src)}"
f"disallowed I/O port operation on port {self.register_value(self.src)}"
)
reason.append(msg)
details.append(msg)
Expand Down
3 changes: 1 addition & 2 deletions problem_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class MalformedProblemReport(ValueError):

def __init__(self, message: str, *args: object):
super().__init__(
f"Malformed problem report: {message}."
f" Is this a proper .crash text file?",
f"Malformed problem report: {message}. Is this a proper .crash text file?",
*args,
)

Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_apport_unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ def test_broken_core_dump(self) -> None:
"""Test unpacking a report file that has a malformed CoreDump entry."""
with tempfile.NamedTemporaryFile("wb") as report_file:
report_file.write(
b"CoreDump: base64\n H4sICAAAAAAC/0NvcmVEdW1wAA==\n"
b" 7Z0LYFPV/cdP0rQ\n"
b"CoreDump: base64\n H4sICAAAAAAC/0NvcmVEdW1wAA==\n 7Z0LYFPV/cdP0rQ\n"
)
report_file.flush()
process = self._call_apport_unpack([report_file.name, self.unpack_dir])
Expand Down
9 changes: 3 additions & 6 deletions tests/integration/test_crashdb_launchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ def get_python_report(self) -> int:
r.add_user_info()
self.assertEqual(
r.standard_title(),
"foo crashed with NameError in fuzz():"
" global name 'weird' is not defined",
"foo crashed with NameError in fuzz(): global name 'weird' is not defined",
)

return self._create_bug_from_report("Python", r)
Expand Down Expand Up @@ -189,8 +188,7 @@ def get_uncommon_description_report(self, force_fresh: bool = False) -> None:
target=self.crashdb.lp_distro,
)
sys.stderr.write(
f"(Created uncommon description:"
f" https://{self.hostname}/bugs/{bug.id}) "
f"(Created uncommon description: https://{self.hostname}/bugs/{bug.id}) "
)

return bug.id
Expand Down Expand Up @@ -855,8 +853,7 @@ def test_project(self):
r.add_user_info()
self.assertEqual(
r.standard_title(),
"foo crashed with NameError in fuzz():"
" global name 'weird' is not defined",
"foo crashed with NameError in fuzz(): global name 'weird' is not defined",
)

# file it
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_dupdb_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ def test_dump_database(self) -> None:
lines = stdout.rstrip().split("\n")
self.assertEqual(len(lines), 2, lines)
self.assertIn(
"0: /bin/crash:11:foo_bar:d01:raise:<signal handler called>:__frob"
" [open]",
"0: /bin/crash:11:foo_bar:d01:raise:<signal handler called>:__frob [open]",
lines[0],
)
self.assertIn("2: /usr/bin/broken:11:h:g:f:e:d [fixed in: 42]", lines[1])
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_fileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def test_get_config(self) -> None:

# nonempty
f.write(
b"[main]\none=1\ntwo = TWO\nb1 = 1\nb2=False\n" b"[spethial]\none= 99\n"
b"[main]\none=1\ntwo = TWO\nb1 = 1\nb2=False\n[spethial]\none= 99\n"
)
f.flush()
self.assertIsNone(apport.fileutils.get_config("main", "foo"))
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_problem_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_write_append(self) -> None:
WhiteSpace:
foo bar
baz
blip{' '}
blip{" "}
Extra: appended
"""
),
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_python_crashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _test_crash(
os.write(
fd,
f"""\
#!/usr/bin/env {os.getenv('PYTHON', 'python3')}
#!/usr/bin/env {os.getenv("PYTHON", "python3")}
import apport_python_hook
apport_python_hook.install()

Expand Down Expand Up @@ -386,7 +386,7 @@ def test_ignoring(self):
fd,
textwrap.dedent(
f"""\
#!/usr/bin/env {os.getenv('PYTHON', 'python3')}
#!/usr/bin/env {os.getenv("PYTHON", "python3")}
import apport_python_hook
apport_python_hook.install()

Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_recoverable_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def _wait_for_report(self) -> str:
time.sleep(0.1)
seconds += 0.1
self.fail(
f"timeout while waiting for .crash file to be created"
f" in {self.report_dir}."
f"timeout while waiting for .crash file to be created in {self.report_dir}."
)

@unittest.mock.patch("os.listdir")
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_add_proc_info(self) -> None:
testscript.write_text(
textwrap.dedent(
f"""\
#!/usr/bin/{os.getenv('PYTHON', 'python3')}
#!/usr/bin/{os.getenv("PYTHON", "python3")}
import sys
sys.stdin.readline()
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_signal_crashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,8 +1229,7 @@ def do_crash(
os.unlink(core_path)
except OSError as error:
sys.stderr.write(
f"WARNING: cannot clean up core file {core_path}:"
f" {str(error)}\n"
f"WARNING: cannot clean up core file {core_path}: {str(error)}\n"
)

self.fail("leaves unexpected core file behind")
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,6 @@ def _gen_test_crash(self) -> apport.Report:
env={"HOME": self.workdir},
stdout=subprocess.PIPE,
) as gdb:

try:
pid = wait_for_process_to_appear(
self.TEST_EXECUTABLE,
Expand Down Expand Up @@ -1996,9 +1995,7 @@ def test_run_symptom(self, stderr_mock: MagicMock) -> None:
# working noninteractive script
self._write_symptom_script(
"itching.py",
"def run(report, ui):\n"
' report["itch"] = "scratch"\n'
' return "bash"\n',
'def run(report, ui):\n report["itch"] = "scratch"\n return "bash"\n',
)
self.ui = UserInterfaceMock(["ui-test", "-s", "itching"])
self.ui.present_details_response = apport.ui.Action(report=True)
Expand Down
12 changes: 6 additions & 6 deletions tests/system/test_packaging_apt_dpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,15 +742,15 @@ def test_create_sources_for_a_named_ppa(
if {"deb", "deb-src"} == set(e.types)
and "jammy" in e.suites
and "main" in e.comps
and "http://ppa.launchpad.net/" "daisy-pluckers/daisy-seeds/ubuntu" in e.uris
and "http://ppa.launchpad.net/daisy-pluckers/daisy-seeds/ubuntu" in e.uris
]
assert [
e
for e in entries
if "deb" in e.types
and "jammy" in e.suites
and "main/debug" in e.comps
and "http://ppa.launchpad.net/" "daisy-pluckers/daisy-seeds/ubuntu" in e.uris
and "http://ppa.launchpad.net/daisy-pluckers/daisy-seeds/ubuntu" in e.uris
]

trusted_gpg_d = pathlib.Path(rootdir) / "etc" / "apt" / "trusted.gpg.d"
Expand Down Expand Up @@ -781,17 +781,17 @@ def test_create_sources_for_an_unnamed_ppa(
if {"deb", "deb-src"} == set(e.types)
and "jammy" in e.suites
and "main" in e.comps
and "http://ppa.launchpad.net/"
"apport-hackers/apport-autopkgtests/ubuntu" in e.uris
and "http://ppa.launchpad.net/apport-hackers/apport-autopkgtests/ubuntu"
in e.uris
]
assert [
e
for e in entries
if "deb" in e.types
and "jammy" in e.suites
and "main/debug" in e.comps
and "http://ppa.launchpad.net/"
"apport-hackers/apport-autopkgtests/ubuntu" in e.uris
and "http://ppa.launchpad.net/apport-hackers/apport-autopkgtests/ubuntu"
in e.uris
]

trusted_gpg_d = pathlib.Path(rootdir) / "etc" / "apt" / "trusted.gpg.d"
Expand Down
5 changes: 2 additions & 3 deletions tests/system/test_python_crashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _test_crash(self, extracode: str) -> str:
os.write(
fd,
f"""\
#!/usr/bin/env {os.getenv('PYTHON', 'python3')}
#!/usr/bin/env {os.getenv("PYTHON", "python3")}
import apport_python_hook
apport_python_hook.install()

Expand Down Expand Up @@ -224,8 +224,7 @@ def test_dbus_service_other_error(self) -> None:
signature = pr.crash_signature()
assert signature
self.assertIn(
"dbus.exceptions.DBusException"
"(org.freedesktop.DBus.Error.UnknownMethod):",
"dbus.exceptions.DBusException(org.freedesktop.DBus.Error.UnknownMethod):",
signature,
)

Expand Down
4 changes: 1 addition & 3 deletions tests/unit/test_fileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ def test_get_recent_crashes(self) -> None:

# ancient report
r = io.BytesIO(
b"ProblemType: Crash\n"
b"Date: Wed Aug 01 00:00:01 1990\n"
b"CrashCounter: 3\n"
b"ProblemType: Crash\nDate: Wed Aug 01 00:00:01 1990\nCrashCounter: 3\n"
)
self.assertEqual(apport.fileutils.get_recent_crashes(r), 0)

Expand Down
16 changes: 6 additions & 10 deletions tests/unit/test_problem_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_load(self) -> None:
WhiteSpace:
foo bar
baz
blip{' '}
blip{" "}
"""
)
pr = problem_report.ProblemReport()
Expand Down Expand Up @@ -275,11 +275,7 @@ def test_load_invalid_utf8(self) -> None:
def test_load_incorrect_padding(self) -> None:
"""Throw exception when base64 encoded data has incorrect padding."""
report = problem_report.ProblemReport()
content = (
b"CoreDump: base64\n"
b" H4sICAAAAAAC/0NvcmVEdW1wAA==\n"
b" 7Z0LYFPV/cdP0rQ\n"
)
content = b"CoreDump: base64\n H4sICAAAAAAC/0NvcmVEdW1wAA==\n 7Z0LYFPV/cdP0rQ\n"
with io.BytesIO(content) as report_file:
with self.assertRaisesRegex(
problem_report.MalformedProblemReport,
Expand Down Expand Up @@ -620,9 +616,9 @@ def test_write_mime_text(self) -> None:
fourth
fifth
LargeMultiline:
{'A' * 120}
{'B' * 90}
Largeline: {'A' * 999}
{"A" * 120}
{"B" * 90}
Largeline: {"A" * 999}
Simple: bar
SimpleLineEnd: bar
SimpleUTF8: 1äö2Φ3
Expand Down Expand Up @@ -665,7 +661,7 @@ def test_write_mime_text(self) -> None:
f"""\
foo bar
baz
blip{' '}
blip{" "}
line4
line♥5!!
łıµ€ ⅝
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,7 @@ def test_crash_signature_addresses(self) -> None:

# all resolvable, but too short
pr["Stacktrace"] = (
"#0 0x00007f491fac5687 in kill ()"
" at ../sysdeps/unix/syscall-template.S:82"
"#0 0x00007f491fac5687 in kill () at ../sysdeps/unix/syscall-template.S:82"
)
self.assertIsNone(pr.crash_signature_addresses())

Expand Down