From c2df39156979ea5a01901b97504c1de276364dfc Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Sun, 20 Jul 2008 03:48:36 +0000 Subject: [PATCH] 14: Added Named.cli property that returns name.replace('_', '-'); Named.doc property now does a strip() to make it more user-friendly; added test_Named unit tests which somehow got dropped, uppdated with new Named properties --- ipalib/base.py | 6 +++++- ipalib/tests/test_base.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ipalib/base.py b/ipalib/base.py index 2769efd3b..ece446cff 100644 --- a/ipalib/base.py +++ b/ipalib/base.py @@ -132,8 +132,12 @@ class Named(object): return self.__class__.__name__ name = property(__get_name) + def __get_cli(self): + return self.name.replace('_', '-') + cli = property(__get_cli) + def __get_doc(self): - return self.__class__.__doc__ + return self.__class__.__doc__.strip() doc = property(__get_doc) diff --git a/ipalib/tests/test_base.py b/ipalib/tests/test_base.py index 818b7713a..0dfd3438f 100644 --- a/ipalib/tests/test_base.py +++ b/ipalib/tests/test_base.py @@ -183,6 +183,17 @@ class test_NameSpace: assert len(kw) == len(ns) == 3 +def test_Named(): + class named_class(base.Named): + """ + This class is so introspective! + """ + i = named_class() + assert i.name == 'named_class' + assert i.cli == 'named-class' + assert i.doc == 'This class is so introspective!' + + def test_Command(): class user(object): name = 'user'