Skip to content

Commit e26d007

Browse files
Merge pull request #485 from reef-technologies/public_get_user_account_info_path
Add SqliteAccountInfo.get_user_account_info_path to public API
2 parents ea8626b + a3d5f22 commit e26d007

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

b2sdk/account_info/sqlite_account_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(self, file_name=None, last_upgrade_to_run=None, profile: str | None
7373
"""
7474
self.thread_local = threading.local()
7575

76-
self.filename = self._get_user_account_info_path(file_name=file_name, profile=profile)
76+
self.filename = self.get_user_account_info_path(file_name=file_name, profile=profile)
7777
logger.debug('%s file path to use: %s', self.__class__.__name__, self.filename)
7878

7979
self._validate_database(last_upgrade_to_run)
@@ -105,7 +105,7 @@ def _get_xdg_config_path(cls) -> str | None:
105105
return None
106106

107107
@classmethod
108-
def _get_user_account_info_path(cls, file_name: str | None = None, profile: str | None = None):
108+
def get_user_account_info_path(cls, file_name: str | None = None, profile: str | None = None):
109109
if profile and not B2_ACCOUNT_INFO_PROFILE_NAME_REGEXP.match(profile):
110110
raise ValueError(f'Invalid profile name: {profile}')
111111

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add SqliteAccountInfo.get_user_account_info_path to public API.

test/unit/account_info/test_sqlite_account_info.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ def setup(self, monkeypatch, tmpdir):
7777

7878
def test_invalid_profile_name(self):
7979
with pytest.raises(ValueError):
80-
SqliteAccountInfo._get_user_account_info_path(profile='&@(*$')
80+
SqliteAccountInfo.get_user_account_info_path(profile='&@(*$')
8181

8282
def test_profile_and_file_name_conflict(self):
8383
with pytest.raises(ValueError):
84-
SqliteAccountInfo._get_user_account_info_path(file_name='foo', profile='bar')
84+
SqliteAccountInfo.get_user_account_info_path(file_name='foo', profile='bar')
8585

8686
def test_profile_and_env_var_conflict(self, monkeypatch):
8787
monkeypatch.setenv(B2_ACCOUNT_INFO_ENV_VAR, 'foo')
8888
with pytest.raises(ValueError):
89-
SqliteAccountInfo._get_user_account_info_path(profile='bar')
89+
SqliteAccountInfo.get_user_account_info_path(profile='bar')
9090

9191
def test_profile_and_xdg_config_env_var(self, monkeypatch):
9292
monkeypatch.setenv(XDG_CONFIG_HOME_ENV_VAR, os.path.join('~', 'custom'))
93-
account_info_path = SqliteAccountInfo._get_user_account_info_path(profile='secondary')
93+
account_info_path = SqliteAccountInfo.get_user_account_info_path(profile='secondary')
9494
assert account_info_path == os.path.expanduser(
9595
os.path.join('~', 'custom', 'b2', 'db-secondary.sqlite')
9696
)
@@ -102,18 +102,18 @@ def test_profile(self, monkeypatch):
102102
else:
103103
expected_path = ('~', '.b2db-foo.sqlite')
104104

105-
account_info_path = SqliteAccountInfo._get_user_account_info_path(profile='foo')
105+
account_info_path = SqliteAccountInfo.get_user_account_info_path(profile='foo')
106106
assert account_info_path == os.path.expanduser(os.path.join(*expected_path))
107107

108108
def test_file_name(self):
109-
account_info_path = SqliteAccountInfo._get_user_account_info_path(
109+
account_info_path = SqliteAccountInfo.get_user_account_info_path(
110110
file_name=os.path.join('~', 'foo')
111111
)
112112
assert account_info_path == os.path.expanduser(os.path.join('~', 'foo'))
113113

114114
def test_env_var(self, monkeypatch):
115115
monkeypatch.setenv(B2_ACCOUNT_INFO_ENV_VAR, os.path.join('~', 'foo'))
116-
account_info_path = SqliteAccountInfo._get_user_account_info_path()
116+
account_info_path = SqliteAccountInfo.get_user_account_info_path()
117117
assert account_info_path == os.path.expanduser(os.path.join('~', 'foo'))
118118

119119
def test_default_file_if_exists(self, monkeypatch):
@@ -124,12 +124,12 @@ def test_default_file_if_exists(self, monkeypatch):
124124
os.makedirs(parent_dir, exist_ok=True)
125125
with open(account_file_path, 'w') as account_file:
126126
account_file.write('')
127-
account_info_path = SqliteAccountInfo._get_user_account_info_path()
127+
account_info_path = SqliteAccountInfo.get_user_account_info_path()
128128
assert account_info_path == os.path.expanduser(B2_ACCOUNT_INFO_DEFAULT_FILE)
129129

130130
def test_xdg_config_env_var(self, monkeypatch):
131131
monkeypatch.setenv(XDG_CONFIG_HOME_ENV_VAR, os.path.join('~', 'custom'))
132-
account_info_path = SqliteAccountInfo._get_user_account_info_path()
132+
account_info_path = SqliteAccountInfo.get_user_account_info_path()
133133
assert account_info_path == os.path.expanduser(
134134
os.path.join('~', 'custom', 'b2', 'account_info')
135135
)
@@ -141,5 +141,5 @@ def test_default_file(self):
141141
else:
142142
expected_path = B2_ACCOUNT_INFO_DEFAULT_FILE
143143

144-
account_info_path = SqliteAccountInfo._get_user_account_info_path()
144+
account_info_path = SqliteAccountInfo.get_user_account_info_path()
145145
assert account_info_path == os.path.expanduser(expected_path)

0 commit comments

Comments
 (0)