black formatting

This commit is contained in:
Paul Gauthier 2023-05-17 18:24:35 -07:00
parent 3c26f90269
commit 9a413d351d
4 changed files with 26 additions and 16 deletions

View file

@ -86,7 +86,10 @@ class Commands:
return
if self.coder.repo.is_dirty():
self.io.tool_error("The repository has uncommitted changes. Please commit or stash them before undoing.")
self.io.tool_error(
"The repository has uncommitted changes. Please commit or stash them before"
" undoing."
)
return
local_head = self.coder.repo.git.rev_parse("HEAD")
@ -100,7 +103,10 @@ class Commands:
self.io.tool_error(f"Error: Unable to get the remote 'origin/{current_branch}'.")
return
if local_head == remote_head:
self.io.tool_error("The last commit has already been pushed to the origin. Undoing is not possible.")
self.io.tool_error(
"The last commit has already been pushed to the origin. Undoing is not"
" possible."
)
return
last_commit = self.coder.repo.head.commit

View file

@ -1,27 +1,29 @@
import traceback
import json
def cvt(s):
if isinstance(s, str):
return s
try:
return json.dumps(s, indent = 4)
return json.dumps(s, indent=4)
except TypeError:
return str(s)
def dump(*vals):
# http://docs.python.org/library/traceback.html
stack= traceback.extract_stack()
vars= stack[-2][3]
stack = traceback.extract_stack()
vars = stack[-2][3]
# strip away the call to dump()
vars= '('.join(vars.split('(')[1:])
vars= ')'.join(vars.split(')')[:-1])
vars = "(".join(vars.split("(")[1:])
vars = ")".join(vars.split(")")[:-1])
vals= [cvt(v) for v in vals]
has_newline = sum(1 for v in vals if '\n' in v)
vals = [cvt(v) for v in vals]
has_newline = sum(1 for v in vals if "\n" in v)
if has_newline:
print('%s:' % vars)
print(', '.join(vals))
print("%s:" % vars)
print(", ".join(vals))
else:
print('%s:' % vars, ', '.join(vals))
print("%s:" % vars, ", ".join(vals))

View file

@ -51,7 +51,9 @@ def try_dotdotdots(whole, part, replace):
continue
if whole.count(part) != 1:
raise ValueError("No perfect matching chunk in edit block with ... or part appears more than once")
raise ValueError(
"No perfect matching chunk in edit block with ... or part appears more than once"
)
whole = whole.replace(part, replace, 1)

View file

@ -13,14 +13,14 @@ class TestMain(TestCase):
def test_main_with_empty_dir_no_files_on_command(self):
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)
pipe_input = create_input(StringIO(''))
pipe_input = create_input(StringIO(""))
main([], input=pipe_input, output=DummyOutput())
pipe_input.close()
def test_main_with_empty_dir_new_file(self):
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)
pipe_input = create_input(StringIO(''))
pipe_input = create_input(StringIO(""))
main(["foo.txt"], input=pipe_input, output=DummyOutput())
pipe_input.close()
self.assertTrue(os.path.exists("foo.txt"))
@ -29,7 +29,7 @@ class TestMain(TestCase):
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)
subprocess.run(["git", "init"], cwd=temp_dir)
pipe_input = create_input(StringIO(''))
pipe_input = create_input(StringIO(""))
main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
pipe_input.close()
self.assertTrue(os.path.exists("foo.txt"))