Skip to content

Commit

Permalink
test Respository.save_config for posix paths on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisvang committed Jun 11, 2024
1 parent 42407b0 commit b8f01ab
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/test_repo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import tarfile
import unittest
from datetime import date, datetime, timedelta
import json
import logging
Expand Down Expand Up @@ -37,7 +38,7 @@
SUFFIX_PUB,
SUFFIX_PATCH,
)

from tufup.utils.platform_specific import ON_WINDOWS

mock_input = Mock(return_value='')

Expand Down Expand Up @@ -545,6 +546,22 @@ def test_save_config(self):
# note Path.is_relative_to() is introduced in python 3.9
self.assertFalse(pathlib.Path(config_dict[key]).is_absolute())

@unittest.skipUnless(condition=ON_WINDOWS, reason='windows only')
def test_save_config_windows_paths(self):
# prepare
kwargs = dict(repo_dir='foo\\repo', keys_dir='bar\\keys')
repo = Repository(app_name='test', **kwargs)
# test
repo.save_config()
self.assertTrue(repo.get_config_file_path().exists())
config_text = repo.get_config_file_path().read_text()
print(config_text)
config = json.loads(repo.get_config_file_path().read_text())
for key in kwargs.keys():
with self.subTest(msg=key):
self.assertEqual(kwargs[key].replace('\\', '/'), config[key])


def test_load_config(self):
# file does not exist
self.assertEqual(dict(), Repository.load_config())
Expand Down

0 comments on commit b8f01ab

Please sign in to comment.