From 422ee290fa33c6b17db748dcbe136bd88a764371 Mon Sep 17 00:00:00 2001 From: Hugo Bastien Date: Wed, 12 Mar 2014 18:19:45 -0400 Subject: [PATCH] Restoring original __getattr__ behaviour --- delegator/delegator.py | 6 +++++- test/tests_delegator.py | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/delegator/delegator.py b/delegator/delegator.py index 9ea3ce8..d099243 100644 --- a/delegator/delegator.py +++ b/delegator/delegator.py @@ -24,7 +24,11 @@ def _missing(*args, **kwargs): else: _missing = getattr(target, name) - return _missing + return _missing + + raise AttributeError("'{0}' object has no attribute '{1}'".format( + self.__getobj__().__class__.__name__, name + )) def __setobj__(self, obj): raise NotImplementedError("need to define `__setobj__'") diff --git a/test/tests_delegator.py b/test/tests_delegator.py index 97fa4fb..230523a 100644 --- a/test/tests_delegator.py +++ b/test/tests_delegator.py @@ -68,3 +68,10 @@ def test_can_exec_callables_on_delegated_model(self): def test_can_exec_callables_on_itself(self): self.assertEqual(self.model_proxy.define(), "First Name, is a Person.") + + def test_raises_no_method_found_error_as_expected(self): + with self.assertRaisesRegexp( + AttributeError, + r"'FrameworkObject' object has no attribute 'this_does_not_exists'" + ): + self.model_proxy.this_does_not_exists()