Files
dikte/tests/test_paths.py
T
yusufipek b186f7fde2 Merge master: the modules moved into a package
Every file this branch touches moved into dikte/, so the merge is mostly the
rename following the edits. What needed a hand:

hotkey.py: master replaced the _macos()/_gnome() pair with one backend()
chooser, and this branch had added _windows() to the pair. Windows is a fifth
value of the chooser now, and everything that used to ask "macOS or Windows?"
asks backend() instead. The key is held by the running process there, so
installs_shortcuts() and shortcut_needs_restart() are both false for it, and
desktop_name() says Windows.

install.ps1 and the Windows README name dikte/__main__.py, the entry point the
Linux and macOS installers were pointed at in the same commit. The Start Menu
entry, the autostart entry and the dikte.cmd shim all come off one $entry
variable.

settings_ui.py: the shortcut tab now has a Windows sentence of its own, with
the Turkish for it. Falling through to the branch master wrote for a desktop
with no registry would have told a Windows user to check /dev/input. Nothing
covers that branch: there is no Windows Settings test class, the way there is
one for macOS.

CONTRIBUTING: the chooser it names is backend() now, and the test count is the
merged one, 1067 of 1110 running anywhere.
2026-08-16 14:10:28 +03:00

84 lines
3.5 KiB
Python

"""Where the settings and the data are kept, per system.
Its own file because the answer has to be one answer: config.py and ggml.py
both need it, and when each worked it out for itself only one of them knew
about macOS.
"""
import os
import unittest
from unittest import mock
from dikte import config as cfg
from dikte import ggml
from dikte import paths
class Directories(unittest.TestCase):
"""Spelled with forward slashes throughout.
A backslash separates on Windows only, and every one of these runs on all
three systems: `as_posix()` is the one spelling they can all be read in.
"""
def test_linux_keeps_them_apart_and_follows_xdg(self):
with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/c",
"XDG_DATA_HOME": "/d"}):
config_dir, data_dir = paths.directories("linux")
self.assertEqual(config_dir.as_posix(), "/c/dikte")
self.assertEqual(data_dir.as_posix(), "/d/dikte")
def test_linux_without_the_variables_set(self):
with mock.patch.dict(os.environ, {}, clear=True):
config_dir, data_dir = paths.directories("linux")
self.assertTrue(config_dir.as_posix().endswith("/.config/dikte"))
self.assertTrue(data_dir.as_posix().endswith("/.local/share/dikte"))
def test_a_mac_keeps_both_in_application_support(self):
config_dir, data_dir = paths.directories("darwin")
self.assertEqual(config_dir, data_dir)
self.assertTrue(config_dir.as_posix()
.endswith("/Library/Application Support/Dikte"))
def test_a_mac_does_not_read_the_xdg_variables(self):
"""A Mac with them set from some other tool still stores in one place."""
with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/c"}):
config_dir, _ = paths.directories("darwin")
self.assertNotIn("/c", config_dir.as_posix())
def test_windows_keeps_the_models_out_of_the_roaming_profile(self):
"""Settings roam with the account; several gigabytes must not."""
with mock.patch.dict(os.environ, {"APPDATA": "C:/roam",
"LOCALAPPDATA": "C:/local"}):
config_dir, data_dir = paths.directories("win32")
self.assertEqual(config_dir.as_posix(), "C:/roam/Dikte")
self.assertEqual(data_dir.as_posix(), "C:/local/Dikte")
def test_windows_without_the_variables_set(self):
with mock.patch.dict(os.environ, {}, clear=True):
config_dir, data_dir = paths.directories("win32")
self.assertTrue(config_dir.as_posix().endswith("/AppData/Roaming/Dikte"))
self.assertTrue(data_dir.as_posix().endswith("/AppData/Local/Dikte"))
class OnePlace(unittest.TestCase):
"""The programs and the models go where everything else goes.
ggml.py used to read XDG_DATA_HOME itself, which is right on Linux and
wrong on a Mac: the settings and the dictations went to ~/Library while
several gigabytes of models went to ~/.local/share, where no Mac user looks
and where `uninstall.sh --purge` would never have found them.
"""
def test_the_models_live_under_the_data_directory(self):
self.assertEqual(ggml.DATA_DIR, paths.DATA_DIR)
self.assertEqual(ggml.MODELS_DIR.parent, paths.DATA_DIR)
self.assertEqual(ggml.BIN_DIR.parent, paths.DATA_DIR)
def test_config_and_ggml_cannot_disagree(self):
self.assertEqual(cfg.DATA_DIR, ggml.DATA_DIR)
if __name__ == "__main__":
unittest.main()