diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-08 21:40:03 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-08 21:40:03 +0000 |
commit | fdfa827a36df87fd6b228fc1560576e268413104 (patch) | |
tree | 62ddec353d8f08980f647b79a6a5b20b410a1e94 /ipalib/tests | |
parent | 58a3b1d0915f32326e9387bc4978c53a16e5f217 (diff) | |
download | freeipa-fdfa827a36df87fd6b228fc1560576e268413104.tar.gz freeipa-fdfa827a36df87fd6b228fc1560576e268413104.tar.xz freeipa-fdfa827a36df87fd6b228fc1560576e268413104.zip |
86: Actually change *all* tab indentation to 4-space: 'sed s/\t/ /g'
Diffstat (limited to 'ipalib/tests')
-rw-r--r-- | ipalib/tests/test_plugable.py | 240 | ||||
-rw-r--r-- | ipalib/tests/test_public.py | 156 | ||||
-rw-r--r-- | ipalib/tests/test_tstutil.py | 68 | ||||
-rw-r--r-- | ipalib/tests/tstutil.py | 14 |
4 files changed, 239 insertions, 239 deletions
diff --git a/ipalib/tests/test_plugable.py b/ipalib/tests/test_plugable.py index af6ee0c94..6a1d8a605 100644 --- a/ipalib/tests/test_plugable.py +++ b/ipalib/tests/test_plugable.py @@ -40,25 +40,25 @@ def test_from_cli(): def test_valid_identifier(): f = plugable.check_identifier okay = [ - 'user_add', - 'stuff2junk', - 'sixty9', + 'user_add', + 'stuff2junk', + 'sixty9', ] nope = [ - '_user_add', - '__user_add', - 'user_add_', - 'user_add__', - '_user_add_', - '__user_add__', - '60nine', + '_user_add', + '__user_add', + 'user_add_', + 'user_add__', + '_user_add_', + '__user_add__', + '60nine', ] for name in okay: - f(name) + f(name) for name in nope: - raises(errors.NameSpaceError, f, name) + raises(errors.NameSpaceError, f, name) for name in okay: - raises(errors.NameSpaceError, f, name.upper()) + raises(errors.NameSpaceError, f, name.upper()) def test_Abstract(): @@ -126,7 +126,7 @@ def test_Plugin(): raises(AssertionError, p.finalize, api) class some_plugin(plugable.Plugin): - pass + pass p = some_plugin() assert read_only(p, 'name') == 'some_plugin' assert repr(p) == '%s.some_plugin()' % __name__ @@ -142,17 +142,17 @@ def test_ReadOnly(): obj._lock() names = ['not_an_attribute', 'an_attribute'] for name in names: - no_set(obj, name) - no_del(obj, name) + no_set(obj, name) + no_del(obj, name) class some_ro_class(plugable.ReadOnly): - def __init__(self): - self.an_attribute = 'Hello world!' - self._lock() + def __init__(self): + self.an_attribute = 'Hello world!' + self._lock() obj = some_ro_class() for name in names: - no_set(obj, name) - no_del(obj, name) + no_set(obj, name) + no_del(obj, name) assert read_only(obj, 'an_attribute') == 'Hello world!' @@ -162,30 +162,30 @@ def test_Proxy(): # Setup: class base(object): - __public__ = frozenset(( - 'public_0', - 'public_1', - '__call__', - )) + __public__ = frozenset(( + 'public_0', + 'public_1', + '__call__', + )) - def public_0(self): - return 'public_0' + def public_0(self): + return 'public_0' - def public_1(self): - return 'public_1' + def public_1(self): + return 'public_1' - def __call__(self, caller): - return 'ya called it, %s.' % caller + def __call__(self, caller): + return 'ya called it, %s.' % caller - def private_0(self): - return 'private_0' + def private_0(self): + return 'private_0' - def private_1(self): - return 'private_1' + def private_1(self): + return 'private_1' class plugin(base): - name = 'user_add' - attr_name = 'add' + name = 'user_add' + attr_name = 'add' # Test that TypeError is raised when base is not a class: raises(TypeError, cls, base(), None) @@ -201,13 +201,13 @@ def test_Proxy(): # Test normal methods: for n in xrange(2): - pub = 'public_%d' % n - priv = 'private_%d' % n - assert getattr(i, pub)() == pub - assert getattr(p, pub)() == pub - assert hasattr(p, pub) - assert getattr(i, priv)() == priv - assert not hasattr(p, priv) + pub = 'public_%d' % n + priv = 'private_%d' % n + assert getattr(i, pub)() == pub + assert getattr(p, pub)() == pub + assert hasattr(p, pub) + assert getattr(i, priv)() == priv + assert not hasattr(p, priv) # Test __call__: value = 'ya called it, dude.' @@ -236,23 +236,23 @@ def test_NameSpace(): assert issubclass(cls, plugable.ReadOnly) class base(object): - __public__ = frozenset(( - 'plusplus', - )) + __public__ = frozenset(( + 'plusplus', + )) - def plusplus(self, n): - return n + 1 + def plusplus(self, n): + return n + 1 class plugin(base): - def __init__(self, name): - self.name = name + def __init__(self, name): + self.name = name def get_name(i): - return 'noun_verb%d' % i + return 'noun_verb%d' % i def get_proxies(n): - for i in xrange(n): - yield plugable.Proxy(base, plugin(get_name(i))) + for i in xrange(n): + yield plugable.Proxy(base, plugin(get_name(i))) cnt = 20 ns = cls(get_proxies(cnt)) @@ -263,20 +263,20 @@ def test_NameSpace(): # Test __iter__ i = None for (i, proxy) in enumerate(ns): - assert type(proxy) is plugable.Proxy - assert proxy.name == get_name(i) + assert type(proxy) is plugable.Proxy + assert proxy.name == get_name(i) assert i == cnt - 1 # Test __contains__, __getitem__, getattr(): proxies = frozenset(ns) for i in xrange(cnt): - name = get_name(i) - assert name in ns - proxy = ns[name] - assert proxy.name == name - assert type(proxy) is plugable.Proxy - assert proxy in proxies - assert read_only(ns, name) is proxy + name = get_name(i) + assert name in ns + proxy = ns[name] + assert proxy.name == name + assert type(proxy) is plugable.Proxy + assert proxy in proxies + assert read_only(ns, name) is proxy # Test dir(): assert set(get_name(i) for i in xrange(cnt)).issubset(set(dir(ns))) @@ -291,27 +291,27 @@ def test_NameSpace(): def test_Registrar(): class Base1(object): - pass + pass class Base2(object): - pass + pass class Base3(object): - pass + pass class plugin1(Base1): - pass + pass class plugin2(Base2): - pass + pass class plugin3(Base3): - pass + pass # Test creation of Registrar: r = plugable.Registrar(Base1, Base2) # Test __hasitem__, __getitem__: for base in [Base1, Base2]: - assert base in r - assert base.__name__ in r - assert r[base] == {} - assert r[base.__name__] == {} + assert base in r + assert base.__name__ in r + assert r[base] == {} + assert r[base.__name__] == {} # Check that TypeError is raised trying to register something that isn't @@ -339,9 +339,9 @@ def test_Registrar(): # name and same base: orig1 = plugin1 class base1_extended(Base1): - pass + pass class plugin1(base1_extended): - pass + pass raises(errors.OverrideError, r, plugin1) # Check that overriding works @@ -364,40 +364,40 @@ def test_Registrar(): # Setup to test __iter__: class plugin1a(Base1): - pass + pass r(plugin1a) class plugin1b(Base1): - pass + pass r(plugin1b) class plugin2a(Base2): - pass + pass r(plugin2a) class plugin2b(Base2): - pass + pass r(plugin2b) m = { - 'Base1': set([plugin1, plugin1a, plugin1b]), - 'Base2': set([plugin2, plugin2a, plugin2b]), + 'Base1': set([plugin1, plugin1a, plugin1b]), + 'Base2': set([plugin2, plugin2a, plugin2b]), } # Now test __iter__: for (base, plugins) in r: - assert base in [Base1, Base2] - assert set(plugins) == m[base.__name__] + assert base in [Base1, Base2] + assert set(plugins) == m[base.__name__] assert len(list(r)) == 2 # Again test __hasitem__, __getitem__: for base in [Base1, Base2]: - assert base in r - assert base.__name__ in r - d = dict((p.__name__, p) for p in m[base.__name__]) - assert len(d) == 3 - assert r[base] == d - assert r[base.__name__] == d + assert base in r + assert base.__name__ in r + d = dict((p.__name__, p) for p in m[base.__name__]) + assert len(d) == 3 + assert r[base] == d + assert r[base.__name__] == d def test_API(): @@ -405,20 +405,20 @@ def test_API(): # Setup the test bases, create the API: class base0(plugable.Plugin): - __public__ = frozenset(( - 'method', - )) + __public__ = frozenset(( + 'method', + )) - def method(self, n): - return n + def method(self, n): + return n class base1(plugable.Plugin): - __public__ = frozenset(( - 'method', - )) + __public__ = frozenset(( + 'method', + )) - def method(self, n): - return n + 1 + def method(self, n): + return n + 1 api = plugable.API(base0, base1) r = api.register @@ -426,48 +426,48 @@ def test_API(): assert read_only(api, 'register') is r class base0_plugin0(base0): - pass + pass r(base0_plugin0) class base0_plugin1(base0): - pass + pass r(base0_plugin1) class base0_plugin2(base0): - pass + pass r(base0_plugin2) class base1_plugin0(base1): - pass + pass r(base1_plugin0) class base1_plugin1(base1): - pass + pass r(base1_plugin1) class base1_plugin2(base1): - pass + pass r(base1_plugin2) # Test API instance: api() # Calling instance performs finalization def get_base(b): - return 'base%d' % b + return 'base%d' % b def get_plugin(b, p): - return 'base%d_plugin%d' % (b, p) + return 'base%d_plugin%d' % (b, p) for b in xrange(2): - base_name = get_base(b) - ns = getattr(api, base_name) - assert isinstance(ns, plugable.NameSpace) - assert read_only(api, base_name) is ns - assert len(ns) == 3 - for p in xrange(3): - plugin_name = get_plugin(b, p) - proxy = ns[plugin_name] - assert isinstance(proxy, plugable.Proxy) - assert proxy.name == plugin_name - assert read_only(ns, plugin_name) is proxy - assert read_only(proxy, 'method')(7) == 7 + b + base_name = get_base(b) + ns = getattr(api, base_name) + assert isinstance(ns, plugable.NameSpace) + assert read_only(api, base_name) is ns + assert len(ns) == 3 + for p in xrange(3): + plugin_name = get_plugin(b, p) + proxy = ns[plugin_name] + assert isinstance(proxy, plugable.Proxy) + assert proxy.name == plugin_name + assert read_only(ns, plugin_name) is proxy + assert read_only(proxy, 'method')(7) == 7 + b diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py index 49fbb17f2..6bff9d895 100644 --- a/ipalib/tests/test_public.py +++ b/ipalib/tests/test_public.py @@ -33,13 +33,13 @@ def test_rule(): flag = public.RULE_FLAG rule = public.rule def my_func(): - pass + pass assert not hasattr(my_func, flag) rule(my_func) assert getattr(my_func, flag) is True @rule def my_func2(): - pass + pass assert getattr(my_func2, flag) is True @@ -48,14 +48,14 @@ def test_is_rule(): flag = public.RULE_FLAG class no_call(object): - def __init__(self, value): - if value is not None: - assert value in (True, False) - setattr(self, flag, value) + def __init__(self, value): + if value is not None: + assert value in (True, False) + setattr(self, flag, value) class call(no_call): - def __call__(self): - pass + def __call__(self): + pass assert is_rule(call(True)) assert not is_rule(no_call(True)) @@ -90,81 +90,81 @@ class test_option(ClassChecker): _cls = public.option def get_subcls(self): - rule = public.rule - class int_opt(self.cls): - type = int - @rule - def rule_0(self, value): - if value == 0: - return 'cannot be 0' - @rule - def rule_1(self, value): - if value == 1: - return 'cannot be 1' - @rule - def rule_2(self, value): - if value == 2: - return 'cannot be 2' - return int_opt + rule = public.rule + class int_opt(self.cls): + type = int + @rule + def rule_0(self, value): + if value == 0: + return 'cannot be 0' + @rule + def rule_1(self, value): + if value == 1: + return 'cannot be 1' + @rule + def rule_2(self, value): + if value == 2: + return 'cannot be 2' + return int_opt def test_class(self): - """ - Perform some tests on the class (not an instance). - """ - #assert issubclass(cls, plugable.ReadOnly) - assert type(self.cls.rules) is property + """ + Perform some tests on the class (not an instance). + """ + #assert issubclass(cls, plugable.ReadOnly) + assert type(self.cls.rules) is property def test_normalize(self): assert 'normalize' in self.cls.__public__ - o = self.subcls() - # Test with values that can't be converted: - nope = ( - '7.0' - 'whatever', - object, - None, - ) - for val in nope: - e = raises(errors.NormalizationError, o.normalize, val) - assert isinstance(e, errors.ValidationError) - assert e.name == 'int_opt' - assert e.value == val - assert e.error == "not <type 'int'>" - assert e.type is int - # Test with values that can be converted: - okay = ( - 7, - 7.0, - 7.2, - 7L, - '7', - ' 7 ', - ) - for val in okay: - assert o.normalize(val) == 7 + o = self.subcls() + # Test with values that can't be converted: + nope = ( + '7.0' + 'whatever', + object, + None, + ) + for val in nope: + e = raises(errors.NormalizationError, o.normalize, val) + assert isinstance(e, errors.ValidationError) + assert e.name == 'int_opt' + assert e.value == val + assert e.error == "not <type 'int'>" + assert e.type is int + # Test with values that can be converted: + okay = ( + 7, + 7.0, + 7.2, + 7L, + '7', + ' 7 ', + ) + for val in okay: + assert o.normalize(val) == 7 def test_validate(self): - """ - Test the validate method. - """ - assert 'validate' in self.cls.__public__ - o = self.subcls() - o.validate(9) - for i in xrange(3): - e = raises(errors.RuleError, o.validate, i) - assert e.error == 'cannot be %d' % i - assert e.value == i + """ + Test the validate method. + """ + assert 'validate' in self.cls.__public__ + o = self.subcls() + o.validate(9) + for i in xrange(3): + e = raises(errors.RuleError, o.validate, i) + assert e.error == 'cannot be %d' % i + assert e.value == i def test_rules(self): - """ - Test the rules property. - """ - o = self.subcls() - assert len(o.rules) == 3 - def get_rule(i): - return getattr(o, 'rule_%d' % i) - rules = tuple(get_rule(i) for i in xrange(3)) - assert o.rules == rules + """ + Test the rules property. + """ + o = self.subcls() + assert len(o.rules) == 3 + def get_rule(i): + return getattr(o, 'rule_%d' % i) + rules = tuple(get_rule(i) for i in xrange(3)) + assert o.rules == rules def test_default(self): assert 'default' in self.cls.__public__ @@ -190,10 +190,10 @@ def test_attr(): assert issubclass(cls, plugable.Plugin) class api(object): - obj = dict(user='the user obj') + obj = dict(user='the user obj') class user_add(cls): - pass + pass i = user_add() assert read_only(i, 'obj_name') == 'user' @@ -222,11 +222,11 @@ def test_PublicAPI(): api = cls() class cmd1(public.cmd): - pass + pass api.register(cmd1) class cmd2(public.cmd): - pass + pass api.register(cmd2) api() diff --git a/ipalib/tests/test_tstutil.py b/ipalib/tests/test_tstutil.py index 76f819e4a..5916f9d24 100644 --- a/ipalib/tests/test_tstutil.py +++ b/ipalib/tests/test_tstutil.py @@ -26,23 +26,23 @@ import tstutil class Prop(object): def __init__(self, *ops): - self.__ops = frozenset(ops) - self.__prop = 'prop value' + self.__ops = frozenset(ops) + self.__prop = 'prop value' def __get_prop(self): - if 'get' not in self.__ops: - raise AttributeError('get prop') - return self.__prop + if 'get' not in self.__ops: + raise AttributeError('get prop') + return self.__prop def __set_prop(self, value): - if 'set' not in self.__ops: - raise AttributeError('set prop') - self.__prop = value + if 'set' not in self.__ops: + raise AttributeError('set prop') + self.__prop = value def __del_prop(self): - if 'del' not in self.__ops: - raise AttributeError('del prop') - self.__prop = None + if 'del' not in self.__ops: + raise AttributeError('del prop') + self.__prop = None prop = property(__get_prop, __set_prop, __del_prop) @@ -51,36 +51,36 @@ def test_yes_raised(): f = tstutil.raises class SomeError(Exception): - pass + pass class AnotherError(Exception): - pass + pass def callback1(): - 'raises correct exception' - raise SomeError() + 'raises correct exception' + raise SomeError() def callback2(): - 'raises wrong exception' - raise AnotherError() + 'raises wrong exception' + raise AnotherError() def callback3(): - 'raises no exception' + 'raises no exception' f(SomeError, callback1) raised = False try: - f(SomeError, callback2) + f(SomeError, callback2) except AnotherError: - raised = True + raised = True assert raised raised = False try: - f(SomeError, callback3) + f(SomeError, callback3) except tstutil.ExceptionNotRaised: - raised = True + raised = True assert raised @@ -91,9 +91,9 @@ def test_no_set(): # Tests that ExceptionNotRaised is raised when prop *can* be set: raised = False try: - tstutil.no_set(Prop('set'), 'prop') + tstutil.no_set(Prop('set'), 'prop') except tstutil.ExceptionNotRaised: - raised = True + raised = True assert raised @@ -104,9 +104,9 @@ def test_no_del(): # Tests that ExceptionNotRaised is raised when prop *can* be set: raised = False try: - tstutil.no_del(Prop('del'), 'prop') + tstutil.no_del(Prop('del'), 'prop') except tstutil.ExceptionNotRaised: - raised = True + raised = True assert raised @@ -117,32 +117,32 @@ def test_read_only(): # Test that ExceptionNotRaised is raised when prop can be set: raised = False try: - tstutil.read_only(Prop('get', 'set'), 'prop') + tstutil.read_only(Prop('get', 'set'), 'prop') except tstutil.ExceptionNotRaised: - raised = True + raised = True assert raised # Test that ExceptionNotRaised is raised when prop can be deleted: raised = False try: - tstutil.read_only(Prop('get', 'del'), 'prop') + tstutil.read_only(Prop('get', 'del'), 'prop') except tstutil.ExceptionNotRaised: - raised = True + raised = True assert raised # Test that ExceptionNotRaised is raised when prop can be both set and # deleted: raised = False try: - tstutil.read_only(Prop('get', 'del'), 'prop') + tstutil.read_only(Prop('get', 'del'), 'prop') except tstutil.ExceptionNotRaised: - raised = True + raised = True assert raised # Test that AttributeError is raised when prop can't be read: raised = False try: - tstutil.read_only(Prop(), 'prop') + tstutil.read_only(Prop(), 'prop') except AttributeError: - raised = True + raised = True assert raised diff --git a/ipalib/tests/tstutil.py b/ipalib/tests/tstutil.py index e34113663..63c75665c 100644 --- a/ipalib/tests/tstutil.py +++ b/ipalib/tests/tstutil.py @@ -29,10 +29,10 @@ class ExceptionNotRaised(Exception): msg = 'expected %s' def __init__(self, expected): - self.expected = expected + self.expected = expected def __str__(self): - return self.msg % self.expected.__name__ + return self.msg % self.expected.__name__ def raises(exception, callback, *args, **kw): @@ -42,11 +42,11 @@ def raises(exception, callback, *args, **kw): """ raised = False try: - callback(*args, **kw) + callback(*args, **kw) except exception, e: - raised = True + raised = True if not raised: - raise ExceptionNotRaised(exception) + raise ExceptionNotRaised(exception) return e @@ -93,7 +93,7 @@ def is_prop(prop): class ClassChecker(object): def new(self, *args, **kw): - return self.cls(*args, **kw) + return self.cls(*args, **kw) def get_sub(self): - raise NotImplementedError('get_sub()') + raise NotImplementedError('get_sub()') |