Files
glassMxrph/tests/providers_test.py
mxandClaude Opus 5.5 99e64a7713 Add glassMxrph shell sources
Initial commit of the Quickshell desktop suite: bar, dock, launcher,
settings, Control Center, dashboard, OSD, lock screen, desktop widgets,
plugin host with the vendored Noctalia/Omarchy compatibility layer,
helpers, packaging, tests and phase documentation.

Includes the optimization work so far: usage widgets and dashboard
gauges no longer animate continuously, desktop widgets pause while
covered, system controls stop flickering on background polls, dock app
matching uses an indexed catalog, and workspace ghosts are created only
for occupied slots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 22:36:17 +02:00

23 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""Filesystem and argument safety checks; no real wallpaper service is modified."""
import importlib.util,json,subprocess,sys,tempfile,unittest
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
spec=importlib.util.spec_from_file_location('desktop',ROOT/'quickshell/helpers/desktop.py');desktop=importlib.util.module_from_spec(spec);spec.loader.exec_module(desktop)
class Providers(unittest.TestCase):
def test_scan_and_argument_boundaries(self):
with tempfile.TemporaryDirectory(prefix='glassmxrph-provider-') as directory:
root=Path(directory);image=root/"a ' quoted ; $(echo nope).png";image.write_bytes(b'fixture')
(root/'ignore.txt').write_text('no image')
result=desktop.scan({'directories':[directory,directory,str(root/'missing')]})
self.assertEqual(len(result['images']),1);self.assertIn('%20',result['images'][0]['url']);self.assertTrue(result['notice'])
record=root/'record.json';helper=root/'record.py';helper.write_text('import json,pathlib,sys\npathlib.Path(sys.argv[1]).write_text(json.dumps(sys.argv[2:]))\n')
result=desktop.apply({'backend':'custom','monitor':'TEST-1','path':str(image),'command':[sys.executable,str(helper),str(record),'{path}','{monitor}']})
self.assertEqual(json.loads(record.read_text()),[str(image),'TEST-1']);self.assertEqual(result['path'],str(image))
with self.assertRaises(ValueError):desktop.apply({'backend':'custom','monitor':'TEST-1','path':str(image),'command':['tool']})
with self.assertRaises(ValueError):desktop.apply({'backend':'custom','monitor':'bad; command','path':str(image),'command':[]})
def test_errors_are_json(self):
p=subprocess.run([sys.executable,str(ROOT/'quickshell/helpers/desktop.py'),json.dumps({'action':'palette','executable':'/missing/matugen','path':'/missing'})],capture_output=True,text=True,check=True)
self.assertFalse(json.loads(p.stdout)['ok']);self.assertEqual(p.stderr,'')
if __name__=='__main__':unittest.main()