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>
67 lines
3.4 KiB
Python
67 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
import importlib.util
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
spec = importlib.util.spec_from_file_location('metrics', Path(__file__).resolve().parents[1] / 'quickshell/helpers/metrics.py')
|
|
m = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(m)
|
|
|
|
class MetricsTests(unittest.TestCase):
|
|
def test_cpu_guest_not_double_counted_and_resets(self):
|
|
self.assertEqual(m.cpu_counts('cpu 10 20 30 40 5 6 7 8 100 200'), (126,45))
|
|
self.assertIsNone(m.cpu_percent(None,(100,20)))
|
|
self.assertEqual(m.cpu_percent((100,20),(200,70)),50)
|
|
self.assertIsNone(m.cpu_percent((200,70),(100,20)))
|
|
self.assertIsNone(m.cpu_percent((100,20),(200,10)))
|
|
|
|
def test_ram_available_cache(self):
|
|
r=m.memory('MemTotal: 100 kB\nMemFree: 10 kB\nMemAvailable: 40 kB')
|
|
self.assertEqual(r['used'],60*1024)
|
|
self.assertEqual(r['percent'],60)
|
|
self.assertFalse(m.memory('MemTotal: 100 kB')['available'])
|
|
|
|
def test_network_time_reset_and_new_interface(self):
|
|
current=m.net_counts(' eth0: 100 0 0 0 0 0 0 0 200 0 0 0 0 0 0 0')
|
|
self.assertEqual(m.net_rates({'eth0':(50,100)},current,2)['eth0'],{'download':25,'upload':50})
|
|
self.assertEqual(m.net_rates({'eth0':(500,500)},current,2)['eth0'],{'download':0,'upload':0})
|
|
self.assertEqual(m.net_rates({},current,2),{})
|
|
self.assertEqual(m.net_rates(current,current,0),{})
|
|
|
|
def test_nvidia_partial_sensor_and_invalid_numbers(self):
|
|
result=m.nvidia_rows('GPU-1, NVIDIA Example, 30, 60, 1024, 8192, 1200, [N/A]\nGPU-2, Other, N/A, N/A, N/A, N/A, N/A, N/A')
|
|
self.assertEqual(len(result),2)
|
|
self.assertEqual(result[0]['used'],1024**3)
|
|
self.assertIsNone(result[0]['power'])
|
|
self.assertIsNone(result[1]['percent'])
|
|
for value in ['nan','inf','-1','N/A']:
|
|
self.assertIsNone(m.number(value))
|
|
|
|
def test_missing_sources_and_storage_path_failure(self):
|
|
with patch.object(m,'read',return_value=''),patch.object(m.shutil,'which',return_value=None):
|
|
c=m.Collector({'storagePaths':['/definitely/missing/glassmxrph']})
|
|
with patch.object(c,'gpu',return_value=[]):
|
|
result=c.sample()
|
|
self.assertIsNone(result['cpu']['percent'])
|
|
self.assertFalse(result['ram']['available'])
|
|
self.assertFalse(result['storage'][0]['available'])
|
|
self.assertTrue(result['warnings'])
|
|
|
|
def test_amd_units(self):
|
|
with tempfile.TemporaryDirectory() as temp:
|
|
base=Path(temp)/'card1/device';hw=base/'hwmon/hwmon1';hw.mkdir(parents=True)
|
|
for file,value in {'vendor':'0x1002','gpu_busy_percent':'25','mem_info_vram_used':'1024','mem_info_vram_total':'4096'}.items():
|
|
(base/file).write_text(value)
|
|
for file,value in {'temp1_input':'52000','freq1_input':'1500000000','power1_average':'23000000'}.items():
|
|
(hw/file).write_text(value)
|
|
c=m.Collector({});c.nvidia=None
|
|
original=m.Path.glob
|
|
def glob(p, pattern):
|
|
return iter([base]) if str(p)=='/sys/class/drm' else original(p,pattern)
|
|
with patch.object(m.Path,'glob',glob):
|
|
gpu=c.gpu()[0]
|
|
self.assertEqual((gpu['temperature'],gpu['frequency'],gpu['power']), (52,1500,23))
|
|
|
|
if __name__=='__main__':unittest.main()
|