Skip to content

Commit 9f31273

Browse files
committed
Fix default loading of config
1 parent 884340e commit 9f31273

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

gitea_github_sync/github.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from dataclasses import dataclass
44
from enum import Flag, auto
5-
from typing import List
5+
from typing import List, Optional
66

77
from github import Github
88

@@ -36,7 +36,9 @@ def get_repo_name(self) -> str:
3636
return self.full_repo_name.split("/")[1]
3737

3838

39-
def get_github(conf: config.Config = config.load_config()) -> Github:
39+
def get_github(conf: Optional[config.Config] = None) -> Github:
40+
if conf is None:
41+
conf = config.load_config()
4042
return Github(login_or_token=conf.github_token)
4143

4244

tests/test_github.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,17 @@ def test_github(mock_github: MagicMock, conf_fixture: Config) -> None:
7171
mock_github.assert_called_once_with(conf_fixture.github_token)
7272

7373

74+
@patch("gitea_github_sync.github.config.load_config", autospec=True)
7475
@patch("gitea_github_sync.github.Github", autospec=True)
75-
def test_github_default_value(mock_github: MagicMock, conf_fixture: Config) -> None:
76-
get_github.__defaults__ = (conf_fixture,)
76+
def test_github_default_value(
77+
mock_github: MagicMock, mock_load_config: MagicMock, conf_fixture: Config
78+
) -> None:
79+
mock_load_config.return_value = conf_fixture
7780
gh = get_github()
7881

7982
assert gh == mock_github.return_value
8083
mock_github.assert_called_once_with(conf_fixture.github_token)
84+
mock_load_config.assert_called_once()
8185

8286

8387
@dataclass(frozen=True)

0 commit comments

Comments
 (0)