Files
glassMxrph/tests/glass_test.py
T
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

39 lines
2.7 KiB
Python

import importlib.util,os,tempfile,unittest
from pathlib import Path
from unittest.mock import patch
spec=importlib.util.spec_from_file_location('glass',Path(__file__).resolve().parents[1]/'quickshell/helpers/glass.py')
glass=importlib.util.module_from_spec(spec);spec.loader.exec_module(glass)
class GlassTests(unittest.TestCase):
def setUp(self):
self.options={'layers':True,'values':glass.GHOSTTY.copy()}
self.target=glass.values(self.options)
self.original={k:('liquid' if k=='default_preset' else 'auto' if k=='layers:mask_mode' else '' if isinstance(v,str) else 0) for k,v in self.target.items()}
self.original.update({'layers:namespaces':'other-shell','layers:exclude_namespaces':'wallpaper','layers:namespace_presets':'other-shell:subtle'})
self.state=self.original.copy()
def fake_put(self,key,value):self.state[key]=value
def test_apply_restore_preserves_other_rules(self):
with tempfile.TemporaryDirectory() as temp,patch.dict(os.environ,{'XDG_STATE_HOME':temp,'HYPRLAND_INSTANCE_SIGNATURE':'fixture'}),patch.object(glass,'get',lambda k:self.state[k]),patch.object(glass,'put',self.fake_put):
self.assertTrue(glass.dispatch({'action':'apply','options':self.options})['available'])
self.assertEqual(self.state['default_preset'],'default')
self.assertEqual(self.state['layers:namespaces'],'other-shell')
glass.dispatch({'action':'restore'})
self.assertEqual(self.state,self.original)
def test_restore_keeps_external_changes(self):
with tempfile.TemporaryDirectory() as temp,patch.dict(os.environ,{'XDG_STATE_HOME':temp,'HYPRLAND_INSTANCE_SIGNATURE':'fixture'}),patch.object(glass,'get',lambda k:self.state[k]),patch.object(glass,'put',self.fake_put):
glass.dispatch({'action':'apply','options':self.options})
self.state['default_preset']='external'
result=glass.dispatch({'action':'restore'})
self.assertEqual(self.state['default_preset'],'external');self.assertIn('default_preset',result['notice'])
def test_partial_failure_rolls_back(self):
def fail(key,value):
if key=='dark:brightness' and value!=self.original[key]:raise ValueError('fixture failure')
self.fake_put(key,value)
with tempfile.TemporaryDirectory() as temp,patch.dict(os.environ,{'XDG_STATE_HOME':temp,'HYPRLAND_INSTANCE_SIGNATURE':'fixture'}),patch.object(glass,'get',lambda k:self.state[k]),patch.object(glass,'put',fail):
with self.assertRaises(ValueError):glass.dispatch({'action':'apply','options':self.options})
self.assertEqual(self.state,self.original)
def test_validation_before_writes(self):
for value in [-1,99,'; bad',float('nan')]:
o={'layers':True,'values':dict(glass.GHOSTTY,blur_strength=value)}
with self.assertRaises(ValueError):glass.values(o)
if __name__=='__main__':unittest.main()