From 1017502ba4bfa740fd73812f11feea2e3476e71d Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 19 May 2008 00:42:52 -0300 Subject: [PATCH] Make magic methods of procman.ProcessManager aliases of normal methods. Add a simple testcase too. --- pymin/procman.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pymin/procman.py b/pymin/procman.py index 170d290..554fdba 100644 --- a/pymin/procman.py +++ b/pymin/procman.py @@ -185,6 +185,8 @@ class ProcessManager: if name in self.pidmap: return self.pidmap[name] raise KeyError, name + # Syntax sugar for self[name] + __getitem__ = get def has(self, name): if isinstance(name, basestring): # is a name @@ -196,12 +198,8 @@ class ProcessManager: if name in self.pidmap: return True return False - - def __getitem__(self, name): - return self.get(name) - - def __contains__(self, name): - return self.has(name) + # Syntax sugar for name in self + __contains__ = has if __name__ == '__main__': @@ -257,6 +255,9 @@ if __name__ == '__main__': assert 'test-service' in manager.services assert 'test-service' not in manager.namemap assert not get('test-service').running + assert manager['test-service'] == get('test-service') + assert has('test-service') + assert 'test-service' in manager register('test-service-2', ('sleep', '3'), notify, False) assert 'test-service-2' in manager.services -- 2.43.0