Something went wrong. Try again.
A Material 3 inspired desktop shell for Niri and Hyprland created with Ignis.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204from __future__ import annotations
import copyimport sysimport unittestfrom pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from core.settings_schema import ( SettingsSchemaError, build_options_classes, defaults_dict, expand_widget_fields, iter_field_paths, load_schema_documents, merge_documents, parse_document,)
class SchemaVersionTests(unittest.TestCase): def test_rejects_unknown_version(self): with self.assertRaises(SettingsSchemaError): parse_document({"version": 2, "groups": {}}, "x")
class WidgetFieldsTests(unittest.TestCase): def test_expands_bar_widgets(self): node = { "widget_fields": "bar_widgets", "type": "int", "defaults": {"a": 1, "b": 2}, "__bar_widgets": ["a", "b"], } expanded = expand_widget_fields("location", node, "interface.modules.location") self.assertEqual(set(expanded["fields"]), {"a", "b"}) self.assertEqual(expanded["fields"]["a"]["default"], 1)
def test_rejects_missing_default(self): node = { "widget_fields": "bar_widgets", "type": "int", "defaults": {"a": 1}, "__bar_widgets": ["a", "b"], } with self.assertRaises(SettingsSchemaError) as ctx: expand_widget_fields("location", node, "interface.modules.location") self.assertIn("missing", str(ctx.exception))
def test_rejects_extra_default(self): node = { "widget_fields": "bar_widgets", "type": "int", "defaults": {"a": 1, "b": 2, "c": 3}, "__bar_widgets": ["a", "b"], } with self.assertRaises(SettingsSchemaError) as ctx: expand_widget_fields("location", node, "interface.modules.location") self.assertIn("extra", str(ctx.exception))
class MergeTests(unittest.TestCase): def test_allows_different_children_of_same_container(self): core = { "version": 1, "groups": {"services": {"groups": {"recorder": {"fields": {"a": {"type": "bool", "default": True}}}}}}, } osd = { "version": 1, "groups": {"services": {"groups": {"osd": {"fields": {"b": {"type": "bool", "default": False}}}}}}, } root = merge_documents([("core", core), ("osd", osd)]) d = defaults_dict(root) self.assertEqual(d["services"]["recorder"]["a"], True) self.assertEqual(d["services"]["osd"]["b"], False)
def test_rejects_duplicate_group_ownership(self): a = { "version": 1, "groups": {"services": {"groups": {"osd": {"fields": {"x": {"type": "bool", "default": True}}}}}}, } b = copy.deepcopy(a) with self.assertRaises(SettingsSchemaError): merge_documents([("a", a), ("b", b)])
class RealSchemaParityTests(unittest.TestCase): @classmethod def setUpClass(cls): repo = Path(__file__).resolve().parents[2] cls.root = load_schema_documents( repo / "ignis" / "core" / "settings.json", [("osd", repo / "ignis" / "modules" / "osd" / "settings.json")], )
def test_defaults_from_source_of_truth(self): d = defaults_dict(self.root) self.assertEqual(d["appearance"]["wallcolors"]["wallpaper_path"], "") self.assertEqual(d["appearance"]["wallcolors"]["color_scheme"], "tonal_spot") self.assertEqual(d["appearance"]["wallcolors"]["dark_mode"], True) self.assertEqual(d["appearance"]["wallcolors"]["auto_dark"]["start_hour"], 22) self.assertEqual(d["interface"]["bar"]["side"], "bottom") self.assertEqual(d["interface"]["bar2"]["enabled"], True) self.assertEqual(d["interface"]["bar2"]["side"], "top") self.assertEqual(d["interface"]["notifications"]["anchor"], ["top", "right"]) self.assertEqual(d["interface"]["misc"]["screen_corners"], "not_fullscreen") self.assertEqual(d["interface"]["modules"]["location"]["workspaces"], 1) self.assertEqual(d["interface"]["modules"]["visibility"]["launcher"], False) self.assertEqual(d["interface"]["modules"]["bar_id"]["clock"], 0) self.assertEqual(d["interface"]["modules"]["options"]["fixed_workspaces_amount"], 5) self.assertEqual(d["services"]["recorder"]["record_audio"], True) self.assertEqual(d["services"]["osd"]["anchor"], ["bottom", "right"]) self.assertEqual(d["services"]["osd"]["vertical"], False)
def test_expected_path_exists(self): paths = set(iter_field_paths(self.root)) self.assertIn("appearance.wallcolors.wallpaper_path", paths) self.assertIn("appearance.wallcolors.auto_dark.start_hour", paths) self.assertIn("interface.modules.location.launcher", paths) self.assertIn("interface.modules.bar_id.clock", paths) self.assertIn("interface.bar2.enabled", paths) self.assertIn("services.recorder.record_audio", paths) self.assertIn("services.osd.anchor", paths)
def test_bar_widgets_data_present(self): modules = self.root.groups["interface"].groups["modules"] self.assertEqual( modules.bar_widgets, ( "launcher", "window_info", "media", "workspaces", "tasks", "recording_indicator", "systeminfotray", "clock", ), )
def test_list_defaults_are_copied(self): a = defaults_dict(self.root) b = defaults_dict(self.root) a["services"]["osd"]["anchor"].append("x") self.assertEqual(b["services"]["osd"]["anchor"], ["bottom", "right"])
class FakeBase: _instance = None
def __new__(cls, *args, **kwargs): if cls._instance is None: cls._instance = super().__new__(cls) return cls._instance
def __init__(self): pass
class BuilderTests(unittest.TestCase): @classmethod def setUpClass(cls): repo = Path(__file__).resolve().parents[2] cls.root = load_schema_documents( repo / "ignis" / "core" / "settings.json", [("osd", repo / "ignis" / "modules" / "osd" / "settings.json")], ) cls.user_cls = build_options_classes(cls.root, FakeBase)
def test_deterministic_class_names_and_nesting(self): self.assertEqual(self.user_cls.__name__, "UserSettings") self.assertEqual(type(self.user_cls.appearance).__name__, "Appearance") self.assertEqual(type(self.user_cls.appearance.wallcolors).__name__, "Appearance_Wallcolors") self.assertEqual(type(self.user_cls.interface.bar).__name__, "Interface_Bar") self.assertEqual(type(self.user_cls.services.osd).__name__, "Services_Osd")
def test_attribute_names_match_legacy(self): self.assertTrue(hasattr(self.user_cls.appearance.wallcolors, "wallpaper_path")) self.assertTrue(hasattr(self.user_cls.appearance.wallcolors.auto_dark, "start_hour")) self.assertTrue(hasattr(self.user_cls.interface.modules.bar_id, "launcher")) self.assertTrue(hasattr(self.user_cls.interface.bar2, "enabled")) self.assertEqual(self.user_cls.interface.misc.screen_corners, "not_fullscreen")
def test_subclass_singletons_are_isolated(self): self.assertIn("_instance", self.user_cls.__dict__) self.assertIn("_instance", type(self.user_cls.interface.bar).__dict__) self.assertIn("_instance", type(self.user_cls.interface.bar2).__dict__) self.assertIsNot(type(self.user_cls.interface.bar), type(self.user_cls.interface.bar2))
def test_list_defaults_are_not_shared_across_generated_classes(self): root = load_schema_documents( Path(__file__).resolve().parents[2] / "ignis" / "core" / "settings.json", [("osd", Path(__file__).resolve().parents[2] / "ignis" / "modules" / "osd" / "settings.json")], ) cls_a = build_options_classes(root, type("BaseA", (FakeBase,), {"_instance": None})) cls_b = build_options_classes(root, type("BaseB", (FakeBase,), {"_instance": None})) cls_a.services.osd.anchor.append("x") self.assertEqual(cls_b.services.osd.anchor, ["bottom", "right"])
if __name__ == "__main__": unittest.main()