.format replaced by f-strings

This commit is contained in:
Vaclav Tvrdik
2026-09-26 20:25:50 +02:00
parent bb7ae537ea
commit af8c1dd6df
7 changed files with 130 additions and 86 deletions

View File

@@ -32,7 +32,7 @@ class Region:
return (self.a, self.b) == (other.a, other.b)
def __repr__(self):
return "Region({}, {})".format(self.a, self.b)
return f"Region({self.a}, {self.b})"
class Settings(dict):
@@ -240,7 +240,13 @@ def find_syntax_for_file(path, first_line=""):
def ui_info():
return {"system": {"style": "dark"}, "color_scheme": {"value": "Mariana.sublime-color-scheme", "resolved_value": "Packages/Color Scheme - Default/Mariana.sublime-color-scheme"}}
return {
"system": {"style": "dark"},
"color_scheme": {
"value": "Mariana.sublime-color-scheme",
"resolved_value": "Packages/Color Scheme - Default/Mariana.sublime-color-scheme",
},
}
def decode_value(text):

View File

@@ -11,7 +11,7 @@ def change(path, status="M"):
def flagged(*flags):
"""f0.py, f1.py ... with the given staged flags"""
return [git.FileChange("f{}.py".format(i), "M", flag, 1, 1, None) for i, flag in enumerate(flags)]
return [git.FileChange(f"f{i}.py", "M", flag, 1, 1, None) for i, flag in enumerate(flags)]
def option(monkeypatch, name, value):
@@ -28,7 +28,7 @@ def at_change(blocks, row):
view = sublime.View()
st = state.ViewState("/repo")
st.blocks = blocks
view.text = "\n" + "\n".join("l{}".format(i) for i in range(20))
view.text = "\n" + "\n".join(f"l{i}" for i in range(20))
view.sel().add(sublime.Region(commands.render.index_point(view, row)))
return view, st

View File

@@ -133,9 +133,9 @@ def test_help_popup_lists_every_key():
assert view.is_popup_visible()
for group in ("Navigate", "Panels", "Actions", "View"):
assert ">{}<".format(group) in html
assert f">{group}<" in html
for keys in ("] [", "n p", "o ⏎", "j k", "f", "c", "s", "u", "d", "C", "m", "r", "?", "esc"):
assert ">{}<".format(keys) in html
assert f">{keys}<" in html
assert "next / previous change" in html and "open the real file at this line" in html
# working-tree mode: nothing dimmed, every single-action row is a link
assert 'class="dim"' not in html and "uncommitted only" not in html
@@ -222,7 +222,7 @@ def test_minihtml_stylesheets_reject_unsupported_selectors():
for rule in css.split("}"):
head = rule.split("{")[0].strip()
for selector in filter(None, (s.strip() for s in head.split(","))):
assert not unsupported.search(selector), "{}: {}".format(name, selector)
assert not unsupported.search(selector), f"{name}: {selector}"
# --- header summary line ----------------------------------------------------
@@ -238,7 +238,26 @@ def test_summary_counts_staged_and_unstaged_files():
git.FileChange("c.py", "?", False, 1, 0, None),
]
render.render(view, st)
assert '<div class="summary">1 staged, 2 unstaged</div>' in header(view)
summary = header(view).split('<div class="summary">')[1].split("</div>")[0]
# the untracked file's whole content counts as insertions, the way git.changed_files records it
assert summary.startswith("1 staged, 2 unstaged · ")
assert '<span class="del">-2</span>' in summary and '<span class="ins">+3</span>' in summary
def test_summary_totals_skip_binary_files_but_still_count_them():
view = sublime.View()
render.init_view(view)
st = make_state()
st.files = [
git.FileChange("a.py", "M", False, 4, 1, None),
git.FileChange("logo.png", "M", False, None, None, None), # binary: no counts, still a file
]
render.render(view, st)
summary = header(view).split('<div class="summary">')[1].split("</div>")[0]
assert summary.startswith("0 staged, 2 unstaged · ")
assert '<span class="del">-1</span>' in summary and '<span class="ins">+4</span>' in summary
def test_summary_totals_a_commit_and_owns_the_date():