Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion swanlab/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ def save_key(username: str, password: str, host: str = None) -> bool:
"""
if host is None:
host = get_host_api()
host = host.rstrip("/api")
host = host.rstrip()
if host.endswith("/api"):
host = host[:-4]
path = get_nrc_path()
if not os.path.exists(path):
with open(path, "w") as f:
Expand Down
12 changes: 12 additions & 0 deletions test/unit/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ def test_ok(self):
assert len(nrc.hosts) == 1
assert nrc.authenticators(new_host) is not None

def test_host(self):
"""
测试 host 的正确性
"""
path = os.path.join(get_save_dir(), ".netrc")
password = nanoid.generate()
host = "https://swanlab.ai/api"
P.save_key("user", password, host=host)
nrc = netrc.netrc(path)
assert len(nrc.hosts) == 1
assert nrc.authenticators("https://swanlab.ai") is not None

def test_duplicate(self):
"""
测试重复保存,此时会略过保存,因此不会改变文件的修改时间
Expand Down