Skip to content

Commit ef5e3cf

Browse files
committed
reformatting
1 parent b5cf15e commit ef5e3cf

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed

src/edit_python_pe/main.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import glob
33
import hashlib
44
import os
5+
import pathlib
56
import re
67
from datetime import datetime
78
from time import sleep
8-
import pathlib
9+
910
import pygit2
1011
from github import Github
1112
from github.GithubException import BadCredentialsException, GithubException
@@ -132,8 +133,12 @@ def clear_form(self) -> None:
132133
self.homepage_input.value = ""
133134
self.who_area.text = "¿Quién eres y a qué te dedicas?"
134135
self.python_area.text = "¿Cómo programas en Python?"
135-
self.contributions_area.text = "¿Tienes algún aporte a la comunidad de Python?"
136-
self.availability_area.text = "¿Estás disponible para hacer mentoring, consultorías, charlas?"
136+
self.contributions_area.text = (
137+
"¿Tienes algún aporte a la comunidad de Python?"
138+
)
139+
self.availability_area.text = (
140+
"¿Estás disponible para hacer mentoring, consultorías, charlas?"
141+
)
137142

138143
for soc in self.social_entries:
139144
soc.remove()
@@ -491,7 +496,9 @@ def save_member(self) -> None:
491496
# commit & push
492497
repo = pygit2.Repository(self.repo_path)
493498
rel_path = os.path.relpath(file_path, self.repo_path)
494-
rel_path = pathlib.Path(rel_path).as_posix() # Force path to POSIX format so Windows backslashes (\) don't break pygit2
499+
rel_path = pathlib.Path(
500+
rel_path
501+
).as_posix() # Force path to POSIX format so Windows backslashes (\) don't break pygit2
495502
repo.index.add(rel_path)
496503
repo.index.write()
497504
author_sig = pygit2.Signature(
@@ -595,9 +602,7 @@ def get_repo() -> tuple[str, Repository]:
595602
def fork_repo(token: str, original_repo: Repository) -> str:
596603
forked_repo = original_repo.create_fork()
597604
forked_repo_url = forked_repo.clone_url
598-
repo_path = user_data_dir(
599-
appname="edit-python-pe", appauthor="python.pe"
600-
)
605+
repo_path = user_data_dir(appname="edit-python-pe", appauthor="python.pe")
601606

602607
if not os.path.exists(repo_path):
603608
callbacks = pygit2.callbacks.RemoteCallbacks(

tests/test_member_app.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,34 @@ def test_add_list_button_clears_form(self):
102102
# Add social and alias entries
103103
self.app.social_entries = [self.StubSocialEntry()]
104104
self.app.alias_entries = [self.StubAliasEntry()]
105+
105106
# Simulate pressing the 'Añadir' button on the list screen
106107
class DummyButton:
107108
id = "add_list"
109+
108110
class DummyEvent:
109111
button = DummyButton()
112+
110113
self.app.on_button_pressed(DummyEvent())
111114
# After pressing, form should be cleared and current_file should be None
112115
self.assertEqual(self.app.name_input.value, "")
113116
self.assertEqual(self.app.email_input.value, "")
114117
self.assertEqual(self.app.city_input.value, "")
115118
self.assertEqual(self.app.homepage_input.value, "")
116-
self.assertEqual(self.app.who_area.text, "¿Quién eres y a qué te dedicas?")
117-
self.assertEqual(self.app.python_area.text, "¿Cómo programas en Python?")
118-
self.assertEqual(self.app.contributions_area.text, "¿Tienes algún aporte a la comunidad de Python?")
119-
self.assertEqual(self.app.availability_area.text, "¿Estás disponible para hacer mentoring, consultorías, charlas?")
119+
self.assertEqual(
120+
self.app.who_area.text, "¿Quién eres y a qué te dedicas?"
121+
)
122+
self.assertEqual(
123+
self.app.python_area.text, "¿Cómo programas en Python?"
124+
)
125+
self.assertEqual(
126+
self.app.contributions_area.text,
127+
"¿Tienes algún aporte a la comunidad de Python?",
128+
)
129+
self.assertEqual(
130+
self.app.availability_area.text,
131+
"¿Estás disponible para hacer mentoring, consultorías, charlas?",
132+
)
120133
self.assertEqual(len(self.app.social_entries), 0)
121134
self.assertEqual(len(self.app.alias_entries), 0)
122135
self.assertIsNone(self.app.current_file)
@@ -448,10 +461,13 @@ def stub_add_alias_entry():
448461
self.assertEqual(self.app.homepage_input.value, "https://joe-doe.org")
449462
self.assertGreaterEqual(len(self.app.social_entries), 1)
450463

464+
451465
# Test for get_repo function
452466
import builtins
467+
453468
from edit_python_pe.main import get_repo
454469

470+
455471
class TestGetRepo(unittest.TestCase):
456472
@patch("edit_python_pe.main.getpass.getpass", return_value="valid-token")
457473
@patch("edit_python_pe.main.Github")
@@ -466,27 +482,36 @@ def test_get_repo_success(self, mock_github, mock_getpass):
466482
@patch("edit_python_pe.main.Github")
467483
def test_get_repo_bad_credentials(self, mock_github, mock_getpass):
468484
from github.GithubException import BadCredentialsException
469-
mock_github.return_value.get_repo.side_effect = BadCredentialsException(401, "Bad credentials", None)
485+
486+
mock_github.return_value.get_repo.side_effect = (
487+
BadCredentialsException(401, "Bad credentials", None)
488+
)
470489
with self.assertRaises(SystemExit):
471490
get_repo()
472491

473492
@patch("edit_python_pe.main.getpass.getpass", return_value="valid-token")
474493
@patch("edit_python_pe.main.Github")
475494
def test_get_repo_github_exception(self, mock_github, mock_getpass):
476495
from github.GithubException import GithubException
477-
mock_github.return_value.get_repo.side_effect = GithubException(404, "Not found", None)
496+
497+
mock_github.return_value.get_repo.side_effect = GithubException(
498+
404, "Not found", None
499+
)
478500
with self.assertRaises(SystemExit):
479501
get_repo()
480502

481503

482504
from edit_python_pe.main import fork_repo
483505

506+
484507
class TestForkRepo(unittest.TestCase):
485508
@patch("edit_python_pe.main.user_data_dir", return_value="/tmp/testrepo")
486509
@patch("edit_python_pe.main.os.path.exists", return_value=False)
487510
@patch("edit_python_pe.main.pygit2.clone_repository")
488511
@patch("edit_python_pe.main.sleep", return_value=None)
489-
def test_fork_repo_clones_if_not_exists(self, mock_sleep, mock_clone, mock_exists, mock_user_data_dir):
512+
def test_fork_repo_clones_if_not_exists(
513+
self, mock_sleep, mock_clone, mock_exists, mock_user_data_dir
514+
):
490515
mock_forked_repo = MagicMock()
491516
mock_forked_repo.clone_url = "https://github.com/fake/fork.git"
492517
mock_original_repo = MagicMock()
@@ -502,16 +527,22 @@ def test_fork_repo_clones_if_not_exists(self, mock_sleep, mock_clone, mock_exist
502527
@patch("edit_python_pe.main.user_data_dir", return_value="/tmp/testrepo")
503528
@patch("edit_python_pe.main.os.path.exists", return_value=True)
504529
@patch("edit_python_pe.main.pygit2.clone_repository")
505-
def test_fork_repo_no_clone_if_exists(self, mock_clone, mock_exists, mock_user_data_dir):
530+
def test_fork_repo_no_clone_if_exists(
531+
self, mock_clone, mock_exists, mock_user_data_dir
532+
):
506533
mock_forked_repo = MagicMock()
507534

535+
508536
from edit_python_pe.main import main
509537

538+
510539
class TestMainFunction(unittest.TestCase):
511540
@patch("edit_python_pe.main.get_repo")
512541
@patch("edit_python_pe.main.fork_repo")
513542
@patch("edit_python_pe.main.MemberApp")
514-
def test_main_runs_app(self, mock_member_app, mock_fork_repo, mock_get_repo):
543+
def test_main_runs_app(
544+
self, mock_member_app, mock_fork_repo, mock_get_repo
545+
):
515546
mock_get_repo.return_value = ("token", MagicMock())
516547
mock_fork_repo.return_value = "/tmp/testrepo"
517548
mock_app_instance = MagicMock()

0 commit comments

Comments
 (0)