| 1 | import json |
| 2 | import os |
| 3 | import sys |
| 4 | import tempfile |
| 5 | import unittest |
| 6 | |
| 7 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 8 | |
| 9 | from prefs import load |
| 10 | |
| 11 | |
| 12 | class TestPrefs(unittest.TestCase): |
| 13 | def test_existing_file(self): |
| 14 | with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f: |
| 15 | json.dump({"theme": "dark"}, f) |
| 16 | path = f.name |
| 17 | self.assertEqual(load(path), {"theme": "dark"}) |
| 18 | |
| 19 | def test_missing_file_means_empty(self): |
| 20 | self.assertEqual(load(os.path.join(tempfile.mkdtemp(), "nope.json")), {}) |
| 21 | |
| 22 | |
| 23 | if __name__ == "__main__": |
| 24 | unittest.main() |
| 25 |