diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2021-05-17 23:12:59 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2021-05-17 23:12:59 (GMT) |
commit | 73a09734a145722a3bd6199750fad62b46dd9339 (patch) | |
tree | 9e7e6d7a78d27cb5d6d6048ab02cddf4983f6f45 /tests/glibext | |
parent | a20cf5f374e64c6db50bf33545dc67804e90eabc (diff) |
Dead with singleton instances containing singleton instances.
Diffstat (limited to 'tests/glibext')
-rw-r--r-- | tests/glibext/singleton.py | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/tests/glibext/singleton.py b/tests/glibext/singleton.py index b0608f0..4588ae5 100644 --- a/tests/glibext/singleton.py +++ b/tests/glibext/singleton.py @@ -47,12 +47,15 @@ class TestSingleton(ChrysalideTestCase): super().__init__() self._val = val - def __eq__(self, other): - return self._val == other._val + def _list_inner_instances(self): + return () def __hash__(self): return hash('common-key') + def __eq__(self, other): + return self._val == other._val + val_0 = IntegerCacheImplem(0) val_0_bis = IntegerCacheImplem(0) val_1 = IntegerCacheImplem(1) @@ -70,24 +73,31 @@ class TestSingleton(ChrysalideTestCase): def testSingletonFootprint(self): """Check for singleton memory footprint.""" + sf = SingletonFactory() + + class IntegerCacheImplem(GObject.Object, SingletonCandidate): def __init__(self, val): super().__init__() self._val = val - def __eq__(self, other): - return self._val == other._val + def _list_inner_instances(self): + return () def __hash__(self): return hash('common-key') + def __eq__(self, other): + return self._val == other._val + + def _set_read_only(self): + pass + val_0 = IntegerCacheImplem(0) val_0_bis = IntegerCacheImplem(0) val_1 = IntegerCacheImplem(1) - sf = SingletonFactory() - obj = sf.get_instance(val_0) self.assertTrue(obj is val_0) @@ -99,3 +109,35 @@ class TestSingleton(ChrysalideTestCase): obj = sf.get_instance(val_1) self.assertTrue(obj is val_1) + + self.assertEqual(len(obj.inner_instances), 0) + + + class MasterCacheImplem(GObject.Object, SingletonCandidate): + + def __init__(self, children): + super().__init__() + self._children = children + + def _list_inner_instances(self): + return self._children + + def _update_inner_instances(self, instances): + self._children = instances + + def __hash__(self): + return hash('master-key') + + def __eq__(self, other): + return False + + def _set_read_only(self): + pass + + master = MasterCacheImplem(( val_0_bis, val_1 )) + + obj = sf.get_instance(master) + + self.assertTrue(obj.inner_instances[0] is val_0) + + self.assertTrue(obj.inner_instances[1] is val_1) |