Add tests
This commit is contained in:
29
tests/test_config_utils.py
Normal file
29
tests/test_config_utils.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import unittest
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from hysteria_panel import utils
|
||||
|
||||
|
||||
class TestConfigUtils(unittest.TestCase):
|
||||
def test_save_load_clear_config(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
temp_dir = Path(td)
|
||||
temp_file = temp_dir / "config.json"
|
||||
|
||||
with patch.object(utils, 'CONFIG_DIR', temp_dir), patch.object(utils, 'CONFIG_FILE', temp_file):
|
||||
data = {"host": "127.0.0.1", "port": 9999, "secret": "abc", "https": True}
|
||||
utils.save_config(data)
|
||||
self.assertTrue(temp_file.exists())
|
||||
|
||||
loaded = utils.load_config()
|
||||
self.assertEqual(loaded, data)
|
||||
|
||||
utils.clear_config()
|
||||
self.assertFalse(temp_file.exists())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user