From 5ed655011b52a63bd7330d00c4b0e0da22330fb4 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 11 Oct 2013 17:00:20 +0300 Subject: [PATCH 01/46] Started implementing argspec validation. See #1 for details. --- .noseids | Bin 5773 -> 6142 bytes testdoubles/fakes/callables.py | 11 ++++++++++- tests/functional/fakes/test_fake_callable.py | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.noseids b/.noseids index cf87ab472c01d14d2a865ecb09d47446d628b47b..128435ac80a894ac43df95d24dc7050458f819a6 100644 GIT binary patch delta 808 zcmYk1%}Z2a6vov%ug=^%-ye?i>8talNk(o&u@8-edNL5AUJ!ywZ=C_1apvApTS!u? z7C~@=T1Z8;im>?$qNNc12}P^6wP+Cp(e*0f>hPTBd47lU=;Ys1o%5dV*F5Vf@OmuE z-=ida@T&L6HhJDkL_OE5t8GrjN^+%PTC(1-z7P~COa%iaqjjF5WZs^Pu`5kXkJ zb=6*NEV)dy^x^!A$TA-@Hg5?j|RB!ASg1&iZFu zy{})=lIZ6}-;|@5!~l}&vBQOvyriWtz|HWK!!r1X;p2Th!X00pKl(FT8Y%wjXDx%Y zGZ*+nSm#fH8IeUsJ#z^+f{P-Dtjn9^?NHoh=8 z1gV}ljKh|SEb!IXS-u_Z=iMHi-^HZ9TH7$21q`cACsyH3chs@xv?2<;7~2sg6y2u} zolyLmD5Ip*Q8vWS<7H7nS+$%^j=y-4ycgFw7|U=cku=P$nq@afP*J-_{t(|!+`2c~ zR-&t`%Qh|BYM$6`j*ZX|1}TI91>vVMij+Z$B=V%8n?_J3KXfwSBOP8!AxXoK_9x7mn0x;U`@qfMJ^AP|5 delta 684 zcmZXR%WD%+6vmUz+$8hLOdgYD@|?VyDp*s5`k+cgP|1fxyQmkzpbO=I8%r8|Krtc+ z3Kii5bWy>DZngh|e}MXzxNskxgfxg<-FtuEJ>PfkJ(H7rCk{Gl_#t0Z>)gv!c^qjA z4KX>IlPq_I&Q`Re=+O9j^ph~4%fUiD6+16X81l)2e2rZa7EJkKLDsZuN*oqH*A9e@ zxO~Mw-4^?%!+&&_Uq^KAnWq&8Hjk2L1J+j(aQKcf<~4nT+vXO3o2_opi@}}n1-@-e zxyxUSZusp#ZU#@RO@3)^1TNFP#vkKd_ANEM_unmz&)Jtn4q16r`4K1{a`OF=n)}WT zk%uP_GYdR%HhE;LeAhS=bQEMdL1yBLD59`%F7Rryr<70(-uF(FQIg}ibAkJ*Em1*P zJ`Kn^|4LmIJ}UCj{N(W)H_xBbNl}F_Kg{T^`aslBomUK9kN1~!cHO3^qc;27bsoAm zl?Lkk-R&z)G`O94ESAxf`+-9#nDcb1N&cO=^{h3NA`}Yk+#Bo+wpVtykF8K1IjW#U zDwaq`jH;+m12u|3r5GZVghOQ%DFK^2WT^(99K Date: Sat, 12 Oct 2013 15:26:08 +0300 Subject: [PATCH 02/46] Moved are_argspecs_identical to the utils module. --- .noseids | Bin 6142 -> 6142 bytes testdoubles/fakes/callables.py | 3 --- testdoubles/utils.py | 5 +++++ tests/unit/utils/__init__.py | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 testdoubles/utils.py create mode 100644 tests/unit/utils/__init__.py diff --git a/.noseids b/.noseids index 128435ac80a894ac43df95d24dc7050458f819a6..c5ec169b185318992d04815903e0ae7680d9c280 100644 GIT binary patch delta 830 zcmZvaO=}ZT6o!-B+$1xZB$Js;zQ4a~p{)v)7NixWN?xQ|pjuecQU-=)7fzvLZHT*))b%UVLpy%yc_KZKhivrd?F>9>XoZ#aoNc6 zm^Cj0D5~dt#b4w3WQxygH)Rkpwd2+l&VD-5;$O*oB81j}x-2zVYICURNS!0WS*ate zUJTf#+uh-p0iEZKOCpT8tG&iwjXT1C!*9iB89_j851lOAiz13L-w$ug7;N>yr7!Vx zOlKo7BTZ;$VgP~q*sgv>%8dOFSERI?y*NDavD+jKV)zb^79@RoKc3ozC0nag$GiY&sf4hNps zLV9SkAN4B(vta=TZ zwa!u;j@l4AcvT+LqLx5h%;2V$MB>P_WE3{!y8|tSq;&1ea-VKe8Y%TkX6!jP>GIQ< zrwr2SjoULP*W=-%_NLr%GL%JTyy0-NA3G;SZ=7<-s+SZ0w|AcM$W6#KDj=`kP3C(6 zUDhKDR7AnuGGpV!h7yY7Yasiv1uCQD_WX6+R&5Gp_v*J)!Iat@)4jkFRZ&q--S*bT zMMsv5luYYgs-dbL{fBc@N9~_=TWg^1KFMopqM_8GWlBEWq!yZL%>_mIRF}T@ zyw*lb_I=yWIzvV7CmgKw2mRiuQSWq{D=4#xD8~@tChD9=mZwl+4PI`e$r0#mAj~>K zoJE?em|{PCoPfhY5I0cc5(*qfkO>->QRE`>+(Ls>NN@o;j>G0Ol6 Date: Sat, 12 Oct 2013 15:49:41 +0300 Subject: [PATCH 03/46] Renamed test's function name. --- tests/functional/fakes/test_fake_callable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/fakes/test_fake_callable.py b/tests/functional/fakes/test_fake_callable.py index fc37f5a..cae599e 100644 --- a/tests/functional/fakes/test_fake_callable.py +++ b/tests/functional/fakes/test_fake_callable.py @@ -21,7 +21,7 @@ def foo(): pass FakeCallable(foo, inspect_args=True) @it.should("not raise a ValueError when arguments inspection is opted out.") - def test_should_not_raise_a_ValueError_when_the_provided_live_object_does_not_match_the_argspec(case): + def test_should_not_raise_a_ValueError_when_argument_inspection_is_opted_out(case): def foo(): pass try: From 265106e609005ff97fba01249f9ae0edcbd72f91 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sat, 12 Oct 2013 18:02:46 +0300 Subject: [PATCH 04/46] Fake callables now optionally inspect the arguments of the live object and the fake object to verify that they match. Closes #1. --- .noseids | Bin 6142 -> 7007 bytes testdoubles/__init__.py | 4 ++ testdoubles/fakes/callables.py | 10 +-- testdoubles/utils.py | 11 +++- tests/unit/fakes/test_fake_callable.py | 58 ++++++++++++++++++ .../unit/utils/test_are_argspecs_identical.py | 30 +++++++++ 6 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 tests/unit/utils/test_are_argspecs_identical.py diff --git a/.noseids b/.noseids index c5ec169b185318992d04815903e0ae7680d9c280..42ffcdd9b01a536406f61e61a1f4deed3a94ea08 100644 GIT binary patch delta 1235 zcmb`GTW=dx5XWP$k1y-ndVP;C*~IrGb%2M0DpjbVN)`QyxJhtcLK5OlXOUya-gQfn zDk>rIR@yL?;Drj1fPz%ox4zMDfXWvDz5yQq39;TbCNI44a2{sPoSFH}{LkNOzn{IG z_kGK$K#h;WWlm^y?gTf4f}ngb^KR!H5kOd8b3NzyxAZGQAR#~YtQ-C<5kyjcHH%JY zrV>Jc-w1d3uF_!37v=NXStX1#Cqs9X2(rAE`dp}3lvg0I~iC`cj8!myE}F4?2S$LT(*zQeS631nFGh#-|KfT7#GHu zCx@CmvpyS|LujovtUXt-Itu)gV-{cFZ7&nS)*kK$KE0;-fx z`%H2v(iBN7%bWas3jCLELufGMy;JaY?&_N&1tCB6VxA-}2^|aaN0037q_dfZCO`W> zsMyL?_!lL}gHZfGfqK@#fjM@kG0H%9mvT#F(Q*4vh1U7?^lKuA^2~~OM0u3t{Tb2s z*|8`cD=9i2VzrHkdY5(B_C-Mr3ydqst=R}_?{_A z9J@Ix{HH(9_v0$tzL&%jR^(69mQI@8ec_y8({R%78H1r?Sc9oz9K#{gUA`wDV|d`1 zed~&84BvZydVQ75!Svo!(#a#s6_RBe!z0J+8N-P)s-fj!OlKM4Cy5ui;!BG<=H=}f z^3xB{&84*ud>pT!D z{}J5~D=5hCPVu%l>Hg#|bH(D}p0iJ;eVTN%il)5d)p{J{figfTyK5UMSda` zSC>}L9<5y;J=cbh7T~8U6e=J~SZ(VqVq;oku_6kt z>_V(p#D!=P1YL;5l?z?F5&wejU34p=;&hC!<^AqC=R5b@`*G`!p*y+20v|D&{3&no z7d^|XL7jJ)u0Az>ezGl4S4&M$>%yAh-)7RY1?-EC)220)W84J43r>$L5hoNqHtlc~> zAPuB^^frE6F!+5+=f&ihj3J|*daODx$140GSY5ihU&awu_dMbnbX=Hl+0Bpe4{<^! zkXBE8_~G~{&!`UYb$NPXa>AYJ%$&V6-I{4{NwwVdw-(bG=^&(5{x~)borko@UE%WEXkJzj{FAlK5549{VoTB;pFP*P zFgbH+uI-|tp8ca&^``nyp$h58`FmRsHQ3%|jIa}1Q`|4>D5@*|Fs}o9L<45Gdz@uv zCGesvep@yn)JwlwTUoN8d-rot4j`)LeD)J_`}IM@J4*EQ^h{68wbxy1uOC2wG6+%y zf|>}C14&hcDUJyBBT56%C<&d4Fi1y?3W(DnOllxO5hSUM6dABcLz)t>sfG;2kfj`Q zR6?FYC{Q1YR7Z*O*xXBLl&KdEg;60FE}5v3jT&W9CxHf~&_@>fNuo*7PG{3kk7oFo diff --git a/testdoubles/__init__.py b/testdoubles/__init__.py index 2a664dd..18932f7 100644 --- a/testdoubles/__init__.py +++ b/testdoubles/__init__.py @@ -109,3 +109,7 @@ def default_implementation(*args, **kwargs): obj = type(obj.__name__, obj.__bases__, attrs) return substitute(obj, qualified_name, spec) + +from testdoubles import utils + +__all__ = ('fake', 'utils') \ No newline at end of file diff --git a/testdoubles/fakes/callables.py b/testdoubles/fakes/callables.py index 64fefcc..1a11f10 100644 --- a/testdoubles/fakes/callables.py +++ b/testdoubles/fakes/callables.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import inspect import sys +from testdoubles.utils import are_argspecs_identical python3 = sys.version_info[0] == 3 @@ -36,13 +37,12 @@ def __init__(self, live, inspect_args=False): except AttributeError: raise TypeError('The provided object is not callable.') + self._live = live + if inspect_args: - live_args_spec = inspect.getargspec(live) - fake_args_spec = inspect.getargspec(self.__call__) - if live_args_spec != fake_args_spec: - raise ValueError("The provided live object's arguments %s does not match %s" % (live_args_spec, fake_args_spec)) + if not are_argspecs_identical(self.live, self.fake): + raise ValueError("The provided live object's arguments %s does not match %s" % (inspect.getargspec(self.live), inspect.getargspec(self.fake))) - self._live = live @property def live(self): diff --git a/testdoubles/utils.py b/testdoubles/utils.py index a822603..4c82165 100644 --- a/testdoubles/utils.py +++ b/testdoubles/utils.py @@ -1,5 +1,12 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import inspect -def are_argspecs_identical(argspec1, argspec2): - return argspec1 == argspec2 \ No newline at end of file + +def are_argspecs_identical(callable1, callable2): + argspec1 = inspect.getargspec(callable1) + argspec2 = inspect.getargspec(callable2) + + return argspec1 == argspec2 + +__all__ = ('are_argspecs_identical', ) \ No newline at end of file diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 6981d2b..d53000e 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -35,6 +35,64 @@ def test_should_be_callable(case): it.createTests(globals()) +with such.A("Fake Function's initialization method") as it: + it.uses(UnitTestsLayer) + + @it.has_test_setup + def setup(case): + try: + case.old_callable = __builtins__['callable'] + __builtins__['callable'] = lambda c: True + except TypeError: + case.old_callable = __builtins__.callable + __builtins__.callable = lambda c: True + + @it.has_test_teardown + def teardown(case): + try: + __builtins__['callable'] = case.old_callable + except TypeError: + __builtins__.callable = case.old_callable + + @it.should("raise a ValueError when the provided live object does not match the argspec") + def test_should_raise_a_ValueError_when_the_provided_live_object_does_not_match_the_argspec(case): + with case.assertRaisesRegexp(ValueError, r"The provided live object's arguments ArgSpec\((?:[a-zA-Z1-9_]+=.+(?:, |(?=\))))+\) does not match ArgSpec\((?:[a-zA-Z1-9_]+=.+(?:, |(?=\))))+\)"): + old_init_globals = callables.FakeCallable.__init__.__globals__ + callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = lambda _, __: False + + with mock.patch('inspect.getargspec', return_value='ArgSpec(a=None)'): + callables.FakeCallable(mock.DEFAULT, inspect_args=True) + + callables.FakeCallable.__init__.__globals__.update(old_init_globals) + + @it.should("not raise a ValueError when the provided live object matches the argspec") + def test_should_not_raise_a_ValueError_when_the_provided_live_object_matches_the_argspec(case): + old_init_globals = callables.FakeCallable.__init__.__globals__ + callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = lambda _, __: True + + try: + callables.FakeCallable(mock.DEFAULT, inspect_args=True) + except ValueError: + case.fail() + + callables.FakeCallable.__init__.__globals__.update(old_init_globals) + + @it.should("not inspect the argspec of the live object when argument inspection is opted out") + def test_should_not_inspect_the_argspec_of_the_live_object_when_argument_inspection_is_opted_out(case): + old_init_globals = callables.FakeCallable.__init__.__globals__ + mocked_are_argspecs_identical = mock.Mock() + callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = mock.Mock() + + try: + callables.FakeCallable(mock.DEFAULT, inspect_args=False) + except ValueError: + pass + + mocked_are_argspecs_identical.assert_has_calls([]) + callables.FakeCallable.__init__.__globals__.update(old_init_globals) + + it.createTests(globals()) + with such.A("Fake Function's live property") as it: it.uses(UnitTestsLayer) diff --git a/tests/unit/utils/test_are_argspecs_identical.py b/tests/unit/utils/test_are_argspecs_identical.py new file mode 100644 index 0000000..ce5b8dd --- /dev/null +++ b/tests/unit/utils/test_are_argspecs_identical.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import random +import string +from nose2.tools import such +from testdoubles.utils import are_argspecs_identical +from tests.common.layers import UnitTestsLayer +from tests.common.compat import mock + +with such.A('Arguments comparison method') as it: + it.uses(UnitTestsLayer) + + @it.should("return true if the argspecs are completely identical") + def test_should_return_true_if_the_argspecs_are_completely_identical(case): + with mock.patch('inspect.getargspec', return_value=mock.DEFAULT): + actual = are_argspecs_identical(mock.DEFAULT, mock.DEFAULT) + + case.assertTrue(actual) + + @it.should("return false if the argspecs are completely different") + def test_should_return_true_if_the_argspecs_are_completely_identical(case): + def fake_getargspec(_): + return getattr(mock.sentinel, random.choice(string.ascii_letters)) + + with mock.patch('inspect.getargspec', fake_getargspec): + actual = are_argspecs_identical(mock.DEFAULT, mock.DEFAULT) + + case.assertEqual(actual, False) + + it.createTests(globals()) \ No newline at end of file From 82d13c02dd541ff25a08156e36bcdd560b0d3cce Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sat, 12 Oct 2013 19:41:03 +0300 Subject: [PATCH 05/46] The PyPy version travis installed has no alias for __globals__. --- tests/unit/fakes/test_fake_callable.py | 40 ++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index d53000e..6e9793f 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -56,6 +56,13 @@ def teardown(case): @it.should("raise a ValueError when the provided live object does not match the argspec") def test_should_raise_a_ValueError_when_the_provided_live_object_does_not_match_the_argspec(case): + try: + old_init_globals = callables.FakeCallable.__init__.__globals__ + callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = lambda _, __: False + except AttributeError: + old_init_globals = callables.FakeCallable.__init__.func_globals + callables.FakeCallable.__init__.func_globals['are_argspecs_identical'] = lambda _, __: False + with case.assertRaisesRegexp(ValueError, r"The provided live object's arguments ArgSpec\((?:[a-zA-Z1-9_]+=.+(?:, |(?=\))))+\) does not match ArgSpec\((?:[a-zA-Z1-9_]+=.+(?:, |(?=\))))+\)"): old_init_globals = callables.FakeCallable.__init__.__globals__ callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = lambda _, __: False @@ -65,23 +72,40 @@ def test_should_raise_a_ValueError_when_the_provided_live_object_does_not_match_ callables.FakeCallable.__init__.__globals__.update(old_init_globals) + try: + callables.FakeCallable.__init__.__globals__.update(old_init_globals) + except AttributeError: + callables.FakeCallable.__init__.func_globals.update(old_init_globals) + @it.should("not raise a ValueError when the provided live object matches the argspec") def test_should_not_raise_a_ValueError_when_the_provided_live_object_matches_the_argspec(case): - old_init_globals = callables.FakeCallable.__init__.__globals__ - callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = lambda _, __: True + try: + old_init_globals = callables.FakeCallable.__init__.__globals__ + callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = lambda _, __: True + except AttributeError: + old_init_globals = callables.FakeCallable.__init__.func_globals + callables.FakeCallable.__init__.func_globals['are_argspecs_identical'] = lambda _, __: True try: callables.FakeCallable(mock.DEFAULT, inspect_args=True) except ValueError: case.fail() - callables.FakeCallable.__init__.__globals__.update(old_init_globals) + try: + callables.FakeCallable.__init__.__globals__.update(old_init_globals) + except AttributeError: + callables.FakeCallable.__init__.func_globals.update(old_init_globals) @it.should("not inspect the argspec of the live object when argument inspection is opted out") def test_should_not_inspect_the_argspec_of_the_live_object_when_argument_inspection_is_opted_out(case): - old_init_globals = callables.FakeCallable.__init__.__globals__ mocked_are_argspecs_identical = mock.Mock() - callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = mock.Mock() + + try: + old_init_globals = callables.FakeCallable.__init__.__globals__ + callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = mocked_are_argspecs_identical + except AttributeError: + old_init_globals = callables.FakeCallable.__init__.func_globals + callables.FakeCallable.__init__.func_globals['are_argspecs_identical'] = mocked_are_argspecs_identical try: callables.FakeCallable(mock.DEFAULT, inspect_args=False) @@ -89,7 +113,11 @@ def test_should_not_inspect_the_argspec_of_the_live_object_when_argument_inspect pass mocked_are_argspecs_identical.assert_has_calls([]) - callables.FakeCallable.__init__.__globals__.update(old_init_globals) + + try: + callables.FakeCallable.__init__.__globals__.update(old_init_globals) + except AttributeError: + callables.FakeCallable.__init__.func_globals.update(old_init_globals) it.createTests(globals()) From c227c9f7c6588b2a98c62733e33d314cf5bcb707 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sat, 12 Oct 2013 19:47:30 +0300 Subject: [PATCH 06/46] Some of the old code was left by mistake. This build should pass. --- tests/unit/fakes/test_fake_callable.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 6e9793f..4901c33 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -64,9 +64,6 @@ def test_should_raise_a_ValueError_when_the_provided_live_object_does_not_match_ callables.FakeCallable.__init__.func_globals['are_argspecs_identical'] = lambda _, __: False with case.assertRaisesRegexp(ValueError, r"The provided live object's arguments ArgSpec\((?:[a-zA-Z1-9_]+=.+(?:, |(?=\))))+\) does not match ArgSpec\((?:[a-zA-Z1-9_]+=.+(?:, |(?=\))))+\)"): - old_init_globals = callables.FakeCallable.__init__.__globals__ - callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = lambda _, __: False - with mock.patch('inspect.getargspec', return_value='ArgSpec(a=None)'): callables.FakeCallable(mock.DEFAULT, inspect_args=True) From d3e2aaf78a186e380aae2b6e651d93a49613198c Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sat, 12 Oct 2013 19:59:04 +0300 Subject: [PATCH 07/46] Some of the old code was left by mistake. This build will pass. --- tests/unit/fakes/test_fake_callable.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 4901c33..4f496f0 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -67,8 +67,6 @@ def test_should_raise_a_ValueError_when_the_provided_live_object_does_not_match_ with mock.patch('inspect.getargspec', return_value='ArgSpec(a=None)'): callables.FakeCallable(mock.DEFAULT, inspect_args=True) - callables.FakeCallable.__init__.__globals__.update(old_init_globals) - try: callables.FakeCallable.__init__.__globals__.update(old_init_globals) except AttributeError: From a854081e9119c99f0138448106f32394c670d8ae Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 1 Nov 2013 17:53:40 +0200 Subject: [PATCH 08/46] Added tests that verify that if the argspecs are not completely identical but can be ducted typed the are_argspecs_identical method will still return true. --- .noseids | Bin 7007 -> 7536 bytes testdoubles/utils.py | 13 ++++++++++++- .../unit/utils/test_are_argspecs_identical.py | 13 ++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.noseids b/.noseids index 42ffcdd9b01a536406f61e61a1f4deed3a94ea08..fe9d45076a5cfe324c7ba31552d251e047d10055 100644 GIT binary patch literal 7536 zcmcgxO_SP25WVv&rhHkSC_wCbotrC(t8_^YcI8S5Gz=39Ns&ftZ+?B=8zhZDA1e^f z#Y?f?nO67v=x)6a)5Yw|gORz(A7<%t_C8Ek)fe-95$}vn;vkyugKsjQ^Z#x5asEks z#t-r5_HVf}_It5dEFOOm`5`HyQ0$V}1UeQ$6p1uTQkfYob72mF5kV%!QRlgimB4>7 z2Pt@_(8n~AM~Oe=r3lBH`A@U_%R3w1Ks1{jt_ikL9oFYE@P`~1XrqHj|7#BwM`;d8 zSO>hU1I_}SOA&~_f~b(cXIYYo?+1B`4iE66Lm7%lzethTXBJ_C=ZO;|j)B=7>{A4p z%2T;}H%r$ufBA^ePnjJEy(f{2IBN`o4To@dI%_LZcub;hAgb`1bZ_HyR0ro(as-<>9vd^cIqPxnr$ zFIPw-0Z{7VFe(SqxUBOyH7ceMKC}Gjm^~a->3pLt=A6@IC95*BtQA?B=3=dAwqrYVc054dhrYJzxAHx#`rR;qMKvIM-+VU$ysM={O?~f!L&?ui zwNu-XgzJ$I;soYJm<;gl%}%7Uqpz^WafT{?=-iNCG$W>N;ChG8QM7lgn$UbOG+5GV zv?5(lr)?W24e_Sz9rFzuO*jSq8U^`OJN+&>ra`82 zNWeu4+ray&4QtABb*k;Tc}4`YiC`$zC5#RZvVNlh>#xqL!`s%kdz;QgE~C8&jLGyC zT`vQKYk2F6^s%*Q3?!ohbgpqP_^e&aD(mG4(LGV46^e3(^8ptdAoDO5I^`hBamcw{uP>>K07Jydr9D<{1+cny z^fT(tYTEUaU9H){uv|dFFMW?a_SBZE=7vio!@PQE?J{%0&jQqY#zg2GmUBLal^dgLG)Q#?TfvPZYUk3~E=? z;He%;PJ?VO4U{y7EWjIpy!;q|5H&lmq67vje~Nv%HDRZHRZaT2ca`5VYp{WveZ8xm zE}olQ;B0k?-pz-z-iWp?`FC`jtQTvlf5Y?p@#Y-rVm-jOPb2oKEsEU8U#bh=QK0Wc zN_EJ_W&O-IdTVIka;ES!n9UTQ3No$O9snGQ9X`4n#ZusXo8pfT_?kbTXNvE!usc#* z;BW`7xCiGJSMerZr*JJk;7GV7`$$Ei@&%aU(O8@*UWEe`U!d?Uin4#fQ+W#{NAbM? zH!+HvSk6O=Z6C)qMHA+ftvI`}C>aX(7wP+Y;V zEm!mbB2RI8;A%l}{-Q1`IxVMZ#i^eAKE<~vY^4-e5L~t@cFMG5#dRQGXei!*(-pOo VyA;Kh5=SS+)jWq3#XcvW{|Ds2J;eY3 delta 1155 zcmY*YO>bLO5RJb*@7d3O&wl=l6FasOJ5JLUAtJR(3kZbK0Tl@$T~+C#YAa0zi%i`J zwNlhbth#7Qa#<9F+KLLqhoEc`QiTL-$UgwFWdZyH?(^$Q=<=SKIdkUB+<#8}{z7vn zu`M$Lm71BExqfAGeIl`Ki4WB0=B+Qf>$)Cik_6J~afqDXkG(^ZL{{CH0S0*3t|@(qB!i^79U!iERzJ2Z{j=TDKRIQ6AzdKJqNH|@qUT5m zzS;|s=k=~*>o;?xZ>B7Lx^b4oLPxzHMtge)p5Dp7L}H_-?g!vSqw5FD)_?mOBst_l zqD^~`Bo9|@hB=!g4lJb(X$ty`-6ttvS=|Z2qs|5QRgxmw>dR^I)SIq8p0xC@)iWe6 zQjz|nnuGG1zE?BTd6-vUhfUY?U$qHI2}QLZAe;8v`!QSpR!!@+o7W!~J0xXzkyX>- zHvEd|v`*q<7%3YYFN~rJW+UVdNfk}?ZKN-g9qB)kCZ~pk`YJ$O&(NLFKf0d&q%_nH zHAw2{tDA?xz{rYzvARmqKvzwsT*l16_iyUYku;H4_rmnC9+lrBnMEtwQ@Gb(s$-HC z%If=RwQ(v?a_H0?;-Q-0zB1YONahiX#tpplpS_GWDrzUv@g#2Pf@AjIfvv6u=)ZK0 zWC0`fUGRE3;oXFzC1cL8i={~1SRa&MC+VS~J`7XG`a#7=?W3+9O&hq6NEVS%pN7OI z^^^F!BuiL%#-R=W6_No45zW!Qr*uQisn0^X^ZIVWG*|}x|2BMcnr15_)YKQD5VMt2 zdbea!SFor)3c-lh{I_FRh^7e83%6ty)h(4UiB~UAb4L!O&(IE4bIQREU_&cov}N}NTRTkx4s;WnzgiW-kl=RO+T zLzAnoVU{as@hs+eh Date: Fri, 1 Nov 2013 18:08:07 +0200 Subject: [PATCH 09/46] Started working on matching arguments. --- .noseids | 235 ++---------------- testdoubles/utils.py | 7 +- .../unit/utils/test_are_argspecs_identical.py | 2 +- .../utils/test_are_arguments_identical.py | 35 +++ 4 files changed, 62 insertions(+), 217 deletions(-) create mode 100644 tests/unit/utils/test_are_arguments_identical.py diff --git a/.noseids b/.noseids index fe9d450..25bc47f 100644 --- a/.noseids +++ b/.noseids @@ -2,232 +2,37 @@ S'tests' p1 (dp2 -S'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' +S'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' p3 -I6 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" +I4 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' p4 -I15 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' +I5 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' p5 -I1 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" +I6 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' p6 -I13 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' +I3 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' p7 -I18 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." -p8 -I16 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" -p9 -I41 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" -p10 -I10 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' -p11 -I28 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" -p12 -I11 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' -p13 -I19 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" -p14 -I39 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" -p15 -I8 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" -p16 -I37 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" -p17 -I9 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' -p18 -I17 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' -p19 -I21 -sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' -p20 -I42 -sS'tests.unit.utils.test_are_argspecs_identical.A Arguments comparison method.test 0000: should return true if the argspecs are completely identical' -p21 -I43 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' -p22 -I34 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' -p23 -I24 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" -p24 -I36 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' -p25 I2 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p26 -I23 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' -p27 -I22 -sS'tests.unit.utils.test_are_argspecs_identical.A Arguments comparison method.test 0001: should return true if the argspecs are almost identical' -p28 -I44 -sS'tests.unit.utils.test_are_argspecs_identical.A Arguments comparison method.test 0002: should return false if the argspecs are completely different' -p29 -I45 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' -p30 -I32 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" -p31 -I14 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p32 -I27 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p33 -I5 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a ValueError when the provided live object matches the argspec" -p34 -I38 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' -p35 -I29 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' -p36 -I26 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" -p37 -I40 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' -p38 -I3 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' -p39 -I30 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" -p40 -I35 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p41 -I20 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' -p42 -I31 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p43 -I7 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p44 -I4 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' -p45 -I33 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p46 -I25 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p47 -I12 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' +p8 +I1 ssS'ids' -p48 -(dp49 +p9 +(dp10 I1 -g5 +g8 sI2 -g25 +g7 sI3 -g38 +g6 sI4 -g44 -sI5 -g33 -sI6 g3 -sI7 -g43 -sI8 -g15 -sI9 -g17 -sI10 -g10 -sI11 -g12 -sI12 -g47 -sI13 -g6 -sI14 -g31 -sI15 +sI5 g4 -sI16 -g8 -sI17 -g18 -sI18 -g7 -sI19 -g13 -sI20 -g41 -sI21 -g19 -sI22 -g27 -sI23 -g26 -sI24 -g23 -sI25 -g46 -sI26 -g36 -sI27 -g32 -sI28 -g11 -sI29 -g35 -sI30 -g39 -sI31 -g42 -sI32 -g30 -sI33 -g45 -sI34 -g22 -sI35 -g40 -sI36 -g24 -sI37 -g16 -sI38 -g34 -sI39 -g14 -sI40 -g37 -sI41 -g9 -sI42 -g20 -sI43 -g21 -sI44 -g28 -sI45 -g29 +sI6 +g5 ss. \ No newline at end of file diff --git a/testdoubles/utils.py b/testdoubles/utils.py index b7e07cb..86f3003 100644 --- a/testdoubles/utils.py +++ b/testdoubles/utils.py @@ -4,7 +4,12 @@ def are_arguments_identical(argspec1, argspec2): - pass + if len(argspec1[0]) == len(argspec2[0]): + return True + elif any(_ for _ in argspec1[0]) and argspec2[1] or any(_ for _ in argspec2[0]) and argspec1[1]: + return True + + return False def are_keyword_arguments_identical(argspec1, argspec2): diff --git a/tests/unit/utils/test_are_argspecs_identical.py b/tests/unit/utils/test_are_argspecs_identical.py index c931b7d..9c8df75 100644 --- a/tests/unit/utils/test_are_argspecs_identical.py +++ b/tests/unit/utils/test_are_argspecs_identical.py @@ -7,7 +7,7 @@ from tests.common.layers import UnitTestsLayer from tests.common.compat import mock -with such.A('Arguments comparison method') as it: +with such.A('argspecs comparison method') as it: it.uses(UnitTestsLayer) @it.should("return true if the argspecs are completely identical") diff --git a/tests/unit/utils/test_are_arguments_identical.py b/tests/unit/utils/test_are_arguments_identical.py new file mode 100644 index 0000000..3b18325 --- /dev/null +++ b/tests/unit/utils/test_are_arguments_identical.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import inspect +from nose2.tools import such +from testdoubles.utils import are_arguments_identical +from tests.common.layers import UnitTestsLayer + +with such.A('arguments comparison method') as it: + it.uses(UnitTestsLayer) + + @it.should("return true if the first method has an argument and the second method has specified a varargs argument") + def test_should_return_true_if_the_first_method_has_an_argument_and_the_second_method_has_specified_a_varargs_argument( + case): + actual = are_arguments_identical(inspect.ArgSpec(['a'], None, None, None), + inspect.ArgSpec([], 'args', None, None)) + + case.assertTrue(actual) + + @it.should( + "return true if the first method has specified a varargs argument and the second method has an argument ") + def test_should_return_true_if_the_first_method_has_specified_a_varargs_argument_and_the_second_method_has_an_argument( + case): + actual = are_arguments_identical(inspect.ArgSpec([], 'args', None, None), + inspect.ArgSpec(['a'], None, None, None)) + + case.assertTrue(actual) + + @it.should("return true if both methods have the same amount of arguments") + def test_should_return_true_if_both_methods_have_the_same_amount_of_arguments(case): + actual = are_arguments_identical(inspect.ArgSpec(['a'], None, None, None), + inspect.ArgSpec(['a'], None, None, None)) + + case.assertTrue(actual) + + it.createTests(globals()) \ No newline at end of file From 467d6d618ec022921750bb29f458525276c14000 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 1 Nov 2013 18:11:05 +0200 Subject: [PATCH 10/46] Arguments will now match correctly and will consider varargs as a match. --- .noseids | 32 ++++++++++++------- .../utils/test_are_arguments_identical.py | 14 ++++++++ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/.noseids b/.noseids index 25bc47f..3151515 100644 --- a/.noseids +++ b/.noseids @@ -5,34 +5,44 @@ p1 S'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' p3 I4 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p4 +I7 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" +p5 +I8 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' +p6 I5 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' -p5 +p7 I6 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' -p6 +p8 I3 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' -p7 +p9 I2 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' -p8 +p10 I1 ssS'ids' -p9 -(dp10 +p11 +(dp12 I1 -g8 +g10 sI2 -g7 +g9 sI3 -g6 +g8 sI4 g3 sI5 -g4 +g6 sI6 +g7 +sI7 +g4 +sI8 g5 ss. \ No newline at end of file diff --git a/tests/unit/utils/test_are_arguments_identical.py b/tests/unit/utils/test_are_arguments_identical.py index 3b18325..42fce1f 100644 --- a/tests/unit/utils/test_are_arguments_identical.py +++ b/tests/unit/utils/test_are_arguments_identical.py @@ -32,4 +32,18 @@ def test_should_return_true_if_both_methods_have_the_same_amount_of_arguments(ca case.assertTrue(actual) + @it.should("return false if the first method doesn't have the same amount of arguments as the second") + def test_should_return_true_if_both_methods_have_the_same_amount_of_arguments(case): + actual = are_arguments_identical(inspect.ArgSpec(['a', 'b'], None, None, None), + inspect.ArgSpec(['a'], None, None, None)) + + case.assertEqual(actual, False) + + @it.should("return false if the second method doesn't have the same amount of arguments as the first") + def test_should_return_true_if_both_methods_have_the_same_amount_of_arguments(case): + actual = are_arguments_identical(inspect.ArgSpec(['a'], None, None, None), + inspect.ArgSpec(['a', 'b'], None, None, None)) + + case.assertEqual(actual, False) + it.createTests(globals()) \ No newline at end of file From 4d5ec991fe7a42e865819e29cfd5ba5436e9bdbb Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 1 Nov 2013 18:28:55 +0200 Subject: [PATCH 11/46] Improved code readability. --- .noseids | 260 ++++++++++++++++++++++++++++++++++++++----- testdoubles/utils.py | 4 +- 2 files changed, 237 insertions(+), 27 deletions(-) diff --git a/.noseids b/.noseids index 3151515..fb0b294 100644 --- a/.noseids +++ b/.noseids @@ -2,47 +2,257 @@ S'tests' p1 (dp2 -S'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' +S'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' p3 -I4 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" +I6 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" p4 -I7 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" +I15 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' p5 -I8 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' +I1 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" p6 -I5 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' +I13 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' p7 -I6 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' -p8 -I3 +I18 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' +p8 +I44 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." p9 -I2 +I16 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' p10 -I1 -ssS'ids' +I43 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p11 -(dp12 +I41 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" +p12 +I10 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' +p13 +I28 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" +p14 +I11 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' +p15 +I19 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" +p16 +I49 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" +p17 +I39 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" +p18 +I8 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" +p19 +I37 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" +p20 +I9 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' +p21 +I17 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' +p22 +I21 +sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' +p23 +I42 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' +p24 +I34 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' +p25 +I24 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" +p26 +I36 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' +p27 +I2 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' +p28 +I23 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" +p29 +I50 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' +p30 +I22 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' +p31 +I45 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' +p32 +I32 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +p33 +I14 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' +p34 +I27 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' +p35 +I5 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a ValueError when the provided live object matches the argspec" +p36 +I38 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' +p37 +I29 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' +p38 +I46 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' +p39 +I26 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" +p40 +I40 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' +p41 +I3 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' +p42 +I30 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" +p43 +I35 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' +p44 +I47 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' +p45 +I48 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' +p46 +I20 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' +p47 +I31 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' +p48 +I7 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' +p49 +I4 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' +p50 +I33 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' +p51 +I25 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" +p52 +I12 +ssS'ids' +p53 +(dp54 I1 -g10 +g5 sI2 -g9 +g27 sI3 -g8 +g41 sI4 -g3 +g49 sI5 -g6 +g35 sI6 -g7 +g3 sI7 -g4 +g48 sI8 -g5 +g18 +sI9 +g20 +sI10 +g12 +sI11 +g14 +sI12 +g52 +sI13 +g6 +sI14 +g33 +sI15 +g4 +sI16 +g9 +sI17 +g21 +sI18 +g7 +sI19 +g15 +sI20 +g46 +sI21 +g22 +sI22 +g30 +sI23 +g28 +sI24 +g25 +sI25 +g51 +sI26 +g39 +sI27 +g34 +sI28 +g13 +sI29 +g37 +sI30 +g42 +sI31 +g47 +sI32 +g32 +sI33 +g50 +sI34 +g24 +sI35 +g43 +sI36 +g26 +sI37 +g19 +sI38 +g36 +sI39 +g17 +sI40 +g40 +sI41 +g11 +sI42 +g23 +sI43 +g10 +sI44 +g8 +sI45 +g31 +sI46 +g38 +sI47 +g44 +sI48 +g45 +sI49 +g16 +sI50 +g29 ss. \ No newline at end of file diff --git a/testdoubles/utils.py b/testdoubles/utils.py index 86f3003..5151bd6 100644 --- a/testdoubles/utils.py +++ b/testdoubles/utils.py @@ -4,9 +4,9 @@ def are_arguments_identical(argspec1, argspec2): - if len(argspec1[0]) == len(argspec2[0]): + if len(argspec1.args) == len(argspec2.args): return True - elif any(_ for _ in argspec1[0]) and argspec2[1] or any(_ for _ in argspec2[0]) and argspec1[1]: + elif any(_ for _ in argspec1.args) and argspec2.varargs or any(_ for _ in argspec2.args) and argspec1.varargs: return True return False From df7e6ab1c5ef08df290354580580bf9120ea0e5f Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 1 Nov 2013 18:52:43 +0200 Subject: [PATCH 12/46] Added tests that verify that if a keyword argument was provided on the first method and a kwargs argument on the second the are_keyword_arguments_identical method will return true. --- .noseids | 264 +++--------------- testdoubles/utils.py | 6 +- .../test_are_keyword_arguments_identical.py | 30 ++ 3 files changed, 67 insertions(+), 233 deletions(-) create mode 100644 tests/unit/utils/test_are_keyword_arguments_identical.py diff --git a/.noseids b/.noseids index fb0b294..cbe8d59 100644 --- a/.noseids +++ b/.noseids @@ -2,257 +2,57 @@ S'tests' p1 (dp2 -S'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' +S'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' p3 -I6 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" +I4 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p4 -I15 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' +I7 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p5 -I1 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" +I10 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" p6 -I13 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' +I8 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' p7 -I18 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' +I9 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' p8 -I44 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." +I5 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' p9 -I16 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' +I6 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' p10 -I43 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" +I3 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' p11 -I41 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" -p12 -I10 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' -p13 -I28 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" -p14 -I11 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' -p15 -I19 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" -p16 -I49 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" -p17 -I39 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" -p18 -I8 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" -p19 -I37 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" -p20 -I9 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' -p21 -I17 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' -p22 -I21 -sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' -p23 -I42 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' -p24 -I34 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' -p25 -I24 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" -p26 -I36 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' -p27 I2 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p28 -I23 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" -p29 -I50 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' -p30 -I22 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' -p31 -I45 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' -p32 -I32 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" -p33 -I14 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p34 -I27 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p35 -I5 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a ValueError when the provided live object matches the argspec" -p36 -I38 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' -p37 -I29 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' -p38 -I46 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' -p39 -I26 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" -p40 -I40 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' -p41 -I3 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' -p42 -I30 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" -p43 -I35 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p44 -I47 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' -p45 -I48 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p46 -I20 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' -p47 -I31 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p48 -I7 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p49 -I4 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' -p50 -I33 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p51 -I25 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p52 -I12 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' +p12 +I1 ssS'ids' -p53 -(dp54 +p13 +(dp14 I1 -g5 +g12 sI2 -g27 +g11 sI3 -g41 +g10 sI4 -g49 +g3 sI5 -g35 +g8 sI6 -g3 +g9 sI7 -g48 +g4 sI8 -g18 -sI9 -g20 -sI10 -g12 -sI11 -g14 -sI12 -g52 -sI13 g6 -sI14 -g33 -sI15 -g4 -sI16 -g9 -sI17 -g21 -sI18 +sI9 g7 -sI19 -g15 -sI20 -g46 -sI21 -g22 -sI22 -g30 -sI23 -g28 -sI24 -g25 -sI25 -g51 -sI26 -g39 -sI27 -g34 -sI28 -g13 -sI29 -g37 -sI30 -g42 -sI31 -g47 -sI32 -g32 -sI33 -g50 -sI34 -g24 -sI35 -g43 -sI36 -g26 -sI37 -g19 -sI38 -g36 -sI39 -g17 -sI40 -g40 -sI41 -g11 -sI42 -g23 -sI43 -g10 -sI44 -g8 -sI45 -g31 -sI46 -g38 -sI47 -g44 -sI48 -g45 -sI49 -g16 -sI50 -g29 +sI10 +g5 ss. \ No newline at end of file diff --git a/testdoubles/utils.py b/testdoubles/utils.py index 5151bd6..7977412 100644 --- a/testdoubles/utils.py +++ b/testdoubles/utils.py @@ -13,7 +13,11 @@ def are_arguments_identical(argspec1, argspec2): def are_keyword_arguments_identical(argspec1, argspec2): - pass + kwargs1 = argspec1.args[-len(argspec1.defaults):] if argspec1.defaults else [] + kwargs2 = argspec2.args[-len(argspec2.defaults):] if argspec2.defaults else [] + + if any(_ for _ in kwargs1) and argspec2.keywords or any(_ for _ in kwargs2) and argspec1.keywords: + return True def are_argspecs_identical(callable1, callable2): diff --git a/tests/unit/utils/test_are_keyword_arguments_identical.py b/tests/unit/utils/test_are_keyword_arguments_identical.py new file mode 100644 index 0000000..845637c --- /dev/null +++ b/tests/unit/utils/test_are_keyword_arguments_identical.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import inspect +import mock +from nose2.tools import such +from testdoubles.utils import are_keyword_arguments_identical +from tests.common.layers import UnitTestsLayer + +with such.A('keyword arguments comparison method') as it: + it.uses(UnitTestsLayer) + + @it.should( + "return true if the first method has a keyword argument and the second method has specified a kwargs argument") + def test_should_return_true_if_the_first_method_has_a_keyword_argument_and_the_second_method_has_specified_a_kwargs_argument( + case): + actual = are_keyword_arguments_identical(inspect.ArgSpec(['a'], None, None, (mock.DEFAULT, )), + inspect.ArgSpec([], None, 'kwargs', None)) + + case.assertTrue(actual) + + @it.should( + "return true if the first method has specified a kwargs argument and the second method has a keyword argument") + def test_should_return_true_if_the_first_method_has_specified_a_kwargs_argument_and_the_second_method_has_a_keyword_argument( + case): + actual = are_keyword_arguments_identical(inspect.ArgSpec([], None, 'kwargs', None), + inspect.ArgSpec(['a'], None, None, (mock.DEFAULT, ))) + + case.assertTrue(actual) + + it.createTests(globals()) \ No newline at end of file From 6279c3fcae29565c0125050bd6479724c5d2cb53 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 1 Nov 2013 18:56:14 +0200 Subject: [PATCH 13/46] Made tests to work again on Python 2.6. --- tests/unit/utils/test_are_argspecs_identical.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/unit/utils/test_are_argspecs_identical.py b/tests/unit/utils/test_are_argspecs_identical.py index 9c8df75..8565fa6 100644 --- a/tests/unit/utils/test_are_argspecs_identical.py +++ b/tests/unit/utils/test_are_argspecs_identical.py @@ -19,10 +19,10 @@ def test_should_return_true_if_the_argspecs_are_completely_identical(case): @it.should("return true if the argspecs are almost identical") def test_should_return_true_if_the_argspecs_are_almost_identical(case): - with mock.patch('inspect.getargspec', return_value=mock.DEFAULT), mock.patch( - 'testdoubles.utils.are_arguments_identical', return_value=True), mock.patch( - 'testdoubles.utils.are_keyword_arguments_identical', return_value=True): - actual = are_argspecs_identical(mock.DEFAULT, mock.DEFAULT) + with mock.patch('inspect.getargspec', return_value=mock.DEFAULT): + with mock.patch('testdoubles.utils.are_arguments_identical', return_value=True): + with mock.patch('testdoubles.utils.are_keyword_arguments_identical', return_value=True): + actual = are_argspecs_identical(mock.DEFAULT, mock.DEFAULT) case.assertTrue(actual) @@ -31,10 +31,10 @@ def test_should_return_true_if_the_argspecs_are_completely_identical(case): def fake_getargspec(_): return getattr(mock.sentinel, random.choice(string.ascii_letters)) - with mock.patch('inspect.getargspec', fake_getargspec), mock.patch( - 'testdoubles.utils.are_arguments_identical', return_value=False), mock.patch( - 'testdoubles.utils.are_keyword_arguments_identical', return_value=False): - actual = are_argspecs_identical(mock.DEFAULT, mock.DEFAULT) + with mock.patch('inspect.getargspec', fake_getargspec): + with mock.patch('testdoubles.utils.are_arguments_identical', return_value=False): + with mock.patch('testdoubles.utils.are_keyword_arguments_identical', return_value=False): + actual = are_argspecs_identical(mock.DEFAULT, mock.DEFAULT) case.assertEqual(actual, False) From 5ad137843f5f05d23b0c801b050846e981a9bafd Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 1 Nov 2013 19:08:47 +0200 Subject: [PATCH 14/46] Finished the argspec matching feature. Closes #3 and #4. --- .noseids | 38 ++++++++++++------- testdoubles/utils.py | 4 ++ .../test_are_keyword_arguments_identical.py | 14 +++++++ 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/.noseids b/.noseids index cbe8d59..a0d07fa 100644 --- a/.noseids +++ b/.noseids @@ -14,45 +14,55 @@ I10 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" p6 I8 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' p7 +I11 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' +p8 I9 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p8 +p9 I5 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' -p9 +p10 I6 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' -p10 +p11 I3 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' +p12 +I12 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' -p11 +p13 I2 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' -p12 +p14 I1 ssS'ids' -p13 -(dp14 +p15 +(dp16 I1 -g12 +g14 sI2 -g11 +g13 sI3 -g10 +g11 sI4 g3 sI5 -g8 -sI6 g9 +sI6 +g10 sI7 g4 sI8 g6 sI9 -g7 +g8 sI10 g5 +sI11 +g7 +sI12 +g12 ss. \ No newline at end of file diff --git a/testdoubles/utils.py b/testdoubles/utils.py index 7977412..33a784e 100644 --- a/testdoubles/utils.py +++ b/testdoubles/utils.py @@ -16,9 +16,13 @@ def are_keyword_arguments_identical(argspec1, argspec2): kwargs1 = argspec1.args[-len(argspec1.defaults):] if argspec1.defaults else [] kwargs2 = argspec2.args[-len(argspec2.defaults):] if argspec2.defaults else [] + if kwargs1 == kwargs2: + return True if any(_ for _ in kwargs1) and argspec2.keywords or any(_ for _ in kwargs2) and argspec1.keywords: return True + return False + def are_argspecs_identical(callable1, callable2): argspec1 = inspect.getargspec(callable1) diff --git a/tests/unit/utils/test_are_keyword_arguments_identical.py b/tests/unit/utils/test_are_keyword_arguments_identical.py index 845637c..522565a 100644 --- a/tests/unit/utils/test_are_keyword_arguments_identical.py +++ b/tests/unit/utils/test_are_keyword_arguments_identical.py @@ -27,4 +27,18 @@ def test_should_return_true_if_the_first_method_has_specified_a_kwargs_argument_ case.assertTrue(actual) + @it.should("return true if both methods have exactly the same keyword arguments") + def test_should_return_true_if_both_methods_have_exactly_the_same_keyword_arguments(case): + actual = are_keyword_arguments_identical(inspect.ArgSpec(['a'], None, None, (mock.DEFAULT, )), + inspect.ArgSpec(['a'], None, None, (mock.DEFAULT, )),) + + case.assertTrue(actual) + + @it.should("return false if both methods have different keyword arguments and no kwargs argument") + def test_should_return_false_if_both_methods_have_different_keyword_arguments_and_no_kwargs_argument(case): + actual = are_keyword_arguments_identical(inspect.ArgSpec(['a'], None, None, (mock.DEFAULT, )), + inspect.ArgSpec(['b'], None, None, (mock.DEFAULT, )),) + + case.assertEqual(actual, False) + it.createTests(globals()) \ No newline at end of file From dffcb288efa29fc4658cf34ee5905bedbfbaffc5 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 1 Nov 2013 19:14:21 +0200 Subject: [PATCH 15/46] Reformatted code. --- testdoubles/fakes/callables.py | 4 +++- tests/functional/utils/__init__.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tests/functional/utils/__init__.py diff --git a/testdoubles/fakes/callables.py b/testdoubles/fakes/callables.py index 1a11f10..d9abe00 100644 --- a/testdoubles/fakes/callables.py +++ b/testdoubles/fakes/callables.py @@ -29,6 +29,7 @@ def is_unbound_instance_method(self): def is_instance_method(self): return inspect.ismethod(self.live) or self.is_unbound_instance_method + class FakeCallable(CallableIntrospectionMixin): def __init__(self, live, inspect_args=False): if not callable(live): @@ -41,7 +42,8 @@ def __init__(self, live, inspect_args=False): if inspect_args: if not are_argspecs_identical(self.live, self.fake): - raise ValueError("The provided live object's arguments %s does not match %s" % (inspect.getargspec(self.live), inspect.getargspec(self.fake))) + raise ValueError("The provided live object's arguments %s does not match %s" % ( + inspect.getargspec(self.live), inspect.getargspec(self.fake))) @property diff --git a/tests/functional/utils/__init__.py b/tests/functional/utils/__init__.py new file mode 100644 index 0000000..a5682fb --- /dev/null +++ b/tests/functional/utils/__init__.py @@ -0,0 +1,2 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- \ No newline at end of file From 5cc588e2c223e1bfa21d8ad02a21f7411500a54c Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 1 Nov 2013 19:23:21 +0200 Subject: [PATCH 16/46] Added tests that verify that if one method has no arguments and the other has a varargs argument then they shouldn't match. --- .noseids | 292 +++++++++++++++--- testdoubles/utils.py | 2 +- .../utils/test_are_arguments_identical.py | 18 ++ 3 files changed, 275 insertions(+), 37 deletions(-) diff --git a/.noseids b/.noseids index a0d07fa..39c996a 100644 --- a/.noseids +++ b/.noseids @@ -2,67 +2,287 @@ S'tests' p1 (dp2 -S'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' +S'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' p3 -I4 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" +I6 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" p4 -I7 +I15 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p5 -I10 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" +I54 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' p6 -I8 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' +I1 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" p7 -I11 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' +I13 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' p8 -I9 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' +I18 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' p9 -I5 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' +I51 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' p10 -I6 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' +I44 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." p11 -I3 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' +I16 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' p12 -I12 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' +I43 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p13 -I2 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' +I41 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" p14 -I1 -ssS'ids' +I10 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' p15 -(dp16 +I28 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" +p16 +I11 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' +p17 +I19 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" +p18 +I49 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" +p19 +I39 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" +p20 +I8 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" +p21 +I37 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" +p22 +I9 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' +p23 +I17 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' +p24 +I21 +sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' +p25 +I42 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' +p26 +I56 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' +p27 +I34 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' +p28 +I24 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" +p29 +I36 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' +p30 +I53 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' +p31 +I2 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' +p32 +I23 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" +p33 +I50 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' +p34 +I55 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' +p35 +I22 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' +p36 +I45 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' +p37 +I32 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' +p38 +I52 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +p39 +I14 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' +p40 +I27 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' +p41 +I5 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a ValueError when the provided live object matches the argspec" +p42 +I38 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' +p43 +I29 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' +p44 +I46 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' +p45 +I26 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" +p46 +I40 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' +p47 +I3 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' +p48 +I30 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" +p49 +I35 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' +p50 +I47 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' +p51 +I48 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' +p52 +I20 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' +p53 +I31 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' +p54 +I7 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' +p55 +I4 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' +p56 +I33 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' +p57 +I25 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" +p58 +I12 +ssS'ids' +p59 +(dp60 I1 -g14 +g6 sI2 -g13 +g31 sI3 -g11 +g47 sI4 -g3 +g55 sI5 -g9 +g41 sI6 -g10 +g3 sI7 -g4 +g54 sI8 -g6 +g20 sI9 -g8 +g22 sI10 -g5 +g14 sI11 -g7 +g16 sI12 +g58 +sI13 +g7 +sI14 +g39 +sI15 +g4 +sI16 +g11 +sI17 +g23 +sI18 +g8 +sI19 +g17 +sI20 +g52 +sI21 +g24 +sI22 +g35 +sI23 +g32 +sI24 +g28 +sI25 +g57 +sI26 +g45 +sI27 +g40 +sI28 +g15 +sI29 +g43 +sI30 +g48 +sI31 +g53 +sI32 +g37 +sI33 +g56 +sI34 +g27 +sI35 +g49 +sI36 +g29 +sI37 +g21 +sI38 +g42 +sI39 +g19 +sI40 +g46 +sI41 +g13 +sI42 +g25 +sI43 g12 +sI44 +g10 +sI45 +g36 +sI46 +g44 +sI47 +g50 +sI48 +g51 +sI49 +g18 +sI50 +g33 +sI51 +g9 +sI52 +g38 +sI53 +g30 +sI54 +g5 +sI55 +g34 +sI56 +g26 ss. \ No newline at end of file diff --git a/testdoubles/utils.py b/testdoubles/utils.py index 33a784e..c625f5b 100644 --- a/testdoubles/utils.py +++ b/testdoubles/utils.py @@ -4,7 +4,7 @@ def are_arguments_identical(argspec1, argspec2): - if len(argspec1.args) == len(argspec2.args): + if len(argspec1.args) == len(argspec2.args) and not (argspec1.varargs or argspec2.varargs): return True elif any(_ for _ in argspec1.args) and argspec2.varargs or any(_ for _ in argspec2.args) and argspec1.varargs: return True diff --git a/tests/unit/utils/test_are_arguments_identical.py b/tests/unit/utils/test_are_arguments_identical.py index 42fce1f..4afacb8 100644 --- a/tests/unit/utils/test_are_arguments_identical.py +++ b/tests/unit/utils/test_are_arguments_identical.py @@ -46,4 +46,22 @@ def test_should_return_true_if_both_methods_have_the_same_amount_of_arguments(ca case.assertEqual(actual, False) + @it.should( + "return false if the first method has specified a varargs argument and the second method has no arguments") + def test_should_return_false_if_the_first_method_has_specified_a_varargs_argument_and_the_second_method_has_no_arguments( + case): + actual = are_arguments_identical(inspect.ArgSpec([], 'args', None, None), + inspect.ArgSpec([], None, None, None)) + + case.assertEqual(actual, False) + + @it.should( + "return false if the first method has no arguments and the second method has specified a varargs argument") + def test_should_return_false_if_the_first_method_has_no_arguments_and_the_second_method_has_specified_a_varargs_argument( + case): + actual = are_arguments_identical(inspect.ArgSpec([], None, None, None), + inspect.ArgSpec([], 'args', None, None)) + + case.assertEqual(actual, False) + it.createTests(globals()) \ No newline at end of file From 8a42a681ae17e8e73da5b5e5cc14fea3ea615f7c Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 1 Nov 2013 19:26:24 +0200 Subject: [PATCH 17/46] Added tests that verify that if one method has no arguments and the other has a kwargs argument then they shouldn't match. --- .noseids | 218 +++++++++--------- testdoubles/utils.py | 2 +- .../test_are_keyword_arguments_identical.py | 24 +- 3 files changed, 136 insertions(+), 108 deletions(-) diff --git a/.noseids b/.noseids index 39c996a..b514615 100644 --- a/.noseids +++ b/.noseids @@ -17,272 +17,282 @@ I1 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" p7 I13 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' p8 +I58 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' +p9 I18 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' -p9 +p10 I51 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' -p10 +p11 I44 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." -p11 +p12 I16 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' -p12 +p13 I43 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" -p13 +p14 I41 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" -p14 +p15 I10 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' -p15 +p16 I28 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" -p16 +p17 I11 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' -p17 +p18 I19 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" -p18 +p19 I49 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" -p19 +p20 I39 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" -p20 +p21 I8 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" -p21 +p22 I37 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" -p22 +p23 I9 sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' -p23 +p24 I17 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' -p24 +p25 I21 sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' -p25 +p26 I42 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' -p26 +p27 I56 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' -p27 +p28 I34 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' -p28 +p29 I24 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" -p29 +p30 I36 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' -p30 +p31 I53 sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' -p31 +p32 I2 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p32 +p33 I23 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" -p33 +p34 I50 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' -p34 +p35 I55 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' -p35 +p36 I22 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' -p36 +p37 I45 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' -p37 +p38 I32 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' -p38 +p39 I52 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" -p39 +p40 I14 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p40 +p41 I27 sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p41 +p42 I5 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a ValueError when the provided live object matches the argspec" -p42 +p43 I38 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' -p43 +p44 I29 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' -p44 +p45 I46 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' -p45 +p46 I26 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" -p46 +p47 I40 sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' -p47 +p48 I3 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' -p48 +p49 I30 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" -p49 +p50 I35 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p50 +p51 I47 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' -p51 +p52 I48 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p52 +p53 I20 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' -p53 +p54 I31 sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p54 +p55 I7 sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p55 +p56 I4 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' +p57 +I57 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' -p56 +p58 I33 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p57 +p59 I25 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p58 +p60 I12 ssS'ids' -p59 -(dp60 +p61 +(dp62 I1 g6 sI2 -g31 +g32 sI3 -g47 +g48 sI4 -g55 +g56 sI5 -g41 +g42 sI6 g3 sI7 -g54 +g55 sI8 -g20 +g21 sI9 -g22 +g23 sI10 -g14 +g15 sI11 -g16 +g17 sI12 -g58 +g60 sI13 g7 sI14 -g39 +g40 sI15 g4 sI16 -g11 +g12 sI17 -g23 +g24 sI18 -g8 +g9 sI19 -g17 +g18 sI20 -g52 +g53 sI21 -g24 +g25 sI22 -g35 +g36 sI23 -g32 +g33 sI24 -g28 +g29 sI25 -g57 +g59 sI26 -g45 +g46 sI27 -g40 +g41 sI28 -g15 +g16 sI29 -g43 +g44 sI30 -g48 +g49 sI31 -g53 +g54 sI32 -g37 +g38 sI33 -g56 +g58 sI34 -g27 +g28 sI35 -g49 +g50 sI36 -g29 +g30 sI37 -g21 +g22 sI38 -g42 +g43 sI39 -g19 +g20 sI40 -g46 +g47 sI41 -g13 +g14 sI42 -g25 +g26 sI43 -g12 +g13 sI44 -g10 +g11 sI45 -g36 +g37 sI46 -g44 +g45 sI47 -g50 -sI48 g51 +sI48 +g52 sI49 -g18 +g19 sI50 -g33 +g34 sI51 -g9 +g10 sI52 -g38 +g39 sI53 -g30 +g31 sI54 g5 sI55 -g34 +g35 sI56 -g26 +g27 +sI57 +g57 +sI58 +g8 ss. \ No newline at end of file diff --git a/testdoubles/utils.py b/testdoubles/utils.py index c625f5b..c6a0900 100644 --- a/testdoubles/utils.py +++ b/testdoubles/utils.py @@ -16,7 +16,7 @@ def are_keyword_arguments_identical(argspec1, argspec2): kwargs1 = argspec1.args[-len(argspec1.defaults):] if argspec1.defaults else [] kwargs2 = argspec2.args[-len(argspec2.defaults):] if argspec2.defaults else [] - if kwargs1 == kwargs2: + if kwargs1 == kwargs2 and not (argspec1.keywords or argspec2.keywords): return True if any(_ for _ in kwargs1) and argspec2.keywords or any(_ for _ in kwargs2) and argspec1.keywords: return True diff --git a/tests/unit/utils/test_are_keyword_arguments_identical.py b/tests/unit/utils/test_are_keyword_arguments_identical.py index 522565a..9d7b680 100644 --- a/tests/unit/utils/test_are_keyword_arguments_identical.py +++ b/tests/unit/utils/test_are_keyword_arguments_identical.py @@ -30,14 +30,32 @@ def test_should_return_true_if_the_first_method_has_specified_a_kwargs_argument_ @it.should("return true if both methods have exactly the same keyword arguments") def test_should_return_true_if_both_methods_have_exactly_the_same_keyword_arguments(case): actual = are_keyword_arguments_identical(inspect.ArgSpec(['a'], None, None, (mock.DEFAULT, )), - inspect.ArgSpec(['a'], None, None, (mock.DEFAULT, )),) + inspect.ArgSpec(['a'], None, None, (mock.DEFAULT, )), ) case.assertTrue(actual) - + @it.should("return false if both methods have different keyword arguments and no kwargs argument") def test_should_return_false_if_both_methods_have_different_keyword_arguments_and_no_kwargs_argument(case): actual = are_keyword_arguments_identical(inspect.ArgSpec(['a'], None, None, (mock.DEFAULT, )), - inspect.ArgSpec(['b'], None, None, (mock.DEFAULT, )),) + inspect.ArgSpec(['b'], None, None, (mock.DEFAULT, )), ) + + case.assertEqual(actual, False) + + @it.should( + "return false if the first method has specified a kwargs argument and the second method has no arguments") + def test_should_return_false_if_the_first_method_has_specified_a_kwargs_argument_and_the_second_method_has_no_arguments( + case): + actual = are_keyword_arguments_identical(inspect.ArgSpec([], None, 'kwargs', None), + inspect.ArgSpec([], None, None, None)) + + case.assertEqual(actual, False) + + @it.should( + "return false if the first method has no arguments and the second method has specified a kwargs argument") + def test_should_return_false_if_the_first_method_has_no_arguments_and_the_second_method_has_specified_a_kwargs_argument( + case): + actual = are_keyword_arguments_identical(inspect.ArgSpec([], None, None, None), + inspect.ArgSpec([], None, 'kwargs', None)) case.assertEqual(actual, False) From e639e91dce05e76e5ca32877d940eb79ed742f25 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sat, 2 Nov 2013 10:33:12 +0200 Subject: [PATCH 18/46] Added a functional test that verifies that two identical callables have the same argspec. --- .noseids | 291 +----------------- .../utils/test_are_argspecs_identical.py | 23 ++ 2 files changed, 26 insertions(+), 288 deletions(-) create mode 100644 tests/functional/utils/test_are_argspecs_identical.py diff --git a/.noseids b/.noseids index b514615..59d93a1 100644 --- a/.noseids +++ b/.noseids @@ -2,297 +2,12 @@ S'tests' p1 (dp2 -S'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' +S'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' p3 -I6 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" -p4 -I15 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' -p5 -I54 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' -p6 I1 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" -p7 -I13 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' -p8 -I58 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' -p9 -I18 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' -p10 -I51 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' -p11 -I44 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." -p12 -I16 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' -p13 -I43 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" -p14 -I41 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" -p15 -I10 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' -p16 -I28 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" -p17 -I11 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' -p18 -I19 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" -p19 -I49 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" -p20 -I39 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" -p21 -I8 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" -p22 -I37 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" -p23 -I9 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' -p24 -I17 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' -p25 -I21 -sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' -p26 -I42 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' -p27 -I56 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' -p28 -I34 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' -p29 -I24 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" -p30 -I36 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' -p31 -I53 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' -p32 -I2 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p33 -I23 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" -p34 -I50 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' -p35 -I55 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' -p36 -I22 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' -p37 -I45 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' -p38 -I32 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' -p39 -I52 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" -p40 -I14 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p41 -I27 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p42 -I5 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a ValueError when the provided live object matches the argspec" -p43 -I38 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' -p44 -I29 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' -p45 -I46 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' -p46 -I26 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" -p47 -I40 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' -p48 -I3 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' -p49 -I30 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" -p50 -I35 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p51 -I47 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' -p52 -I48 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p53 -I20 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' -p54 -I31 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p55 -I7 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p56 -I4 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' -p57 -I57 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' -p58 -I33 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p59 -I25 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p60 -I12 ssS'ids' -p61 -(dp62 +p4 +(dp5 I1 -g6 -sI2 -g32 -sI3 -g48 -sI4 -g56 -sI5 -g42 -sI6 g3 -sI7 -g55 -sI8 -g21 -sI9 -g23 -sI10 -g15 -sI11 -g17 -sI12 -g60 -sI13 -g7 -sI14 -g40 -sI15 -g4 -sI16 -g12 -sI17 -g24 -sI18 -g9 -sI19 -g18 -sI20 -g53 -sI21 -g25 -sI22 -g36 -sI23 -g33 -sI24 -g29 -sI25 -g59 -sI26 -g46 -sI27 -g41 -sI28 -g16 -sI29 -g44 -sI30 -g49 -sI31 -g54 -sI32 -g38 -sI33 -g58 -sI34 -g28 -sI35 -g50 -sI36 -g30 -sI37 -g22 -sI38 -g43 -sI39 -g20 -sI40 -g47 -sI41 -g14 -sI42 -g26 -sI43 -g13 -sI44 -g11 -sI45 -g37 -sI46 -g45 -sI47 -g51 -sI48 -g52 -sI49 -g19 -sI50 -g34 -sI51 -g10 -sI52 -g39 -sI53 -g31 -sI54 -g5 -sI55 -g35 -sI56 -g27 -sI57 -g57 -sI58 -g8 ss. \ No newline at end of file diff --git a/tests/functional/utils/test_are_argspecs_identical.py b/tests/functional/utils/test_are_argspecs_identical.py new file mode 100644 index 0000000..4cbd52b --- /dev/null +++ b/tests/functional/utils/test_are_argspecs_identical.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import mock +from nose2.tools import such +from testdoubles.utils import are_argspecs_identical +from tests.common.layers import FunctionalTestsLayer + +with such.A('keyword arguments comparison method') as it: + it.uses(FunctionalTestsLayer) + + @it.should("return true if the argspecs are completely identical") + def test_should_return_true_if_the_argspecs_are_completely_identical(case): + def fake_callable1(a, k=mock.DEFAULT): + pass + + def fake_callable2(a, k=mock.DEFAULT): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertTrue(actual) + + it.createTests(globals()) \ No newline at end of file From 7629f62c8eec69efa96efc600cf0309f5f534ce2 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sat, 2 Nov 2013 10:39:03 +0200 Subject: [PATCH 19/46] Added a functional test that verifies that two callables have the same argspec if they have the same number of positional arguments. --- .noseids | 21 ++++++++++++++++--- .../utils/test_are_argspecs_identical.py | 13 ++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/.noseids b/.noseids index 59d93a1..d568281 100644 --- a/.noseids +++ b/.noseids @@ -2,12 +2,27 @@ S'tests' p1 (dp2 -S'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' +S'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method contains a varargs argument' p3 +I4 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' +p4 +I2 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method contains a varargs argument' +p5 +I3 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' +p6 I1 ssS'ids' -p4 -(dp5 +p7 +(dp8 I1 +g6 +sI2 +g4 +sI3 +g5 +sI4 g3 ss. \ No newline at end of file diff --git a/tests/functional/utils/test_are_argspecs_identical.py b/tests/functional/utils/test_are_argspecs_identical.py index 4cbd52b..51f8b7e 100644 --- a/tests/functional/utils/test_are_argspecs_identical.py +++ b/tests/functional/utils/test_are_argspecs_identical.py @@ -20,4 +20,17 @@ def fake_callable2(a, k=mock.DEFAULT): case.assertTrue(actual) + @it.should( + 'return true if the argspecs are not completely identical but have the same number of positional arguments') + def test_should_return_true_if_the_argspecs_are_completely_identical_but_have_the_same_number_of_positional_arguments(case): + def fake_callable1(a): + pass + + def fake_callable2(b): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertTrue(actual) + it.createTests(globals()) \ No newline at end of file From 3d7589d7163a8fa885654c81c6904127420aa4f5 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sat, 2 Nov 2013 10:39:42 +0200 Subject: [PATCH 20/46] Added a functional test that verifies that two callables have the same argspec if one of them has an argument and the other has a varargs argument. --- .../utils/test_are_argspecs_identical.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/functional/utils/test_are_argspecs_identical.py b/tests/functional/utils/test_are_argspecs_identical.py index 51f8b7e..69b85be 100644 --- a/tests/functional/utils/test_are_argspecs_identical.py +++ b/tests/functional/utils/test_are_argspecs_identical.py @@ -33,4 +33,30 @@ def fake_callable2(b): case.assertTrue(actual) + @it.should( + 'return true if the argspecs are not completely identical but the first method contains a varargs argument') + def test_should_return_true_if_the_argspecs_are_completely_identical_but_the_first_method_contains_a_varargs_argument(case): + def fake_callable1(*args): + pass + + def fake_callable2(a): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertTrue(actual) + + @it.should( + 'return true if the argspecs are not completely identical but the second method contains a varargs argument') + def test_should_return_true_if_the_argspecs_are_completely_identical_but_the_second_method_contains_a_varargs_argument(case): + def fake_callable1(a): + pass + + def fake_callable2(*args): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertTrue(actual) + it.createTests(globals()) \ No newline at end of file From 3f3f018cf50e9d9e3aee41b9acebd5109e7b2cba Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sat, 2 Nov 2013 10:50:44 +0200 Subject: [PATCH 21/46] Added a functional test that verifies that two callables are not identical if one of them has no positional arguments and the other has a varargs argument. --- .noseids | 34 +++++++++++------- .../utils/test_are_argspecs_identical.py | 36 ++++++++++++++++--- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/.noseids b/.noseids index d568281..80664f0 100644 --- a/.noseids +++ b/.noseids @@ -2,27 +2,37 @@ S'tests' p1 (dp2 -S'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method contains a varargs argument' +S'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' p3 +I3 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no positional arguments and the second method has a varargs argument' +p4 +I6 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' +p5 I4 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' -p4 +p6 I2 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method contains a varargs argument' -p5 -I3 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' -p6 +p7 I1 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return false if the first method has a varargs argument and the second method has no positional arguments' +p8 +I5 ssS'ids' -p7 -(dp8 +p9 +(dp10 I1 -g6 +g7 sI2 -g4 +g6 sI3 -g5 -sI4 g3 +sI4 +g5 +sI5 +g8 +sI6 +g4 ss. \ No newline at end of file diff --git a/tests/functional/utils/test_are_argspecs_identical.py b/tests/functional/utils/test_are_argspecs_identical.py index 69b85be..6b4cbb0 100644 --- a/tests/functional/utils/test_are_argspecs_identical.py +++ b/tests/functional/utils/test_are_argspecs_identical.py @@ -22,7 +22,7 @@ def fake_callable2(a, k=mock.DEFAULT): @it.should( 'return true if the argspecs are not completely identical but have the same number of positional arguments') - def test_should_return_true_if_the_argspecs_are_completely_identical_but_have_the_same_number_of_positional_arguments(case): + def test_should_return_true_if_the_argspecs_are_not_completely_identical_but_have_the_same_number_of_positional_arguments(case): def fake_callable1(a): pass @@ -34,8 +34,8 @@ def fake_callable2(b): case.assertTrue(actual) @it.should( - 'return true if the argspecs are not completely identical but the first method contains a varargs argument') - def test_should_return_true_if_the_argspecs_are_completely_identical_but_the_first_method_contains_a_varargs_argument(case): + 'return true if the argspecs are not completely identical but the first method has a varargs argument') + def test_should_return_true_if_the_argspecs_are_not_completely_identical_but_the_first_method_has_a_varargs_argument(case): def fake_callable1(*args): pass @@ -47,8 +47,8 @@ def fake_callable2(a): case.assertTrue(actual) @it.should( - 'return true if the argspecs are not completely identical but the second method contains a varargs argument') - def test_should_return_true_if_the_argspecs_are_completely_identical_but_the_second_method_contains_a_varargs_argument(case): + 'return true if the argspecs are not completely identical but the second method has a varargs argument') + def test_should_return_true_if_the_argspecs_are_not_completely_identical_but_the_second_method_has_a_varargs_argument(case): def fake_callable1(a): pass @@ -58,5 +58,31 @@ def fake_callable2(*args): actual = are_argspecs_identical(fake_callable1, fake_callable2) case.assertTrue(actual) + + @it.should( + 'return false if the first method has a varargs argument and the second method has no positional arguments') + def test_should_return_false_if_the_first_method_has_a_varargs_argument_and_the_second_method_has_no_positional_arguments(case): + def fake_callable1(*args): + pass + + def fake_callable2(k=mock.DEFAULT): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertEqual(actual, False) + + @it.should( + 'return false if the first method has no positional arguments and the second method has a varargs argument') + def test_should_return_false_if_the_first_method_has_no_positional_arguments_and_the_second_method_has_a_varargs_argument(case): + def fake_callable1(k=mock.DEFAULT): + pass + + def fake_callable2(*args): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertEqual(actual, False) it.createTests(globals()) \ No newline at end of file From 8ffb9c9bec5757708a48868199062ff837307a81 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sat, 2 Nov 2013 11:02:00 +0200 Subject: [PATCH 22/46] Added a functional test that verifies that two callables are not identical if one of them has more positional arguments than the other. --- .../utils/test_are_argspecs_identical.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/functional/utils/test_are_argspecs_identical.py b/tests/functional/utils/test_are_argspecs_identical.py index 6b4cbb0..18b4b3a 100644 --- a/tests/functional/utils/test_are_argspecs_identical.py +++ b/tests/functional/utils/test_are_argspecs_identical.py @@ -85,4 +85,30 @@ def fake_callable2(*args): case.assertEqual(actual, False) + @it.should( + 'return false if the first method has a more positional arguments than the second method') + def test_should_return_false_if_the_first_method_has_more_positional_arguments_than_the_second_method(case): + def fake_callable1(a): + pass + + def fake_callable2(a, b): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertEqual(actual, False) + + @it.should( + 'return false if the second method has a more positional arguments than the first method') + def test_should_return_false_if_the_second_method_has_more_positional_arguments_than_the_first_method(case): + def fake_callable1(a, b): + pass + + def fake_callable2(a): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertEqual(actual, False) + it.createTests(globals()) \ No newline at end of file From 07238be4e14475faaa35881bf1232fbccf7728e4 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sat, 2 Nov 2013 11:10:32 +0200 Subject: [PATCH 23/46] Added a functional test that verifies that two callables are identical if both have the same keyword arguments. --- .noseids | 37 +++++++++++++------ .../utils/test_are_argspecs_identical.py | 18 +++++++-- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/.noseids b/.noseids index 80664f0..4376dfd 100644 --- a/.noseids +++ b/.noseids @@ -5,34 +5,49 @@ p1 S'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' p3 I3 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no positional arguments and the second method has a varargs argument' +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return false if the first method has no positional arguments and the second method has a varargs argument' p4 -I6 +I7 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' p5 I4 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return false if the first method has a varargs argument and the second method has no positional arguments' p6 +I6 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' +p7 I2 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' -p7 -I1 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return false if the first method has a varargs argument and the second method has no positional arguments' p8 +I1 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a more positional arguments than the second method' +p9 +I8 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the second method has a more positional arguments than the first method' +p10 +I9 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods contain exactly the same keyword arguments' +p11 I5 ssS'ids' -p9 -(dp10 +p12 +(dp13 I1 -g7 +g8 sI2 -g6 +g7 sI3 g3 sI4 g5 sI5 -g8 +g11 sI6 +g6 +sI7 g4 +sI8 +g9 +sI9 +g10 ss. \ No newline at end of file diff --git a/tests/functional/utils/test_are_argspecs_identical.py b/tests/functional/utils/test_are_argspecs_identical.py index 18b4b3a..a2ea91b 100644 --- a/tests/functional/utils/test_are_argspecs_identical.py +++ b/tests/functional/utils/test_are_argspecs_identical.py @@ -58,6 +58,18 @@ def fake_callable2(*args): actual = are_argspecs_identical(fake_callable1, fake_callable2) case.assertTrue(actual) + + @it.should("return true if both methods contain exactly the same keyword arguments") + def test_should_return_true_if_both_methods_contain_exactly_the_same_keyword_arguments(case): + def fake_callable1(a, k=mock.DEFAULT): + pass + + def fake_callable2(b, k=mock.DEFAULT): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertTrue(actual) @it.should( 'return false if the first method has a varargs argument and the second method has no positional arguments') @@ -85,8 +97,7 @@ def fake_callable2(*args): case.assertEqual(actual, False) - @it.should( - 'return false if the first method has a more positional arguments than the second method') + @it.should('return false if the first method has a more positional arguments than the second method') def test_should_return_false_if_the_first_method_has_more_positional_arguments_than_the_second_method(case): def fake_callable1(a): pass @@ -98,8 +109,7 @@ def fake_callable2(a, b): case.assertEqual(actual, False) - @it.should( - 'return false if the second method has a more positional arguments than the first method') + @it.should('return false if the second method has a more positional arguments than the first method') def test_should_return_false_if_the_second_method_has_more_positional_arguments_than_the_first_method(case): def fake_callable1(a, b): pass From 61e0367c05c8068c7112ac578ce191d184cddce1 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sat, 2 Nov 2013 11:35:49 +0200 Subject: [PATCH 24/46] Added a functional test that verifies that two callables are identical if one of the methods have keyword arguments and the other has a kwargs argument. Fixed a related bug where the positional arguments comparison function did not filter keyword arguments. --- .noseids | 354 ++++++++++++++++-- testdoubles/utils.py | 18 +- .../utils/test_are_argspecs_identical.py | 28 +- 3 files changed, 367 insertions(+), 33 deletions(-) diff --git a/.noseids b/.noseids index 4376dfd..5fe9139 100644 --- a/.noseids +++ b/.noseids @@ -2,52 +2,352 @@ S'tests' p1 (dp2 -S'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' +S'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' p3 -I3 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return false if the first method has no positional arguments and the second method has a varargs argument' +I6 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" p4 -I7 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' +I15 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p5 -I4 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return false if the first method has a varargs argument and the second method has no positional arguments' +I65 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' p6 -I6 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' +I19 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' p7 -I2 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' -p8 I1 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a more positional arguments than the second method' +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" +p8 +I13 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' p9 -I8 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the second method has a more positional arguments than the first method' +I69 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' p10 -I9 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods contain exactly the same keyword arguments' +I29 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' p11 +I62 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' +p12 +I55 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." +p13 +I16 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' +p14 +I42 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' +p15 +I17 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' +p16 +I54 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" +p17 +I52 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" +p18 +I10 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' +p19 +I23 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" +p20 +I11 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' +p21 +I30 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" +p22 +I60 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" +p23 +I50 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" +p24 +I8 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" +p25 +I48 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' +p26 +I25 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' +p27 +I22 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" +p28 +I9 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' +p29 +I28 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' +p30 +I33 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' +p31 +I21 +sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' +p32 +I53 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' +p33 +I67 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' +p34 +I45 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' +p35 +I35 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" +p36 +I47 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' +p37 +I64 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' +p38 +I2 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' +p39 +I24 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' +p40 +I34 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" +p41 +I61 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' +p42 +I66 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' +p43 +I32 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' +p44 +I56 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' +p45 +I43 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' +p46 +I63 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +p47 +I14 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a more positional arguments than the second method' +p48 +I26 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' +p49 +I38 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' +p50 I5 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a ValueError when the provided live object matches the argspec" +p51 +I49 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' +p52 +I40 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' +p53 +I57 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' +p54 +I37 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" +p55 +I51 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' +p56 +I3 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' +p57 +I41 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" +p58 +I46 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' +p59 +I39 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' +p60 +I59 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' +p61 +I31 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the second method has a more positional arguments than the first method' +p62 +I27 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' +p63 +I20 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' +p64 +I7 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' +p65 +I18 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' +p66 +I4 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' +p67 +I68 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' +p68 +I44 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' +p69 +I36 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" +p70 +I12 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' +p71 +I58 ssS'ids' -p12 -(dp13 +p72 +(dp73 I1 -g8 -sI2 g7 +sI2 +g38 sI3 -g3 +g56 sI4 -g5 +g66 sI5 -g11 +g50 sI6 -g6 +g3 sI7 -g4 +g64 sI8 -g9 +g24 sI9 +g28 +sI10 +g18 +sI11 +g20 +sI12 +g70 +sI13 +g8 +sI14 +g47 +sI15 +g4 +sI16 +g13 +sI17 +g15 +sI18 +g65 +sI19 +g6 +sI20 +g63 +sI21 +g31 +sI22 +g27 +sI23 +g19 +sI24 +g39 +sI25 +g26 +sI26 +g48 +sI27 +g62 +sI28 +g29 +sI29 g10 +sI30 +g21 +sI31 +g61 +sI32 +g43 +sI33 +g30 +sI34 +g40 +sI35 +g35 +sI36 +g69 +sI37 +g54 +sI38 +g49 +sI39 +g59 +sI40 +g52 +sI41 +g57 +sI42 +g14 +sI43 +g45 +sI44 +g68 +sI45 +g34 +sI46 +g58 +sI47 +g36 +sI48 +g25 +sI49 +g51 +sI50 +g23 +sI51 +g55 +sI52 +g17 +sI53 +g32 +sI54 +g16 +sI55 +g12 +sI56 +g44 +sI57 +g53 +sI58 +g71 +sI59 +g60 +sI60 +g22 +sI61 +g41 +sI62 +g11 +sI63 +g46 +sI64 +g37 +sI65 +g5 +sI66 +g42 +sI67 +g33 +sI68 +g67 +sI69 +g9 ss. \ No newline at end of file diff --git a/testdoubles/utils.py b/testdoubles/utils.py index c6a0900..06c534e 100644 --- a/testdoubles/utils.py +++ b/testdoubles/utils.py @@ -3,18 +3,28 @@ import inspect +def get_keyword_arguments(argspec): + return argspec.args[-len(argspec.defaults):] if argspec.defaults else [] + + def are_arguments_identical(argspec1, argspec2): - if len(argspec1.args) == len(argspec2.args) and not (argspec1.varargs or argspec2.varargs): + kwargs1 = get_keyword_arguments(argspec1) + kwargs2 = get_keyword_arguments(argspec2) + + arguments1 = set(argspec1.args) - set(kwargs1) + arguments2 = set(argspec2.args) - set(kwargs2) + + if len(arguments1) == len(arguments2) and not (argspec1.varargs or argspec2.varargs): return True - elif any(_ for _ in argspec1.args) and argspec2.varargs or any(_ for _ in argspec2.args) and argspec1.varargs: + elif any(_ for _ in arguments1) and argspec2.varargs or any(_ for _ in arguments2) and argspec1.varargs: return True return False def are_keyword_arguments_identical(argspec1, argspec2): - kwargs1 = argspec1.args[-len(argspec1.defaults):] if argspec1.defaults else [] - kwargs2 = argspec2.args[-len(argspec2.defaults):] if argspec2.defaults else [] + kwargs1 = get_keyword_arguments(argspec1) + kwargs2 = get_keyword_arguments(argspec2) if kwargs1 == kwargs2 and not (argspec1.keywords or argspec2.keywords): return True diff --git a/tests/functional/utils/test_are_argspecs_identical.py b/tests/functional/utils/test_are_argspecs_identical.py index a2ea91b..70b27ae 100644 --- a/tests/functional/utils/test_are_argspecs_identical.py +++ b/tests/functional/utils/test_are_argspecs_identical.py @@ -59,8 +59,8 @@ def fake_callable2(*args): case.assertTrue(actual) - @it.should("return true if both methods contain exactly the same keyword arguments") - def test_should_return_true_if_both_methods_contain_exactly_the_same_keyword_arguments(case): + @it.should("return true if both methods have exactly the same keyword arguments") + def test_should_return_true_if_both_methods_have_exactly_the_same_keyword_arguments(case): def fake_callable1(a, k=mock.DEFAULT): pass @@ -70,6 +70,30 @@ def fake_callable2(b, k=mock.DEFAULT): actual = are_argspecs_identical(fake_callable1, fake_callable2) case.assertTrue(actual) + + @it.should("return true if the first method has a kwargs argument and the second method has keyword arguments") + def test_should_return_true_if_the_first_method_has_a_kwargs_argument_and_the_second_method_has_keyword_arguments(case): + def fake_callable1(**kwargs): + pass + + def fake_callable2(k=mock.DEFAULT): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertTrue(actual) + + @it.should("return true if the first method has keyword arguments and the second method has a kwargs argument ") + def test_should_return_true_if_the_first_method_has_has_keyword_arguments_and_the_second_method_a_kwargs_argument(case): + def fake_callable1(k=mock.DEFAULT): + pass + + def fake_callable2(**kwargs): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertTrue(actual) @it.should( 'return false if the first method has a varargs argument and the second method has no positional arguments') From 293e938bbaf8519acd61b688bc1529791c3fb778 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 4 Nov 2013 12:51:34 +0200 Subject: [PATCH 25/46] Added a functional test that verifies that two callables are not identical if one of the methods has no keyword arguments and the other has a kwargs argument. --- .noseids | 368 +++++++++--------- .../utils/test_are_argspecs_identical.py | 25 ++ 2 files changed, 214 insertions(+), 179 deletions(-) diff --git a/.noseids b/.noseids index 5fe9139..1d0b4c3 100644 --- a/.noseids +++ b/.noseids @@ -10,344 +10,354 @@ p4 I15 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p5 -I65 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' +I67 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' p6 +I61 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' +p7 I19 sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' -p7 +p8 I1 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the second method has a more positional arguments than the first method' +p9 +I29 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" -p8 +p10 I13 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' -p9 -I69 +p11 +I71 sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' -p10 -I29 +p12 +I31 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' -p11 -I62 +p13 +I64 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' -p12 -I55 +p14 +I57 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." -p13 +p15 I16 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' -p14 -I42 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' -p15 +p16 I17 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' -p16 -I54 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p17 -I52 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" +I56 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p18 +I54 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" +p19 I10 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' -p19 +p20 I23 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" -p20 +p21 I11 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' -p21 -I30 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p22 -I60 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" +I32 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p23 +I62 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" +p24 I50 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" +p25 +I52 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" -p24 +p26 I8 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" -p25 -I48 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' +p27 +I26 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' -p26 +p28 I25 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' -p27 +p29 I22 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" -p28 +p30 I9 sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' -p29 -I28 +p31 +I30 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' -p30 -I33 +p32 +I35 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' -p31 +p33 I21 sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' -p32 -I53 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' -p33 -I67 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' p34 -I45 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' +I55 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' p35 -I35 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" +I69 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' p36 I47 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' p37 -I64 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' +I37 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" p38 +I49 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' +p39 +I66 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' +p40 I2 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' -p39 +p41 I24 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p40 -I34 +p42 +I36 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" -p41 -I61 +p43 +I63 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' -p42 -I66 +p44 +I68 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' -p43 -I32 +p45 +I34 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if the first method has a more positional arguments than the second method' +p46 +I28 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' -p44 -I56 +p47 +I58 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' -p45 -I43 +p48 +I45 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' -p46 -I63 +p49 +I65 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" -p47 +p50 I14 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a more positional arguments than the second method' -p48 -I26 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p49 -I38 +p51 +I40 sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p50 +p52 I5 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a ValueError when the provided live object matches the argspec" -p51 -I49 +p53 +I51 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' -p52 -I40 +p54 +I42 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' -p53 -I57 +p55 +I59 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' -p54 -I37 +p56 +I39 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" -p55 -I51 +p57 +I53 sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' -p56 +p58 I3 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' -p57 -I41 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" -p58 -I46 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' p59 -I39 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' +I43 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" p60 -I59 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' +I48 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' p61 -I31 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the second method has a more positional arguments than the first method' +I41 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' p62 I27 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' p63 +I33 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' +p64 +I44 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' +p65 I20 sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p64 +p66 I7 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' -p65 +p67 I18 sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p66 +p68 I4 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' -p67 -I68 +p69 +I70 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' -p68 -I44 +p70 +I46 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p69 -I36 +p71 +I38 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p70 +p72 I12 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p71 -I58 +p73 +I60 ssS'ids' -p72 -(dp73 +p74 +(dp75 I1 -g7 +g8 sI2 -g38 +g40 sI3 -g56 +g58 sI4 -g66 +g68 sI5 -g50 +g52 sI6 g3 sI7 -g64 +g66 sI8 -g24 +g26 sI9 -g28 +g30 sI10 -g18 +g19 sI11 -g20 +g21 sI12 -g70 +g72 sI13 -g8 +g10 sI14 -g47 +g50 sI15 g4 sI16 -g13 -sI17 g15 +sI17 +g16 sI18 -g65 +g67 sI19 -g6 +g7 sI20 -g63 +g65 sI21 -g31 +g33 sI22 -g27 +g29 sI23 -g19 +g20 sI24 -g39 +g41 sI25 -g26 +g28 sI26 -g48 +g27 sI27 g62 sI28 -g29 +g46 sI29 -g10 +g9 sI30 -g21 +g31 sI31 -g61 +g12 sI32 -g43 +g22 sI33 -g30 +g63 sI34 -g40 +g45 sI35 -g35 +g32 sI36 -g69 +g42 sI37 -g54 +g37 sI38 -g49 +g71 sI39 -g59 +g56 sI40 -g52 +g51 sI41 -g57 +g61 sI42 -g14 +g54 sI43 -g45 +g59 sI44 -g68 +g64 sI45 -g34 +g48 sI46 -g58 +g70 sI47 g36 sI48 -g25 +g60 sI49 -g51 +g38 sI50 -g23 +g24 sI51 -g55 +g53 sI52 -g17 +g25 sI53 -g32 +g57 sI54 -g16 +g18 sI55 -g12 +g34 sI56 -g44 +g17 sI57 -g53 +g14 sI58 -g71 +g47 sI59 -g60 +g55 sI60 -g22 +g73 sI61 -g41 +g6 sI62 -g11 +g23 sI63 -g46 +g43 sI64 -g37 +g13 sI65 -g5 +g49 sI66 -g42 +g39 sI67 -g33 +g5 sI68 -g67 +g44 sI69 -g9 +g35 +sI70 +g69 +sI71 +g11 ss. \ No newline at end of file diff --git a/tests/functional/utils/test_are_argspecs_identical.py b/tests/functional/utils/test_are_argspecs_identical.py index 70b27ae..3d7eea1 100644 --- a/tests/functional/utils/test_are_argspecs_identical.py +++ b/tests/functional/utils/test_are_argspecs_identical.py @@ -121,6 +121,31 @@ def fake_callable2(*args): case.assertEqual(actual, False) + @it.should('return false if the first method has a kwargs argument and the second method has no keyword arguments') + def test_should_return_false_if_the_first_method_has_a_kwargs_argument_and_the_second_method_has_no_keyword_arguments(case): + def fake_callable1(b, **kwargs): + pass + + def fake_callable2(a): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertEqual(actual, False) + + @it.should( + 'return false if the first method has no keyword arguments and the second method has a kwargs argument') + def test_should_return_false_if_the_first_method_has_no_keyword_arguments_and_the_second_method_has_a_kwargs_argument(case): + def fake_callable1(a): + pass + + def fake_callable2(b, **kwargs): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertEqual(actual, False) + @it.should('return false if the first method has a more positional arguments than the second method') def test_should_return_false_if_the_first_method_has_more_positional_arguments_than_the_second_method(case): def fake_callable1(a): From f70e6a3e110decde6bf5a2f2c657503f4a873ca1 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 4 Nov 2013 12:58:04 +0200 Subject: [PATCH 26/46] Added a functional test that verifies that two callables with different keyword arguments don't have identical argspecs. --- .noseids | 357 +++++++++--------- .../utils/test_are_argspecs_identical.py | 12 + 2 files changed, 193 insertions(+), 176 deletions(-) diff --git a/.noseids b/.noseids index 1d0b4c3..ee89635 100644 --- a/.noseids +++ b/.noseids @@ -10,354 +10,359 @@ p4 I15 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p5 -I67 +I68 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' p6 -I61 +I62 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' p7 I19 sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' p8 I1 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the second method has a more positional arguments than the first method' -p9 -I29 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" -p10 +p9 I13 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' -p11 -I71 +p10 +I72 sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' -p12 -I31 +p11 +I32 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' -p13 -I64 +p12 +I65 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' -p14 -I57 +p13 +I58 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." -p15 +p14 I16 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' -p16 +p15 I17 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' -p17 -I56 +p16 +I57 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" -p18 -I54 +p17 +I55 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" -p19 +p18 I10 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' -p20 +p19 I23 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" -p21 +p20 I11 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' -p22 -I32 +p21 +I33 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" -p23 -I62 +p22 +I63 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" -p24 -I50 +p23 +I51 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" -p25 -I52 +p24 +I53 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" -p26 +p25 I8 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' -p27 +p26 I26 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' -p28 +p27 I25 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' -p29 +p28 I22 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" -p30 +p29 I9 sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' -p31 -I30 +p30 +I31 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' -p32 -I35 +p31 +I36 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' -p33 +p32 I21 sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' -p34 -I55 +p33 +I56 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' -p35 -I69 +p34 +I70 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' -p36 -I47 +p35 +I48 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' -p37 -I37 +p36 +I38 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" -p38 -I49 +p37 +I50 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' -p39 -I66 +p38 +I67 sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' -p40 +p39 I2 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' -p41 +p40 I24 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p42 -I36 +p41 +I37 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" -p43 -I63 +p42 +I64 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' +p43 +I69 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' p44 -I68 +I30 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' p45 -I34 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if the first method has a more positional arguments than the second method' -p46 -I28 +I35 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' -p47 -I58 +p46 +I59 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' -p48 -I45 +p47 +I46 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' -p49 -I65 +p48 +I66 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" -p50 +p49 I14 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p51 -I40 +p50 +I41 sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p52 +p51 I5 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a ValueError when the provided live object matches the argspec" +p52 +I52 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' p53 -I51 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' -p54 -I42 +I28 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' -p55 -I59 +p54 +I60 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' -p56 -I39 +p55 +I40 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" -p57 -I53 +p56 +I54 sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' -p58 +p57 I3 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' +p58 +I43 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' p59 -I43 +I44 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" p60 -I48 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' +I49 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' p61 -I41 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' +I29 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' p62 +I42 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' +p63 I27 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p63 -I33 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' p64 -I44 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' +I34 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' p65 +I45 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' +p66 I20 sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p66 +p67 I7 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' -p67 +p68 I18 sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p68 +p69 I4 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' -p69 -I70 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' p70 -I46 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' +I71 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' p71 -I38 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" +I47 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' p72 +I39 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" +p73 I12 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p73 -I60 -ssS'ids' p74 -(dp75 +I61 +ssS'ids' +p75 +(dp76 I1 g8 sI2 -g40 +g39 sI3 -g58 +g57 sI4 -g68 +g69 sI5 -g52 +g51 sI6 g3 sI7 -g66 +g67 sI8 -g26 +g25 sI9 -g30 +g29 sI10 -g19 +g18 sI11 -g21 +g20 sI12 -g72 +g73 sI13 -g10 +g9 sI14 -g50 +g49 sI15 g4 sI16 -g15 +g14 sI17 -g16 +g15 sI18 -g67 +g68 sI19 g7 sI20 -g65 +g66 sI21 -g33 +g32 sI22 -g29 +g28 sI23 -g20 +g19 sI24 -g41 +g40 sI25 -g28 -sI26 g27 +sI26 +g26 sI27 -g62 +g63 sI28 -g46 +g53 sI29 -g9 +g61 sI30 -g31 +g44 sI31 -g12 +g30 sI32 -g22 +g11 sI33 -g63 +g21 sI34 -g45 +g64 sI35 -g32 +g45 sI36 -g42 +g31 sI37 -g37 +g41 sI38 -g71 +g36 sI39 -g56 +g72 sI40 -g51 +g55 sI41 -g61 +g50 sI42 -g54 +g62 sI43 -g59 +g58 sI44 -g64 +g59 sI45 -g48 +g65 sI46 -g70 +g47 sI47 -g36 +g71 sI48 -g60 +g35 sI49 -g38 +g60 sI50 -g24 +g37 sI51 -g53 +g23 sI52 -g25 +g52 sI53 -g57 +g24 sI54 -g18 +g56 sI55 -g34 -sI56 g17 +sI56 +g33 sI57 -g14 +g16 sI58 -g47 +g13 sI59 -g55 +g46 sI60 -g73 +g54 sI61 -g6 +g74 sI62 -g23 +g6 sI63 -g43 +g22 sI64 -g13 +g42 sI65 -g49 +g12 sI66 -g39 +g48 sI67 -g5 +g38 sI68 -g44 +g5 sI69 -g35 +g43 sI70 -g69 +g34 sI71 -g11 +g70 +sI72 +g10 ss. \ No newline at end of file diff --git a/tests/functional/utils/test_are_argspecs_identical.py b/tests/functional/utils/test_are_argspecs_identical.py index 3d7eea1..89f1925 100644 --- a/tests/functional/utils/test_are_argspecs_identical.py +++ b/tests/functional/utils/test_are_argspecs_identical.py @@ -146,6 +146,18 @@ def fake_callable2(b, **kwargs): case.assertEqual(actual, False) + @it.should('return false if both methods have different keyword arguments') + def test_should_return_false_if_both_methods_have_different_keyword_arguments(case): + def fake_callable1(b, k=mock.DEFAULT): + pass + + def fake_callable2(a, kk=mock.DEFAULT): + pass + + actual = are_argspecs_identical(fake_callable1, fake_callable2) + + case.assertEqual(actual, False) + @it.should('return false if the first method has a more positional arguments than the second method') def test_should_return_false_if_the_first_method_has_more_positional_arguments_than_the_second_method(case): def fake_callable1(a): From 73c97d2a24c0a55fc2ae40cdb34b5d576dc7fb40 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 4 Nov 2013 13:04:03 +0200 Subject: [PATCH 27/46] Just replaced the positional arguments' names to keep consistency. --- .noseids | 375 +++++++++--------- .../utils/test_are_argspecs_identical.py | 4 +- 2 files changed, 192 insertions(+), 187 deletions(-) diff --git a/.noseids b/.noseids index ee89635..552bae2 100644 --- a/.noseids +++ b/.noseids @@ -10,43 +10,43 @@ p4 I15 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p5 -I68 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' -p6 -I62 +I69 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' -p7 +p6 I19 sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' -p8 +p7 I1 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" -p9 +p8 I13 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' -p10 -I72 +p9 +I73 sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' -p11 -I32 +p10 +I33 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' -p12 -I65 +p11 +I66 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' -p13 -I58 +p12 +I59 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." -p14 +p13 I16 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' +p14 +I43 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' p15 I17 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' p16 -I57 +I58 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p17 -I55 +I56 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" p18 I10 @@ -56,313 +56,318 @@ I23 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" p20 I11 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return true if both methods have different keyword arguments but the second has a kwargs argument' p21 -I33 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" +I24 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" p22 -I63 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" +I65 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p23 -I51 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" +I64 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" p24 -I53 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" +I52 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" p25 -I8 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' +I54 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" p26 -I26 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' +I8 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" p27 -I25 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' +I55 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the first method has a more positional arguments than the second method' p28 +I30 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' +p29 I22 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" -p29 +p30 I9 sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' -p30 -I31 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' p31 -I36 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' +I32 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' p32 +I37 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' +p33 I21 sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' -p33 -I56 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' p34 -I70 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' +I57 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' p35 -I48 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' +I71 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if both methods have different keyword arguments' p36 -I38 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" +I29 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' p37 -I50 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' +I49 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has a kwargs argument and the second method has no keyword arguments' p38 -I67 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' +I27 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' p39 -I2 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' +I39 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" p40 -I24 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' +I51 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' p41 -I37 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" +I68 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' p42 -I64 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' +I2 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' p43 -I69 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' +I38 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' p44 -I30 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' +I34 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' p45 -I35 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' +I70 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' p46 -I59 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' +I36 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' p47 -I46 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' +I60 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' p48 -I66 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +I47 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' p49 +I67 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +p50 I14 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' +p51 +I48 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p50 -I41 +p52 +I42 sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p51 +p53 I5 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a ValueError when the provided live object matches the argspec" -p52 -I52 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' -p53 -I28 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' p54 -I60 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' +I53 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' p55 -I40 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" +I44 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0014: should return false if the second method has a more positional arguments than the first method' p56 -I54 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' +I31 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' p57 -I3 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' +I41 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has no positional arguments and the second method has a varargs argument' p58 -I43 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' +I26 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' p59 -I44 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" +I61 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' p60 -I49 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' +I3 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' p61 -I29 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' +I45 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" p62 -I42 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' +I50 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if the first method has no keyword arguments and the second method has a kwargs argument' p63 -I27 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' +I28 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' p64 -I34 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' +I63 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' p65 -I45 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' +I35 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' p66 +I46 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' +p67 I20 sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p67 +p68 I7 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' -p68 +p69 I18 sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p69 +p70 I4 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' -p70 -I71 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' p71 -I47 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' +I72 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has a varargs argument and the second method has no positional arguments' p72 -I39 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" +I25 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' p73 +I40 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" +p74 I12 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p74 -I61 -ssS'ids' p75 -(dp76 +I62 +ssS'ids' +p76 +(dp77 I1 -g8 +g7 sI2 -g39 +g42 sI3 -g57 +g60 sI4 -g69 +g70 sI5 -g51 +g53 sI6 g3 sI7 -g67 +g68 sI8 -g25 +g26 sI9 -g29 +g30 sI10 g18 sI11 g20 sI12 -g73 +g74 sI13 -g9 +g8 sI14 -g49 +g50 sI15 g4 sI16 -g14 +g13 sI17 g15 sI18 -g68 +g69 sI19 -g7 +g6 sI20 -g66 +g67 sI21 -g32 +g33 sI22 -g28 +g29 sI23 g19 sI24 -g40 +g21 sI25 -g27 +g72 sI26 -g26 +g58 sI27 -g63 +g38 sI28 -g53 +g63 sI29 -g61 +g36 sI30 -g44 +g28 sI31 -g30 +g56 sI32 -g11 +g31 sI33 -g21 +g10 sI34 -g64 +g44 sI35 -g45 +g65 sI36 -g31 +g46 sI37 -g41 +g32 sI38 -g36 +g43 sI39 -g72 +g39 sI40 -g55 +g73 sI41 -g50 +g57 sI42 -g62 +g52 sI43 -g58 +g14 sI44 -g59 +g55 sI45 -g65 +g61 sI46 -g47 +g66 sI47 -g71 +g48 sI48 -g35 +g51 sI49 -g60 -sI50 g37 +sI50 +g62 sI51 -g23 +g40 sI52 -g52 -sI53 g24 +sI53 +g54 sI54 -g56 +g25 sI55 -g17 +g27 sI56 -g33 +g17 sI57 -g16 +g34 sI58 -g13 +g16 sI59 -g46 +g12 sI60 -g54 +g47 sI61 -g74 +g59 sI62 -g6 +g75 sI63 -g22 +g64 sI64 -g42 +g23 sI65 -g12 +g22 sI66 -g48 +g11 sI67 -g38 +g49 sI68 -g5 +g41 sI69 -g43 +g5 sI70 -g34 +g45 sI71 -g70 +g35 sI72 -g10 +g71 +sI73 +g9 ss. \ No newline at end of file diff --git a/tests/functional/utils/test_are_argspecs_identical.py b/tests/functional/utils/test_are_argspecs_identical.py index 89f1925..4bb41e8 100644 --- a/tests/functional/utils/test_are_argspecs_identical.py +++ b/tests/functional/utils/test_are_argspecs_identical.py @@ -148,10 +148,10 @@ def fake_callable2(b, **kwargs): @it.should('return false if both methods have different keyword arguments') def test_should_return_false_if_both_methods_have_different_keyword_arguments(case): - def fake_callable1(b, k=mock.DEFAULT): + def fake_callable1(a, k=mock.DEFAULT): pass - def fake_callable2(a, kk=mock.DEFAULT): + def fake_callable2(b, kk=mock.DEFAULT): pass actual = are_argspecs_identical(fake_callable1, fake_callable2) From ca361e21a9df932575d2ec4cf9ecb01eb4b8b72a Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 4 Nov 2013 13:45:14 +0200 Subject: [PATCH 28/46] Improved code readability for fake callable unit tests. --- .noseids | 375 ++++++++++++------------- tests/unit/fakes/support/fakes.py | 10 + tests/unit/fakes/support/mocks.py | 20 ++ tests/unit/fakes/support/stubs.py | 52 ++++ tests/unit/fakes/test_fake_callable.py | 226 ++++----------- 5 files changed, 315 insertions(+), 368 deletions(-) create mode 100644 tests/unit/fakes/support/fakes.py create mode 100644 tests/unit/fakes/support/mocks.py create mode 100644 tests/unit/fakes/support/stubs.py diff --git a/.noseids b/.noseids index 552bae2..ee89635 100644 --- a/.noseids +++ b/.noseids @@ -10,43 +10,43 @@ p4 I15 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p5 -I69 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' +I68 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' p6 +I62 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' +p7 I19 sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' -p7 +p8 I1 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" -p8 +p9 I13 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' -p9 -I73 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' p10 -I33 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' +I72 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' p11 -I66 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' +I32 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' p12 -I59 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." +I65 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' p13 -I16 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' +I58 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." p14 -I43 +I16 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' p15 I17 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' p16 -I58 +I57 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p17 -I56 +I55 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" p18 I10 @@ -56,318 +56,313 @@ I23 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" p20 I11 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return true if both methods have different keyword arguments but the second has a kwargs argument' +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' p21 -I24 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" -p22 -I65 +I33 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" -p23 -I64 +p22 +I63 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" -p24 -I52 +p23 +I51 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" -p25 -I54 +p24 +I53 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" -p26 +p25 I8 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' +p26 +I26 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' p27 -I55 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the first method has a more positional arguments than the second method' -p28 -I30 +I25 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' -p29 +p28 I22 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" -p30 +p29 I9 sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' -p31 -I32 +p30 +I31 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' -p32 -I37 +p31 +I36 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' -p33 +p32 I21 sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' -p34 -I57 +p33 +I56 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' +p34 +I70 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' p35 -I71 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if both methods have different keyword arguments' +I48 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' p36 -I29 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' +I38 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" p37 -I49 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has a kwargs argument and the second method has no keyword arguments' +I50 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' p38 -I27 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' +I67 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' p39 -I39 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" +I2 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' p40 -I51 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' +I24 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' p41 -I68 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' +I37 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" p42 -I2 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' +I64 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' p43 -I38 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' +I69 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' p44 -I34 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' -p45 -I70 +I30 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' -p46 -I36 +p45 +I35 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' -p47 -I60 +p46 +I59 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' -p48 -I47 +p47 +I46 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' -p49 -I67 +p48 +I66 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" -p50 +p49 I14 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' -p51 -I48 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p52 -I42 +p50 +I41 sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p53 +p51 I5 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a ValueError when the provided live object matches the argspec" +p52 +I52 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' +p53 +I28 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' p54 -I53 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' +I60 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' p55 -I44 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0014: should return false if the second method has a more positional arguments than the first method' +I40 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" p56 -I31 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' +I54 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' p57 -I41 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has no positional arguments and the second method has a varargs argument' +I3 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' p58 -I26 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' +I43 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' p59 -I61 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' +I44 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" p60 -I3 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' +I49 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' p61 -I45 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" +I29 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' p62 -I50 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if the first method has no keyword arguments and the second method has a kwargs argument' +I42 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' p63 -I28 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' -p64 -I63 +I27 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p65 -I35 +p64 +I34 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' -p66 -I46 +p65 +I45 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' -p67 +p66 I20 sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p68 +p67 I7 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' -p69 +p68 I18 sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p70 +p69 I4 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' +p70 +I71 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' p71 -I72 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has a varargs argument and the second method has no positional arguments' -p72 -I25 +I47 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p73 -I40 +p72 +I39 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p74 +p73 I12 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p75 -I62 +p74 +I61 ssS'ids' -p76 -(dp77 +p75 +(dp76 I1 -g7 +g8 sI2 -g42 +g39 sI3 -g60 +g57 sI4 -g70 +g69 sI5 -g53 +g51 sI6 g3 sI7 -g68 +g67 sI8 -g26 +g25 sI9 -g30 +g29 sI10 g18 sI11 g20 sI12 -g74 +g73 sI13 -g8 +g9 sI14 -g50 +g49 sI15 g4 sI16 -g13 +g14 sI17 g15 sI18 -g69 +g68 sI19 -g6 +g7 sI20 -g67 +g66 sI21 -g33 +g32 sI22 -g29 +g28 sI23 g19 sI24 -g21 +g40 sI25 -g72 +g27 sI26 -g58 +g26 sI27 -g38 -sI28 g63 +sI28 +g53 sI29 -g36 +g61 sI30 -g28 +g44 sI31 -g56 +g30 sI32 -g31 +g11 sI33 -g10 +g21 sI34 -g44 +g64 sI35 -g65 +g45 sI36 -g46 +g31 sI37 -g32 +g41 sI38 -g43 +g36 sI39 -g39 +g72 sI40 -g73 +g55 sI41 -g57 +g50 sI42 -g52 +g62 sI43 -g14 +g58 sI44 -g55 +g59 sI45 -g61 +g65 sI46 -g66 +g47 sI47 -g48 +g71 sI48 -g51 +g35 sI49 -g37 +g60 sI50 -g62 +g37 sI51 -g40 +g23 sI52 -g24 +g52 sI53 -g54 +g24 sI54 -g25 +g56 sI55 -g27 -sI56 g17 +sI56 +g33 sI57 -g34 -sI58 g16 +sI58 +g13 sI59 -g12 +g46 sI60 -g47 +g54 sI61 -g59 +g74 sI62 -g75 +g6 sI63 -g64 +g22 sI64 -g23 +g42 sI65 -g22 +g12 sI66 -g11 +g48 sI67 -g49 +g38 sI68 -g41 -sI69 g5 +sI69 +g43 sI70 -g45 +g34 sI71 -g35 +g70 sI72 -g71 -sI73 -g9 +g10 ss. \ No newline at end of file diff --git a/tests/unit/fakes/support/fakes.py b/tests/unit/fakes/support/fakes.py new file mode 100644 index 0000000..d1627b6 --- /dev/null +++ b/tests/unit/fakes/support/fakes.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import mock + + +def fake_real_callable(): + mocked_callable = mock.MagicMock() + self = mock.PropertyMock() + type(mocked_callable).__self__ = self + return mocked_callable, self \ No newline at end of file diff --git a/tests/unit/fakes/support/mocks.py b/tests/unit/fakes/support/mocks.py new file mode 100644 index 0000000..f653eb4 --- /dev/null +++ b/tests/unit/fakes/support/mocks.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from testdoubles.fakes import callables + + +def mock_are_argspecs_identical(case, mocked_are_argspecs_identical): + try: + old_init_globals = callables.FakeCallable.__init__.__globals__ + callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = mocked_are_argspecs_identical + except AttributeError: + old_init_globals = callables.FakeCallable.__init__.func_globals + callables.FakeCallable.__init__.func_globals['are_argspecs_identical'] = mocked_are_argspecs_identical + case.old_init_globals = old_init_globals + + +def unmock_are_argspecs_identical(case): + try: + callables.FakeCallable.__init__.__globals__.update(case.old_init_globals) + except AttributeError: + callables.FakeCallable.__init__.func_globals.update(case.old_init_globals) \ No newline at end of file diff --git a/tests/unit/fakes/support/stubs.py b/tests/unit/fakes/support/stubs.py new file mode 100644 index 0000000..48ef648 --- /dev/null +++ b/tests/unit/fakes/support/stubs.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from imp import reload +import sys +import mock +from testdoubles.fakes import callables + + +def stub_callable(case, return_value): + try: + case.old_callable = __builtins__['callable'] + __builtins__['callable'] = lambda c: return_value + except TypeError: + case.old_callable = __builtins__.callable + __builtins__.callable = lambda c: return_value + + +def unstub_callable(case): + try: + __builtins__['callable'] = case.old_callable + except TypeError: + __builtins__.callable = case.old_callable + + +def stub_are_argspecs_identical(case, return_value): + try: + old_init_globals = callables.FakeCallable.__init__.__globals__ + callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = lambda _, __: return_value + except AttributeError: + old_init_globals = callables.FakeCallable.__init__.func_globals + callables.FakeCallable.__init__.func_globals['are_argspecs_identical'] = lambda _, __: return_value + case.old_init_globals = old_init_globals + + +def unstub_are_argspecs_identical(case): + try: + callables.FakeCallable.__init__.__globals__.update(case.old_init_globals) + except AttributeError: + callables.FakeCallable.__init__.func_globals.update(case.old_init_globals) + + +def stub_python_version(case, major_version): + stubbed_sys = mock.MagicMock() + stubbed_sys.version_info = (major_version, ) + case.patch_python_version = mock.patch.dict(sys.modules, sys=stubbed_sys) + case.patch_python_version.start() + reload(callables) + + +def unstub_python_version(case): + case.patch_python_version.stop() + reload(callables) \ No newline at end of file diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 4f496f0..355c392 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -1,32 +1,25 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from imp import reload -import sys from nose2.tools import such from testdoubles.fakes import callables from tests.common.compat import mock from tests.common.layers import UnitTestsLayer +from tests.unit.fakes.support.fakes import fake_real_callable +from tests.unit.fakes.support.mocks import mock_are_argspecs_identical, unmock_are_argspecs_identical +from tests.unit.fakes.support.stubs import stub_callable, unstub_callable, stub_are_argspecs_identical, unstub_are_argspecs_identical, stub_python_version, unstub_python_version with such.A("Fake Function object") as it: it.uses(UnitTestsLayer) @it.has_test_setup def setup(case): - try: - case.old_callable = __builtins__['callable'] - __builtins__['callable'] = lambda c: True - except TypeError: - case.old_callable = __builtins__.callable - __builtins__.callable = lambda c: True + stub_callable(case, True) @it.has_test_teardown def teardown(case): - try: - __builtins__['callable'] = case.old_callable - except TypeError: - __builtins__.callable = case.old_callable + unstub_callable(case) @it.should("be callable") def test_should_be_callable(case): @@ -40,67 +33,39 @@ def test_should_be_callable(case): @it.has_test_setup def setup(case): - try: - case.old_callable = __builtins__['callable'] - __builtins__['callable'] = lambda c: True - except TypeError: - case.old_callable = __builtins__.callable - __builtins__.callable = lambda c: True + stub_callable(case, True) @it.has_test_teardown def teardown(case): - try: - __builtins__['callable'] = case.old_callable - except TypeError: - __builtins__.callable = case.old_callable + unstub_callable(case) @it.should("raise a ValueError when the provided live object does not match the argspec") def test_should_raise_a_ValueError_when_the_provided_live_object_does_not_match_the_argspec(case): - try: - old_init_globals = callables.FakeCallable.__init__.__globals__ - callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = lambda _, __: False - except AttributeError: - old_init_globals = callables.FakeCallable.__init__.func_globals - callables.FakeCallable.__init__.func_globals['are_argspecs_identical'] = lambda _, __: False + stub_are_argspecs_identical(case, False) - with case.assertRaisesRegexp(ValueError, r"The provided live object's arguments ArgSpec\((?:[a-zA-Z1-9_]+=.+(?:, |(?=\))))+\) does not match ArgSpec\((?:[a-zA-Z1-9_]+=.+(?:, |(?=\))))+\)"): + with case.assertRaisesRegexp(ValueError, + r"The provided live object's arguments ArgSpec\((?:[a-zA-Z1-9_]+=.+(?:, |(?=\))))+\) does not match ArgSpec\((?:[a-zA-Z1-9_]+=.+(?:, |(?=\))))+\)"): with mock.patch('inspect.getargspec', return_value='ArgSpec(a=None)'): callables.FakeCallable(mock.DEFAULT, inspect_args=True) - try: - callables.FakeCallable.__init__.__globals__.update(old_init_globals) - except AttributeError: - callables.FakeCallable.__init__.func_globals.update(old_init_globals) + unstub_are_argspecs_identical(case) @it.should("not raise a ValueError when the provided live object matches the argspec") def test_should_not_raise_a_ValueError_when_the_provided_live_object_matches_the_argspec(case): - try: - old_init_globals = callables.FakeCallable.__init__.__globals__ - callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = lambda _, __: True - except AttributeError: - old_init_globals = callables.FakeCallable.__init__.func_globals - callables.FakeCallable.__init__.func_globals['are_argspecs_identical'] = lambda _, __: True + stub_are_argspecs_identical(case, True) try: callables.FakeCallable(mock.DEFAULT, inspect_args=True) except ValueError: case.fail() - try: - callables.FakeCallable.__init__.__globals__.update(old_init_globals) - except AttributeError: - callables.FakeCallable.__init__.func_globals.update(old_init_globals) + unstub_are_argspecs_identical(case) @it.should("not inspect the argspec of the live object when argument inspection is opted out") def test_should_not_inspect_the_argspec_of_the_live_object_when_argument_inspection_is_opted_out(case): mocked_are_argspecs_identical = mock.Mock() - try: - old_init_globals = callables.FakeCallable.__init__.__globals__ - callables.FakeCallable.__init__.__globals__['are_argspecs_identical'] = mocked_are_argspecs_identical - except AttributeError: - old_init_globals = callables.FakeCallable.__init__.func_globals - callables.FakeCallable.__init__.func_globals['are_argspecs_identical'] = mocked_are_argspecs_identical + mock_are_argspecs_identical(case, mocked_are_argspecs_identical) try: callables.FakeCallable(mock.DEFAULT, inspect_args=False) @@ -109,10 +74,7 @@ def test_should_not_inspect_the_argspec_of_the_live_object_when_argument_inspect mocked_are_argspecs_identical.assert_has_calls([]) - try: - callables.FakeCallable.__init__.__globals__.update(old_init_globals) - except AttributeError: - callables.FakeCallable.__init__.func_globals.update(old_init_globals) + unmock_are_argspecs_identical(case) it.createTests(globals()) @@ -121,19 +83,11 @@ def test_should_not_inspect_the_argspec_of_the_live_object_when_argument_inspect @it.has_test_setup def setup(case): - try: - case.old_callable = __builtins__['callable'] - __builtins__['callable'] = lambda c: True - except TypeError: - case.old_callable = __builtins__.callable - __builtins__.callable = lambda c: True + stub_callable(case, True) @it.has_test_teardown def teardown(case): - try: - __builtins__['callable'] = case.old_callable - except TypeError: - __builtins__.callable = case.old_callable + unstub_callable(case) @it.should("have a read only property named live") def test_should_have_a_read_only_property_named_live(case): @@ -155,19 +109,11 @@ def test_should_have_a_read_only_property_named_live(case): @it.has_test_setup def setup(case): - try: - case.old_callable = __builtins__['callable'] - __builtins__['callable'] = lambda c: True - except TypeError: - case.old_callable = __builtins__.callable - __builtins__.callable = lambda c: True + stub_callable(case, True) @it.has_test_teardown def teardown(case): - try: - __builtins__['callable'] = case.old_callable - except TypeError: - __builtins__.callable = case.old_callable + unstub_callable(case) @it.should("have a read only property named fake") def test_should_have_a_read_only_property_named_live(case): @@ -190,35 +136,18 @@ def test_should_have_a_read_only_property_named_live(case): with it.having('a python 3.x runtime1'): @it.has_test_setup def setup(case): - stubbed_sys = mock.MagicMock() - stubbed_sys.version_info = (3, ) - - case.patch_python_version = mock.patch.dict(sys.modules, sys=stubbed_sys) - case.patch_python_version.start() + stub_python_version(case, 3) - reload(callables) - - try: - case.old_callable = __builtins__['callable'] - __builtins__['callable'] = lambda c: True - except TypeError: - case.old_callable = __builtins__.callable - __builtins__.callable = lambda c: True + stub_callable(case, True) @it.has_test_teardown def teardown(case): - case.patch_python_version.stop() - - reload(callables) + unstub_python_version(case) - try: - __builtins__['callable'] = case.old_callable - except TypeError: - __builtins__.callable = case.old_callable + unstub_callable(case) @it.should("return true if the live function is an instance method") def test_should_return_true_if_the_live_function_is_an_instance_method(case): - sut = callables.FakeCallable(mock.DEFAULT) with mock.patch('inspect.ismethod', return_value=True): with mock.patch('inspect.getargspec', return_value=([], )): @@ -249,31 +178,15 @@ def test_should_return_false_if_the_live_function_is_not_an_instance_method(case with it.having('a python 2.x runtime1'): @it.has_test_setup def setup(case): - stubbed_sys = mock.MagicMock() - stubbed_sys.version_info = (2, ) - - case.patch_python_version = mock.patch.dict(sys.modules, sys=stubbed_sys) - case.patch_python_version.start() - - reload(callables) + stub_python_version(case, 2) - try: - case.old_callable = __builtins__['callable'] - __builtins__['callable'] = lambda c: True - except TypeError: - case.old_callable = __builtins__.callable - __builtins__.callable = lambda c: True + stub_callable(case, True) @it.has_test_teardown def teardown(case): - case.patch_python_version.stop() + unstub_python_version(case) - reload(callables) - - try: - __builtins__['callable'] = case.old_callable - except TypeError: - __builtins__.callable = case.old_callable + unstub_callable(case) @it.should("return true if the live function is an instance method") def test_should_return_true_if_the_live_function_is_an_instance_method(case): @@ -287,14 +200,12 @@ def test_should_return_true_if_the_live_function_is_an_instance_method(case): @it.should("return true if the live function is an unbound instance method") def test_should_return_true_if_the_live_function_is_an_unbound_instance_method(case): - mocked_callable = mock.MagicMock() - self = mock.PropertyMock() - self.return_value = False - type(mocked_callable).__self__ = self + mocked_callable, self = fake_real_callable() + sut = callables.FakeCallable(mocked_callable) with mock.patch('inspect.ismethod', return_value=True): - actual = sut.is_instance_method + actual = sut.is_instance_method case.assertTrue(actual) @@ -316,31 +227,15 @@ def test_should_return_false_if_the_live_function_is_not_an_instance_method(case with it.having('a python 3.x runtime'): @it.has_test_setup def setup(case): - stubbed_sys = mock.MagicMock() - stubbed_sys.version_info = (3, ) - - case.patch_python_version = mock.patch.dict(sys.modules, sys=stubbed_sys) - case.patch_python_version.start() + stub_python_version(case, 3) - reload(callables) - - try: - case.old_callable = __builtins__['callable'] - __builtins__['callable'] = lambda c: True - except TypeError: - case.old_callable = __builtins__.callable - __builtins__.callable = lambda c: True + stub_callable(case, True) @it.has_test_teardown def teardown(case): - case.patch_python_version.stop() - - reload(callables) + unstub_python_version(case) - try: - __builtins__['callable'] = case.old_callable - except TypeError: - __builtins__.callable = case.old_callable + unstub_callable(case) @it.should("return true if the live function is an unbound instance method") def test_should_return_true_if_the_live_function_is_an_unbound_instance_method(case): @@ -383,9 +278,7 @@ def test_should_detect_unbound_instance_methods_by_inspecting_the_arguments(case @it.should("not detect unbound instance methods by inspecting their self attribute") def test_should_not_detect_unbound_instance_methods_by_inspecting_their_self_attribute(case): - mocked_callable = mock.MagicMock() - self = mock.PropertyMock() - type(mocked_callable).__self__ = self + mocked_callable, self = fake_real_callable() sut = callables.FakeCallable(mocked_callable) @@ -397,55 +290,35 @@ def test_should_not_detect_unbound_instance_methods_by_inspecting_their_self_att with it.having('a python 2.x runtime'): @it.has_test_setup def setup(case): - stubbed_sys = mock.MagicMock() - stubbed_sys.version_info = (2, ) + stub_python_version(case, 2) - case.patch_python_version = mock.patch.dict(sys.modules, sys=stubbed_sys) - case.patch_python_version.start() - - reload(callables) - - try: - case.old_callable = __builtins__['callable'] - __builtins__['callable'] = lambda c: True - except TypeError: - case.old_callable = __builtins__.callable - __builtins__.callable = lambda c: True + stub_callable(case, True) @it.has_test_teardown def teardown(case): - case.patch_python_version.stop() + unstub_python_version(case) - reload(callables) - - try: - __builtins__['callable'] = case.old_callable - except TypeError: - __builtins__.callable = case.old_callable + unstub_callable(case) @it.should("return true if the live function is an unbound instance method") def test_should_return_true_if_the_live_function_is_an_unbound_instance_method(case): - mocked_callable = mock.MagicMock() - self = mock.PropertyMock() - self.return_value = False - type(mocked_callable).__self__ = self + mocked_callable, self = fake_real_callable() + sut = callables.FakeCallable(mocked_callable) with mock.patch('inspect.ismethod', return_value=True): - actual = sut.is_instance_method + actual = sut.is_instance_method case.assertTrue(actual) @it.should("return false if the live function is a bound instance method") def test_should_return_false_if_the_live_function_is_a_bound_instance_method(case): - mocked_callable = mock.MagicMock() - self = mock.PropertyMock() - self.return_value = True - type(mocked_callable).__self__ = self + mocked_callable, self = fake_real_callable() + sut = callables.FakeCallable(mocked_callable) with mock.patch('inspect.ismethod', return_value=True): - actual = sut.is_unbound_instance_method + actual = sut.is_unbound_instance_method case.assertEqual(actual, False) @@ -471,15 +344,12 @@ def test_should_not_detect_unbound_instance_methods_by_inspecting_the_arguments( @it.should("detect unbound instance methods by inspecting their self attribute") def test_should_detect_unbound_instance_methods_by_inspecting_their_self_attribute(case): - mocked_callable = mock.MagicMock() - self = mock.PropertyMock() - self.return_value = False - type(mocked_callable).__self__ = self + mocked_callable, self = fake_real_callable() sut = callables.FakeCallable(mocked_callable) with mock.patch('inspect.ismethod', return_value=True): - _ = sut.is_unbound_instance_method - self.assert_called_once_with() + _ = sut.is_unbound_instance_method + self.assert_called_once_with() it.createTests(globals()) \ No newline at end of file From 68c2f37b76c3234d53ec7fef889b76bdda162e1f Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 4 Nov 2013 13:49:53 +0200 Subject: [PATCH 29/46] Improved code readability for fake callable unit tests some more. --- .noseids | 52 +++++++++++++------------- tests/unit/fakes/test_fake_callable.py | 12 +++--- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/.noseids b/.noseids index ee89635..ce5f568 100644 --- a/.noseids +++ b/.noseids @@ -62,21 +62,21 @@ I33 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p22 I63 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a ValueError when the provided live object does not match the argspec" -p23 -I51 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" -p24 +p23 I53 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" -p25 +p24 I8 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' -p26 +p25 I26 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' -p27 +p26 I25 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a value error when the provided live object matches the argspec" +p27 +I52 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' p28 I22 @@ -134,24 +134,24 @@ I35 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' p46 I59 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when the provided live object does not match the argspec" p47 +I51 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' +p48 I46 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' -p48 +p49 I66 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" -p49 +p50 I14 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p50 +p51 I41 sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p51 -I5 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a ValueError when the provided live object matches the argspec" p52 -I52 +I5 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' p53 I28 @@ -230,13 +230,13 @@ g57 sI4 g69 sI5 -g51 +g52 sI6 g3 sI7 g67 sI8 -g25 +g24 sI9 g29 sI10 @@ -248,7 +248,7 @@ g73 sI13 g9 sI14 -g49 +g50 sI15 g4 sI16 @@ -270,9 +270,9 @@ g19 sI24 g40 sI25 -g27 -sI26 g26 +sI26 +g25 sI27 g63 sI28 @@ -302,7 +302,7 @@ g72 sI40 g55 sI41 -g50 +g51 sI42 g62 sI43 @@ -312,7 +312,7 @@ g59 sI45 g65 sI46 -g47 +g48 sI47 g71 sI48 @@ -322,11 +322,11 @@ g60 sI50 g37 sI51 -g23 +g47 sI52 -g52 +g27 sI53 -g24 +g23 sI54 g56 sI55 @@ -352,7 +352,7 @@ g42 sI65 g12 sI66 -g48 +g49 sI67 g38 sI68 diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 355c392..15cd980 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -24,7 +24,9 @@ def teardown(case): @it.should("be callable") def test_should_be_callable(case): sut = callables.FakeCallable(mock.DEFAULT) - case.assertTrue(case.old_callable(sut)) + + callable = case.old_callable + case.assertTrue(callable(sut)) it.createTests(globals()) @@ -39,8 +41,8 @@ def setup(case): def teardown(case): unstub_callable(case) - @it.should("raise a ValueError when the provided live object does not match the argspec") - def test_should_raise_a_ValueError_when_the_provided_live_object_does_not_match_the_argspec(case): + @it.should("raise a value error when the provided live object does not match the argspec") + def test_should_raise_a_value_error_when_the_provided_live_object_does_not_match_the_argspec(case): stub_are_argspecs_identical(case, False) with case.assertRaisesRegexp(ValueError, @@ -50,8 +52,8 @@ def test_should_raise_a_ValueError_when_the_provided_live_object_does_not_match_ unstub_are_argspecs_identical(case) - @it.should("not raise a ValueError when the provided live object matches the argspec") - def test_should_not_raise_a_ValueError_when_the_provided_live_object_matches_the_argspec(case): + @it.should("not raise a value error when the provided live object matches the argspec") + def test_should_not_raise_a_value_error_when_the_provided_live_object_matches_the_argspec(case): stub_are_argspecs_identical(case, True) try: From 7cefe2749374d536c237fbfd1bda3bcd553d1320 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 4 Nov 2013 14:01:51 +0200 Subject: [PATCH 30/46] Improved code readability for fake callable unit tests some more. Added a test that verifies that testers won't try to inspect arguments of a builtin callable. --- .noseids | 297 +++++++++++++------------ testdoubles/fakes/callables.py | 3 + tests/unit/fakes/test_fake_callable.py | 10 +- 3 files changed, 163 insertions(+), 147 deletions(-) diff --git a/.noseids b/.noseids index ce5f568..7ca33a6 100644 --- a/.noseids +++ b/.noseids @@ -10,73 +10,73 @@ p4 I15 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p5 -I68 +I69 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' p6 -I62 +I63 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' p7 I19 sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' p8 I1 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' p9 +I58 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" +p10 I13 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' -p10 -I72 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' p11 +I73 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' +p12 I32 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' -p12 -I65 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' p13 -I58 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." +I66 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' p14 +I59 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." +p15 I16 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' -p15 -I17 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' p16 -I57 +I17 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p17 -I55 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" +I56 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" p18 +I54 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" +p19 I10 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' -p19 +p20 I23 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" -p20 +p21 I11 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' -p21 +p22 I33 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" -p22 -I63 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not inspect the argspec of the live object when argument inspection is opted out" p23 -I53 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" +I64 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" p24 +I51 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" +p25 I8 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' -p25 +p26 I26 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' -p26 -I25 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should not raise a value error when the provided live object matches the argspec" p27 -I52 +I25 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' p28 I22 @@ -94,275 +94,280 @@ p32 I21 sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' p33 -I56 +I57 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' p34 -I70 +I71 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' p35 I48 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a value error when the provided live object matches the argspec" p36 +I53 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' +p37 I38 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" -p37 +p38 I50 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' -p38 -I67 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' p39 +I68 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' +p40 I2 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' -p40 +p41 I24 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p41 +p42 I37 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" -p42 -I64 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' p43 -I69 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' +I65 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' p44 +I70 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' +p45 I30 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' -p45 -I35 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' p46 -I59 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when the provided live object does not match the argspec" +I35 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" p47 -I51 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' +I52 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' p48 +I60 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' +p49 I46 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' -p49 -I66 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" p50 +I67 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +p51 I14 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p51 +p52 I41 sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p52 +p53 I5 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' -p53 +p54 I28 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' -p54 -I60 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' p55 +I61 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' +p56 I40 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" -p56 -I54 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' p57 +I55 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' +p58 I3 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' -p58 +p59 I43 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' -p59 +p60 I44 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" -p60 +p61 I49 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' -p61 +p62 I29 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' -p62 +p63 I42 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' -p63 +p64 I27 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p64 +p65 I34 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' -p65 +p66 I45 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' -p66 +p67 I20 sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p67 +p68 I7 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' -p68 +p69 I18 sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p69 +p70 I4 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' -p70 -I71 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' p71 +I72 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' +p72 I47 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p72 +p73 I39 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p73 +p74 I12 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p74 -I61 -ssS'ids' p75 -(dp76 +I62 +ssS'ids' +p76 +(dp77 I1 g8 sI2 -g39 +g40 sI3 -g57 +g58 sI4 -g69 +g70 sI5 -g52 +g53 sI6 g3 sI7 -g67 +g68 sI8 -g24 +g25 sI9 g29 sI10 -g18 +g19 sI11 -g20 +g21 sI12 -g73 +g74 sI13 -g9 +g10 sI14 -g50 +g51 sI15 g4 sI16 -g14 -sI17 g15 +sI17 +g16 sI18 -g68 +g69 sI19 g7 sI20 -g66 +g67 sI21 g32 sI22 g28 sI23 -g19 +g20 sI24 -g40 +g41 sI25 -g26 +g27 sI26 -g25 +g26 sI27 -g63 +g64 sI28 -g53 +g54 sI29 -g61 +g62 sI30 -g44 +g45 sI31 g30 sI32 -g11 +g12 sI33 -g21 +g22 sI34 -g64 +g65 sI35 -g45 +g46 sI36 g31 sI37 -g41 +g42 sI38 -g36 +g37 sI39 -g72 +g73 sI40 -g55 +g56 sI41 -g51 +g52 sI42 -g62 +g63 sI43 -g58 -sI44 g59 +sI44 +g60 sI45 -g65 +g66 sI46 -g48 +g49 sI47 -g71 +g72 sI48 g35 sI49 -g60 +g61 sI50 -g37 +g38 sI51 -g47 +g24 sI52 -g27 +g47 sI53 -g23 +g36 sI54 -g56 +g18 sI55 -g17 +g57 sI56 -g33 +g17 sI57 -g16 +g33 sI58 -g13 +g9 sI59 -g46 +g14 sI60 -g54 +g48 sI61 -g74 +g55 sI62 -g6 +g75 sI63 -g22 +g6 sI64 -g42 +g23 sI65 -g12 +g43 sI66 -g49 +g13 sI67 -g38 +g50 sI68 -g5 +g39 sI69 -g43 +g5 sI70 -g34 +g44 sI71 -g70 +g34 sI72 -g10 +g71 +sI73 +g11 ss. \ No newline at end of file diff --git a/testdoubles/fakes/callables.py b/testdoubles/fakes/callables.py index d9abe00..a81929e 100644 --- a/testdoubles/fakes/callables.py +++ b/testdoubles/fakes/callables.py @@ -41,6 +41,9 @@ def __init__(self, live, inspect_args=False): self._live = live if inspect_args: + if inspect.isbuiltin(self.live): + raise ValueError('Cannot inspect arguments of a builtin live object.') + if not are_argspecs_identical(self.live, self.fake): raise ValueError("The provided live object's arguments %s does not match %s" % ( inspect.getargspec(self.live), inspect.getargspec(self.fake))) diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 15cd980..3e7c1e2 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -1,5 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from inspect import ArgSpec from nose2.tools import such @@ -41,13 +42,20 @@ def setup(case): def teardown(case): unstub_callable(case) + @it.should("raise a value error when inspecting arguments of a builtin callable") + def test_should_raise_a_value_error_when_inspecting_arguments_of_a_builtin_callable(case): + with case.assertRaisesRegexp(ValueError, + r"Cannot inspect arguments of a builtin live object."): + with mock.patch('inspect.isbuiltin', return_value=True): + callables.FakeCallable(mock.DEFAULT, inspect_args=True) + @it.should("raise a value error when the provided live object does not match the argspec") def test_should_raise_a_value_error_when_the_provided_live_object_does_not_match_the_argspec(case): stub_are_argspecs_identical(case, False) with case.assertRaisesRegexp(ValueError, r"The provided live object's arguments ArgSpec\((?:[a-zA-Z1-9_]+=.+(?:, |(?=\))))+\) does not match ArgSpec\((?:[a-zA-Z1-9_]+=.+(?:, |(?=\))))+\)"): - with mock.patch('inspect.getargspec', return_value='ArgSpec(a=None)'): + with mock.patch('inspect.getargspec', return_value=ArgSpec(['a'], None, None, (None,))): callables.FakeCallable(mock.DEFAULT, inspect_args=True) unstub_are_argspecs_identical(case) From 6780b1c05fb271d7ed1a44622713da5990c83f3c Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 4 Nov 2013 15:11:09 +0200 Subject: [PATCH 31/46] A fake callable will now have the live callable's name. --- .noseids | 405 ++++++++++--------- testdoubles/fakes/callables.py | 12 +- tests/functional/fakes/test_fake_callable.py | 16 + tests/unit/fakes/test_fake_callable.py | 36 ++ 4 files changed, 273 insertions(+), 196 deletions(-) diff --git a/.noseids b/.noseids index 7ca33a6..f76e79f 100644 --- a/.noseids +++ b/.noseids @@ -10,364 +10,379 @@ p4 I15 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p5 -I69 +I72 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' p6 -I63 +I66 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' p7 -I19 +I20 sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' p8 I1 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' p9 -I58 +I61 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" p10 I13 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' p11 -I73 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' +I70 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' p12 -I32 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' +I76 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' p13 -I66 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' +I33 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' p14 -I59 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." +I69 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' p15 +I62 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." +p16 I16 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' -p16 -I17 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p17 -I56 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" +I18 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p18 -I54 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" +I57 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" p19 -I10 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' +I55 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" p20 -I23 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" +I10 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0000: should have the same name as the live object' p21 +I17 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" +p22 I11 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' -p22 -I33 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p23 -I64 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" +I34 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p24 -I51 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" +I67 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" p25 +I52 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' +p26 +I24 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" +p27 I8 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' -p26 -I26 +p28 +I27 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' -p27 -I25 +p29 +I26 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' -p28 -I22 +p30 +I23 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" -p29 +p31 I9 sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' -p30 -I31 +p32 +I32 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' -p31 -I36 +p33 +I37 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' -p32 -I21 +p34 +I22 sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' -p33 -I57 +p35 +I58 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' -p34 -I71 +p36 +I74 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' -p35 -I48 +p37 +I49 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a value error when the provided live object matches the argspec" -p36 -I53 +p38 +I54 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' -p37 -I38 +p39 +I39 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" -p38 -I50 +p40 +I51 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' -p39 -I68 +p41 +I71 sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' -p40 +p42 I2 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' -p41 -I24 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p42 -I37 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" p43 -I65 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' +I25 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' p44 -I70 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' +I38 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" p45 -I30 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' +I68 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' p46 -I35 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" +I73 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' p47 -I52 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' +I31 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' p48 -I60 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' +I36 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" p49 -I46 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' +I53 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' p50 -I67 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +I63 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' p51 +I47 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0000: should have the same name as the live object' +p52 +I59 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +p53 I14 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0000: should have the same name as the live object' +p54 +I60 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p52 -I41 +p55 +I42 sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p53 +p56 I5 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' -p54 -I28 +p57 +I29 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' -p55 -I61 +p58 +I64 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' -p56 -I40 +p59 +I41 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" -p57 -I55 +p60 +I56 sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' -p58 +p61 I3 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' -p59 -I43 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' -p60 +p62 I44 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' +p63 +I45 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" -p61 -I49 +p64 +I50 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' -p62 -I29 +p65 +I30 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' -p63 -I42 +p66 +I43 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' -p64 -I27 +p67 +I28 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p65 -I34 +p68 +I35 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' -p66 -I45 +p69 +I46 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' -p67 -I20 +p70 +I21 sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p68 +p71 I7 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' -p69 -I18 +p72 +I19 sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p70 +p73 I4 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' -p71 -I72 +p74 +I75 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' -p72 -I47 +p75 +I48 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p73 -I39 +p76 +I40 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p74 +p77 I12 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p75 -I62 +p78 +I65 ssS'ids' -p76 -(dp77 +p79 +(dp80 I1 g8 sI2 -g40 +g42 sI3 -g58 +g61 sI4 -g70 +g73 sI5 -g53 +g56 sI6 g3 sI7 -g68 +g71 sI8 -g25 +g27 sI9 -g29 +g31 sI10 -g19 +g20 sI11 -g21 +g22 sI12 -g74 +g77 sI13 g10 sI14 -g51 +g53 sI15 g4 sI16 -g15 -sI17 g16 +sI17 +g21 sI18 -g69 +g17 sI19 -g7 +g72 sI20 -g67 +g7 sI21 -g32 +g70 sI22 -g28 +g34 sI23 -g20 +g30 sI24 -g41 +g26 sI25 -g27 +g43 sI26 -g26 +g29 sI27 -g64 +g28 sI28 -g54 +g67 sI29 -g62 +g57 sI30 -g45 +g65 sI31 -g30 +g47 sI32 -g12 +g32 sI33 -g22 +g13 sI34 -g65 +g23 sI35 -g46 +g68 sI36 -g31 +g48 sI37 -g42 +g33 sI38 -g37 +g44 sI39 -g73 +g39 sI40 -g56 +g76 sI41 -g52 +g59 sI42 -g63 +g55 sI43 -g59 +g66 sI44 -g60 +g62 sI45 -g66 +g63 sI46 -g49 +g69 sI47 -g72 +g51 sI48 -g35 +g75 sI49 -g61 +g37 sI50 -g38 +g64 sI51 -g24 +g40 sI52 -g47 +g25 sI53 -g36 +g49 sI54 -g18 +g38 sI55 -g57 +g19 sI56 -g17 +g60 sI57 -g33 +g18 sI58 -g9 +g35 sI59 -g14 +g52 sI60 -g48 +g54 sI61 -g55 +g9 sI62 -g75 +g15 sI63 -g6 +g50 sI64 -g23 +g58 sI65 -g43 +g78 sI66 -g13 +g6 sI67 -g50 +g24 sI68 -g39 +g45 sI69 -g5 +g14 sI70 -g44 +g11 sI71 -g34 +g41 sI72 -g71 +g5 sI73 -g11 +g46 +sI74 +g36 +sI75 +g74 +sI76 +g12 ss. \ No newline at end of file diff --git a/testdoubles/fakes/callables.py b/testdoubles/fakes/callables.py index a81929e..d13e720 100644 --- a/testdoubles/fakes/callables.py +++ b/testdoubles/fakes/callables.py @@ -19,6 +19,11 @@ def is_unbound_instance_method(self): @property def is_instance_method(self): return inspect.ismethod(self.live) or self.is_unbound_instance_method + + class CallableInternalAttributesMixin(object): + @property + def __name__(self): + return self.live.__name__ else: class CallableIntrospectionMixin(object): @property @@ -29,8 +34,13 @@ def is_unbound_instance_method(self): def is_instance_method(self): return inspect.ismethod(self.live) or self.is_unbound_instance_method + class CallableInternalAttributesMixin(object): + @property + def __name__(self): + return self.live.__name__ + -class FakeCallable(CallableIntrospectionMixin): +class FakeCallable(CallableIntrospectionMixin, CallableInternalAttributesMixin): def __init__(self, live, inspect_args=False): if not callable(live): try: diff --git a/tests/functional/fakes/test_fake_callable.py b/tests/functional/fakes/test_fake_callable.py index cae599e..6a03987 100644 --- a/tests/functional/fakes/test_fake_callable.py +++ b/tests/functional/fakes/test_fake_callable.py @@ -5,6 +5,22 @@ from tests.common.layers import FunctionalTestsLayer from tests.common.compat import mock +with such.A("Fake Function object") as it: + it.uses(FunctionalTestsLayer) + + @it.should("have the same name as the live object") + def test_should_have_the_same_name_as_the_live_object(case): + def foo(): pass + + sut = FakeCallable(foo) + expected = foo.__name__ + + actual = sut.__name__ + + case.assertEqual(actual, expected) + + it.createTests(globals()) + with such.A("Fake Function's initialization method") as it: it.uses(FunctionalTestsLayer) diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 3e7c1e2..9fbc381 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -29,6 +29,42 @@ def test_should_be_callable(case): callable = case.old_callable case.assertTrue(callable(sut)) + with it.having('a python 3.x runtime2'): + @it.has_test_setup + def setup(case): + stub_python_version(case, 3) + + @it.has_test_teardown + def teardown(case): + unstub_python_version(case) + + @it.should("have the same name as the live object") + def test_should_have_the_same_name_as_the_live_object(case): + sut = callables.FakeCallable(object) + expected = object.__name__ + + actual = sut.__name__ + + case.assertEqual(actual, expected) + + with it.having('a python 2.x runtime2'): + @it.has_test_setup + def setup(case): + stub_python_version(case, 2) + + @it.has_test_teardown + def teardown(case): + unstub_python_version(case) + + @it.should("have the same name as the live object") + def test_should_have_the_same_name_as_the_live_object(case): + sut = callables.FakeCallable(object) + expected = object.__name__ + + actual = sut.__name__ + + case.assertEqual(actual, expected) + it.createTests(globals()) with such.A("Fake Function's initialization method") as it: From 0e3324d2fa8a2a84ca6c97a9a13640b32f4407dc Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 4 Nov 2013 15:59:45 +0200 Subject: [PATCH 32/46] A fake callable will now have the live callable's name when the callable is a class instance. --- .noseids | 383 ++++++++++--------- testdoubles/fakes/callables.py | 6 + tests/functional/fakes/test_fake_callable.py | 13 + tests/unit/fakes/test_fake_callable.py | 47 ++- 4 files changed, 257 insertions(+), 192 deletions(-) diff --git a/.noseids b/.noseids index f76e79f..baeecf7 100644 --- a/.noseids +++ b/.noseids @@ -10,49 +10,49 @@ p4 I15 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p5 -I72 +I75 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' p6 -I66 +I69 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' p7 -I20 +I21 sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' p8 I1 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' p9 -I61 +I63 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" p10 I13 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' p11 -I70 +I73 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' p12 -I76 +I79 sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' p13 -I33 +I34 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' p14 -I69 +I72 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' p15 -I62 +I65 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." p16 I16 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' p17 -I18 +I19 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p18 -I57 +I58 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" p19 -I55 +I56 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" p20 I10 @@ -64,203 +64,212 @@ p22 I11 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' p23 -I34 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" +I35 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' p24 -I67 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" +I66 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p25 -I52 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' +I70 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" p26 -I24 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" +I53 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' p27 +I25 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" +p28 I8 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' -p28 -I27 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' p29 -I26 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' +I28 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' p30 -I23 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" +I27 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' p31 +I24 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" +p32 I9 sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' -p32 -I32 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' p33 -I37 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' +I33 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' p34 -I22 -sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' +I38 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' p35 -I58 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' +I23 +sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' p36 -I74 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' +I59 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' p37 -I49 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a value error when the provided live object matches the argspec" +I77 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' p38 -I54 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' +I50 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a value error when the provided live object matches the argspec" p39 -I39 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" +I55 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' p40 -I51 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' +I40 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" p41 -I71 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' +I52 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' p42 +I74 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' +p43 I2 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' -p43 -I25 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' p44 -I38 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" +I26 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' p45 -I68 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' +I39 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" p46 -I73 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' +I71 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' p47 -I31 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' +I76 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' p48 -I36 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" +I32 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' p49 -I53 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' +I37 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" p50 -I63 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' +I54 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' p51 -I47 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0000: should have the same name as the live object' +I61 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' p52 -I59 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +I48 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0000: should have the same name as the live object' p53 +I60 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +p54 I14 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0000: should have the same name as the live object' -p54 -I60 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' p55 -I42 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' +I62 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' p56 +I64 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' +p57 +I43 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' +p58 I5 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' -p57 -I29 +p59 +I30 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' -p58 -I64 +p60 +I67 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' -p59 -I41 +p61 +I42 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0001: should have the same name as the live object when the live object is a callable class instance' +p62 +I18 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" -p60 -I56 +p63 +I57 sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' -p61 +p64 I3 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' -p62 -I44 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' -p63 +p65 I45 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' +p66 +I46 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" -p64 -I50 +p67 +I51 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' -p65 -I30 +p68 +I31 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' -p66 -I43 +p69 +I44 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' -p67 -I28 +p70 +I29 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p68 -I35 +p71 +I36 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' -p69 -I46 +p72 +I47 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' -p70 -I21 +p73 +I22 sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p71 +p74 I7 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' -p72 -I19 +p75 +I20 sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p73 +p76 I4 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' -p74 -I75 +p77 +I78 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' -p75 -I48 +p78 +I49 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p76 -I40 +p79 +I41 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p77 +p80 I12 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p78 -I65 +p81 +I68 ssS'ids' -p79 -(dp80 +p82 +(dp83 I1 g8 sI2 -g42 +g43 sI3 -g61 +g64 sI4 -g73 +g76 sI5 -g56 +g58 sI6 g3 sI7 -g71 +g74 sI8 -g27 +g28 sI9 -g31 +g32 sI10 g20 sI11 g22 sI12 -g77 +g80 sI13 g10 sI14 -g53 +g54 sI15 g4 sI16 @@ -268,121 +277,127 @@ g16 sI17 g21 sI18 -g17 +g62 sI19 -g72 +g17 sI20 -g7 +g75 sI21 -g70 +g7 sI22 -g34 +g73 sI23 -g30 +g35 sI24 -g26 +g31 sI25 -g43 +g27 sI26 -g29 +g44 sI27 -g28 +g30 sI28 -g67 +g29 sI29 -g57 +g70 sI30 -g65 +g59 sI31 -g47 +g68 sI32 -g32 +g48 sI33 -g13 +g33 sI34 -g23 +g13 sI35 -g68 +g23 sI36 -g48 +g71 sI37 -g33 +g49 sI38 -g44 +g34 sI39 -g39 +g45 sI40 -g76 +g40 sI41 -g59 +g79 sI42 -g55 +g61 sI43 -g66 +g57 sI44 -g62 +g69 sI45 -g63 +g65 sI46 -g69 +g66 sI47 -g51 +g72 sI48 -g75 +g52 sI49 -g37 +g78 sI50 -g64 +g38 sI51 -g40 +g67 sI52 -g25 +g41 sI53 -g49 +g26 sI54 -g38 +g50 sI55 -g19 +g39 sI56 -g60 +g19 sI57 -g18 +g63 sI58 -g35 +g18 sI59 -g52 +g36 sI60 -g54 +g53 sI61 -g9 +g51 sI62 -g15 +g55 sI63 -g50 +g9 sI64 -g58 +g56 sI65 -g78 +g15 sI66 -g6 -sI67 g24 +sI67 +g60 sI68 -g45 +g81 sI69 -g14 +g6 sI70 -g11 +g25 sI71 -g41 +g46 sI72 -g5 +g14 sI73 -g46 +g11 sI74 -g36 +g42 sI75 -g74 +g5 sI76 +g47 +sI77 +g37 +sI78 +g77 +sI79 g12 ss. \ No newline at end of file diff --git a/testdoubles/fakes/callables.py b/testdoubles/fakes/callables.py index d13e720..83ebddf 100644 --- a/testdoubles/fakes/callables.py +++ b/testdoubles/fakes/callables.py @@ -23,6 +23,9 @@ def is_instance_method(self): class CallableInternalAttributesMixin(object): @property def __name__(self): + if not self.is_instance_method and not inspect.isfunction(self.live): + return self.live.__class__.__name__ + return self.live.__name__ else: class CallableIntrospectionMixin(object): @@ -37,6 +40,9 @@ def is_instance_method(self): class CallableInternalAttributesMixin(object): @property def __name__(self): + if not self.is_instance_method and not inspect.isfunction(self.live): + return self.live.__class__.__name__ + return self.live.__name__ diff --git a/tests/functional/fakes/test_fake_callable.py b/tests/functional/fakes/test_fake_callable.py index 6a03987..d205d59 100644 --- a/tests/functional/fakes/test_fake_callable.py +++ b/tests/functional/fakes/test_fake_callable.py @@ -18,6 +18,19 @@ def foo(): pass actual = sut.__name__ case.assertEqual(actual, expected) + + @it.should("have the same name as the live object when the live object is a callable class instance") + def test_should_have_the_same_name_as_the_live_object_when_the_live_object_is_a_callable_class_instance(case): + class Foo(object): + def __call__(self, *args, **kwargs): + pass + + sut = FakeCallable(Foo()) + expected = Foo.__name__ + + actual = sut.__name__ + + case.assertEqual(actual, expected) it.createTests(globals()) diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 9fbc381..7f4af31 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -32,38 +32,69 @@ def test_should_be_callable(case): with it.having('a python 3.x runtime2'): @it.has_test_setup def setup(case): + stub_callable(case, True) stub_python_version(case, 3) @it.has_test_teardown def teardown(case): unstub_python_version(case) + unstub_callable(case) @it.should("have the same name as the live object") def test_should_have_the_same_name_as_the_live_object(case): - sut = callables.FakeCallable(object) - expected = object.__name__ + with mock.patch('inspect.ismethod', return_value=True): + with mock.patch('inspect.isfunction', return_value=True): + sut = callables.FakeCallable(object) + expected = object.__name__ + + actual = sut.__name__ + + case.assertEqual(actual, expected) + + @it.should("have the same name as the live object when the live object is a callable class instance") + def test_should_have_the_same_name_as_the_live_object_when_the_live_object_is_a_callable_class_instance(case): + with mock.patch('inspect.ismethod', return_value=False): + with mock.patch('inspect.isfunction', return_value=False): + with mock.patch('inspect.getargspec', return_value=[]): + sut = callables.FakeCallable(mock.DEFAULT) + expected = mock.DEFAULT.__class__.__name__ - actual = sut.__name__ + actual = sut.__name__ - case.assertEqual(actual, expected) + case.assertEqual(actual, expected) with it.having('a python 2.x runtime2'): @it.has_test_setup def setup(case): + stub_callable(case, True) stub_python_version(case, 2) @it.has_test_teardown def teardown(case): unstub_python_version(case) + unstub_callable(case) @it.should("have the same name as the live object") def test_should_have_the_same_name_as_the_live_object(case): - sut = callables.FakeCallable(object) - expected = object.__name__ + with mock.patch('inspect.ismethod', return_value=True): + with mock.patch('inspect.isfunction', return_value=True): + sut = callables.FakeCallable(object) + expected = object.__name__ + + actual = sut.__name__ + + case.assertEqual(actual, expected) + + @it.should("have the same name as the live object when the live object is a callable class instance") + def test_should_have_the_same_name_as_the_live_object_when_the_live_object_is_a_callable_class_instance(case): + with mock.patch('inspect.ismethod', return_value=False): + with mock.patch('inspect.isfunction', return_value=False): + sut = callables.FakeCallable(mock.DEFAULT) + expected = mock.DEFAULT.__class__.__name__ - actual = sut.__name__ + actual = sut.__name__ - case.assertEqual(actual, expected) + case.assertEqual(actual, expected) it.createTests(globals()) From 8ed41c81c835b54a7b903207554fccc1561fc7aa Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 4 Nov 2013 16:44:15 +0200 Subject: [PATCH 33/46] getargspec raises a type error when the argument is not a method. --- .noseids | Bin 14620 -> 13939 bytes testdoubles/fakes/callables.py | 2 ++ 2 files changed, 2 insertions(+) diff --git a/.noseids b/.noseids index baeecf777a5d2b7d803a73c79b3b78b37d5963d9..1ba1aaac10d07bc0b6f111a926dc1663684eb96a 100644 GIT binary patch delta 2016 zcmZWpTW^$A6m6My+B26WM@X>ehobU8ze3*x`_MUIAz1Q0N#`%BF zl&{+^i>w&W&C1HUaBA(sn#jH^4#oIw^_EW^U2?UoLcWMPWhxSo?-$0Iu%VMb*U@zL zNfimpjq+nm=@&hOnOSL zMw3kBVZb11cdxwe56YywmWh0L`G;1qa7vyi9btl@j^DKqca>af^ULj)H6|R$<3A`g zQ=FDg|2z{;`1u`^HYjg8!&VP})(kP>LIM9qM@)Bu2{*d=XBvqlXXJypL;f8YW1;|U z{MpVY*NapQ56X8KhKJ=F(OxDBF~q+&MTX^;w?Q7yon*ob2mjijD+ckwy~|nmRwx@o z4*6H?H71JS<6r39tDQ&naAZqmL_R(gVxkz6{P9jCV?WPC2~vA}?zbvFr6}ePb;f#S zTHb6*GvP-i-_S@TxxqvLN&b$0=|+DEjxte(4*sr2(mS&Y)~QB=$mQz?(Z*1UiE1Wm)c!SRA9l_;h^|0qH6q=7_pSv zGgl(ukdK^8OjMzVUpv5Kb8(J|2<*m1+E*J@4!M<>VWJvQ{+>=Xt(D488shFVr{6v$ zYS7M~sE9H`#_p9XHkbUM*eiclzkYkUJnQu_5k(olX9`)~$Yj6DL@hl0V+|SuGkLUG zX<3IR{?&n0rI9LMk3vH#9o}RjhI;<3&e1yjRyWN=11k8oLbMwb0nMUMQcIMHI7<0X zI#tVUhUS(pD+}b6iY_J^G0kt9V#eCXbDh!^f1QaY*!YiDL=D^6WSog+%o)nsx3{Vl z-2__x+k}NC(P(U8X1K^i3u^i5fl8Si<>ppo^Dh;sSzA)Ip@?r;z!nqj2<%f&1cLIu zM@^ywQ)UvI?P?O8XyqU2&+e;!f{8AS8sF%Hkq9g^(T#aCv9xn3zC_KQd{Ln3%+bwd8U=^o)rq1o`hOrWG-& zd*o_Cj(pM@m!I3}nV3cizpnqhYuX2KwMa8)-Z?kwP+iM;i-{D5%}Ad*K4fAReP%he zZ;ll@Gd}zN^nrv$&~kHLLNS~}c<&O)<$QID<}qUm+>YF3VgZAEO_MNJMK!sI923{; zSrxg!#1gvp*Z6D)lXt`VVz}kKTCY463tkb25x>Z7>NBTLu8CJJiz6{)Q!5TpIc(H~ z99l#!1!1QM^2mXF3W3oW9OQ+QM&Y6!xXFhCa=}BjD5QFLDIY#6LJ_s0m`YJX(^SL7TxnJy0V$9C<6w2vP-=rRoc9_NGe;G4B}dEgv67CXZ(JB&Jj{~OWl%% zz+Oz^!Uk^NzW1DSKlJnNcsKj=OBoeq@nv>g%zoY-m(2_F{VCm+ah8V3d>?*`iaG!8 zi9gPNRe#`r>Oar_jkaa=y1Ki&TmPbpm+X}6)HX}YFiusNB~a(=4p$s37->f)*rRuUkZFd zT*hG%|G)ZBb%@HBY^M!gXoK@GE+Q4Gzr*Ad{hsGpuD-uSXX|i)*LWB0R1&{NDyz<{ zb{Wo-W~DlW<@TjIMVL!*jJ7|`j`y=*v4-hq&(2RUVty*)q;?@Z@boQu`<~^yC%oyz zLl;l@inNSz7I?S*Eqqn~79Kqu!#pmsbl?zCdCFmPeu6jmXV1oY0UN7htCz4)v@qVs zI8CU&eW%I#OH`Qdsy7u8?r&$m3x9jISN}2YXFUrZ-Z`bVzjZqO>cFX%=4#rfdd|w1 z+Oz^E!i_M3itvEzJ7lM{RM}oz$*A5SjJ}%7u%fziC3FV7GyNudZKj3Ir{jmH3LM^O z5|vT%ru5aT=Tqsww@|%?IX^?64M%&J1aR)ck;sGep>2z_DZS?);=Ok-cx$j~}n(5$!n|r~+h8R!KE*8Lz zcaC&BbTpjwQAg~cD57k!#0f3P@g+wOg}RLN7fAQF>;!uISC;N$Ipr0VbvO!uZGLCS zso`PfPWg7ke=_xa=Gz?&1;wuJKPtK|bp24+3`Cn9lspo+_hI?&kzAnH_&kwm_4|qM zVRFd8yBgPN80d0Cy1Wj12K9_V9Rf<9rqOsoyaC}+ZV`mCV+mQ1oys|Z2egTQ8h9GC zf;_o3Z5kG;Q`8nPEw}n8ldc61E|_n%Ykm1<$f(w?mPoARrvu?86_GK~|4v{;WDhgx z88Tz1o~n<0dZOOY^w>}jJqU(eKTfx5Sh}t>bn~j~i>&OZJ=U0Ivtvb>&Gk2L>fSz0 z2T!iA*WQIXrDtC?6#U_Qxg=lSdBe6>opb`C);*faO?ZydC5T68vH&rumY^Fk05m}?U3S2R&Pv{ ziI_QzPF7sjh4m{7YZaNwy5Szy1-i;*>4q98PD*qJEG%7ujnteUyW+<_SyIvMt0JYZLctrn5&;YlQ+Ulz01Fz$&=DBy1f%oD1 zxc@$&9G&aqjez`?pL4j!%MJ&Fk6D3+7JG75*7P6I+cj8$BN29=aeGb)Fqll2T%Pad zR^VMgv&J+lEHC5T(Xz#8#F0$b^T`0@6?k}B&1fZb4Yq%w)EieIMnB?$jJ6`*S^#^Q z3b6V)H&p?sO@r0vq~d)y6`M$P`;F0$a9g5lSMe#EQ{Gqvze2?5BpY_cwX1hWI5F(JBZ+DfQB7HN zx0$%YTCS_4d*N`vsV1|Hp*~J_6okLI33uLui11J2_3(Xnas(Ap^-UMl?b>S%F~B|d z;EeS<{i55YkOkH4sRl3A5tr`NWuOm6)!Q@Jp{v=Fv^sr_2S(5K4AV6|Mb7rlgQZIc zd-ot4%jK3W9qejqu~uW-LEC{+>Y#eyE;|Zh)@j5Zuy$vMC{psC3iK%3g1G&GyN+Tg3qgK0ugWAEL&g zhRJadYX_lcT8%tG|0>v6YR5|ZUMF1|lE$iL_~R)BwG65fsorO)htN%N0gy!m2AHNz zbeeUYS2>MSvo5%Fklw2jnimJef#ob$jOq7toYymV!iXf;O!knKr@CIbS-^v0ptAJc z^~YMz9NMPwV-jx95uW9-#OyuQqMJKi?e!4z3r0N4C9e@z&h=8ZyTv**`=!=XJQKvIDD?qp#>z;BYsEDf3Hs4Nc^*03;;Ptj|t z^Xg5JUv|~PBp@2QOu^c^+kWr$q`8GRm4x|sRtC))X0)?fh;jOweXDl3(zj-aTWxcK zH%2XU0w)6tkS0qS4V4C=*k8Cwdk5Ym9VS4DRd zMjiv-3pu`@AqQrG(9=G$Lhja}ZUtut)O)%mBWjmc0ZRN~@nRk4vMcwYqba#Aj!BL7 z)!HhE2#ti#aI_Ppt#ZquCEwg^fS;VH4&08(bAUOUKHOxto2I0J{i{6k+?5xeuajazgh=1esyEB38acD~(6M%gZS#LA9vaVV~cROu79Q%T!#6S<7 zS+o0LI+LixhJh%o`4{z%A&9MkNA&;kpu$*cLti!coGWp{sOdxz5XWChM;DzA&r!~G zF<;w<*TPYjC5bJ_?-Z^**J4MKr@%{$*S~bI&=%jF zfz|*d0zn&LPpHStD|ndPp77y~@%SWh)V2;3d4CJ6_J|G-vbbQF_D${RI}8;Tj&<`a=Zc zNb!y#{kY__WRC#!#Z2%E%zK0l3Df|>mI)GC*aJs@K)57}C%uHfe!$E8_2W#qgM*C- zVQ-l`ok9%as-lo1=s2sL$`0XVgKcYJ)^YzqxTDXRjj%f5$W%Bs zW#9{+GhhWR?7Xt)BP Date: Mon, 4 Nov 2013 17:58:49 +0200 Subject: [PATCH 34/46] Fake callables now contain a reference to the instance they are bound if we are faking a bound method. --- .noseids | Bin 13939 -> 15648 bytes testdoubles/fakes/callables.py | 35 ++++++++----- tests/unit/fakes/support/fakes.py | 2 +- tests/unit/fakes/test_fake_callable.py | 69 ++++++++++++++++++++++--- 4 files changed, 86 insertions(+), 20 deletions(-) diff --git a/.noseids b/.noseids index 1ba1aaac10d07bc0b6f111a926dc1663684eb96a..75fbdbfadec50d3fed01841a49ffa78d892acaf1 100644 GIT binary patch literal 15648 zcmcgzO>^7272WGsVBRKg<*_8ocDn1d%?vl~;=SqCLrc^(8;Mj&DvA5+dk#bbAP6GV zhqFmEvP4~6T%2?62Y%li?q`2|YO=biKg|yF+3%afqI=_Rdo0#XUKZ)@ZkvA1>N|e! zg)i^^s=nYq^{?0eWa~!1ukP>fSAS9UTY21V)VeI1G%r-T+o?lU9!tzQ`YiIm=n{III8oO`8|7=4FkaNndxytS_zMpKAO- z-sI^n|DS%S+GovMxiJRMjlor#*O^Myzti0@`$tukmHPgcovgzGzU7;2qjveXOqF`g zYExo8McJr*+N|I7D$+{oL$>~Hc6gX2^A$`#dG_uIBkqn(zH40w54?QM-oKaC<^^9m za?$k*exhh{tOed}{|aBVe}zZ)hqTJ;vWP4qYmOCcu8#2L_T<^Ts$rvEwt7ozMGNz7 zj@6{<>vx)Lenh3kMt`Z!uzwr(TlnnBUh`q>&uW%D&*Q5!_V-q2-i@qkVYjBgs@Jl4 zYfY=MBJ2nws809TzI}Nt8dYwMm5l1gS@Ps;h7;A^me3jS&gDBXYBMeDo{krp4jk_2 zE^D&gyE0p^UXM+9-%|B0t@sSHHZ1LFmMokdaF#ahz}_1t*T>ho$(v(ya%YvLyDrkd z=Ww_=rKj-6Z$Bf(!H&=vx9;b%HPdu1`)qacfipWe6-13P%0Qryi5yYYWr9K=6sH5T6&Hi9?t+$PQj8# z6XtFB^sLveYG*O!+%+ihQ7%raUgX!qh3c)4M~kZOJRd$x{n{*Xfdgi82(c?2K-tt_^=94pPe z9;t$1?B6V#cEW+jpm{&wpHjV^1cEjc%({H=oO-i3ITL2!{g$4Mdxy;VvnT zE@;S0hE6UN2Il*uqja|~ArlM@F(gQv1o#h>Ulu(G3}X_kbFzjb@H5pR!K6GiP%-7P zxg&sp3SqL5Tpj8_O-=EpuWssyGKoe>&#fVbr)x=_M26P2S{{0*&9X`>wZB+R%a3-d z+Cs5Ch&V6Ve~%z=oE@Gceah8~ek7m(@<`JrpVDy%JqWH_Jzs8BTxnbA;#PyJxRKh9 z)?=MnF3oA~>$bo9lE3>feF45(-Gc9q#mQG4mwq_!LA@nl>rmKE4Tx5z8A`U{IZ0q3 z9v5ILoF5a9&e@r21T(D(a>3db&~XE`5L5~aP!-gI@mT!u_>#<_)p@{Umsv#@l9!w$ zBb4!V(BP*+8rvgyV^K1sUb?61w88| z4wf#!Mk|NaofCCyHX3N#X!bwkxp93vtPe1hz+DKZ>#<@o)H-`}%KduceIjTukF%KZ zf!p!fO7wuWy~Dt2%+SZ<`+>A%uzlE(CCCrEVgT_27x#SL;$ZNhtWkes3DIcfSV|Qv zaxB4-I8bJR@uTk}elQ8Qkg7Q{RaK_Ja;@_X0*_GuZ7OT?rY>h%f;Ar_=XcXdwZT zrGxtyhw4qm$r9YT{51&i;3GuGM#HLY_9I<4sC{ahXYnf-i>z=?cBn`D4;qiBTjOp}t{<06LmwFtH*}6JIgk?iHGD3IWH;Go5xg`4+3xBF^=jm8Bj>MH zuc&38aytqoY;9ga!|foGx;hmMd|oEme1Sij9YvgKPqsBQq?-q@7p|SsoggB(^kR4FUm8?)EhhWr1mm@i@#r3K#)=t6 zq~p~k^8Nmbc{h>)4fwAo0S5#aE4f7~b#B?0ZUvJ(g;CSn_Yp#|9_)&m?1r9%#JR1| z2M~+n-p=zMP~Cd+5j^hep<;`BI3x(^Y)}+Zyng(6Znh<{Nyp2&|2k1Y>%c-l)&2?d z2*Sj%pWdIc>PU23bPeG^zoLA00<8}R4=6b9$x*AJ62R>^ZUAjp%76z_+AoR!`8Yjm zp%Unf?@LtBLvaoMLkWvtb0G@x1oBIeK3o{>!5Y@Uj%B>r)->7vfC3QoPN|OQesah2z3#lBvy!JALO?Yr zdAzNG7T|OetHYBz`j(w!_%wOExZ3LE-bPE_EKtFS0JZDSklk^c0Zwu#cNMht=twVz zmq&x|+%sdX>KbH$ywqqiebUredHKOo`(28pwGjuBIKaFF7U%c8l3H(wT=l_%3?kOQiu#&hTGX)x-oFEvzv z=1qdD@pl6PI3>P%`_g@?!O%1OXm>Phuie7T zY5P$>PBDs5pq$m7miIOc_`Fc6B`$)m%p<2yY9G!DgU z%l=t5NjKY@ZJdf~UVJOR>W*6R-nH7h^D=2d7-l98B%bHh5LnxD&2r04s$DqJ3DWoL zx85*{jlQchTToqs+`Dg_hvc_Q3(u_MxCNO=RlzOy46C7-VM?Cq{tJtZ8f&^k9oT}O z0RX=b06_aaL2hLn?Hnr4-JMG5)e+7iPUrYdYe7y(V0%>vumMKa67=QFa;`sl7S7H- zb+)xg%g9rX#Qi`=56)pP=XP^`J$cV!y*ET3?}Y|}nPtFRNCd0jZM2w3KD!l)!HfhV z>-uQ0#c`_*uE#i5?|h6Kl>qR9W~9Inw>kX-<9ZuEs;f*-*@!CCmlG5hjpIHpSnuum z3OKaG96dxt=5q##Om<}MCiK8ShxV`v%##S>!)RG(ah~@_bc8e764w!uHM;(SOFMP@ zGKHe(P@8o)%pBI!ZXIFXKlwFVG6R0^SUu+_k#yJqq9alwB0yZ7!UcjGpZyhj z5kIMyVerO!{32D_<40JQpqy^D|9a*g(4ZT}Loh7Hy2o@Ki+Yq5*A1Odm_&`9y)%r4 zw0j2o;j%~Hqh3VgG+#Jf88tK-!2X?-NCdNf(OqTWHh?jqqiQTE->`c9{LGu7&j9rK zOpqF)7b(nXkbDVKMI2~he+H!?VYwLhHU)VZa8!7G3bS`Y*@DR&;q48MJPR+bagtX! z-$4fo9ElfrB9lsT&`Bo-$2!b&2i>4jN7flYWPk=NpcpT*~d zw{SQ`B5Z7Mv`ILl!!btT;2ax|!X$`OW@P2-2&=1{1Qt$EQFaKsZfvOtIPA``Ibr{cWd`949qV4g3rMWJ3TJV6_e6N1gM-V$iBn#a5#Fk0 zXbM6UFX#>aPm}cvJeW-ZHtvO40B>Lk4=1nj37?DT5IzLqD#SsK$_Sgg#BAZ*4AVv7 I)tCD2{~$z#vj6}9 delta 2149 zcmZWq-A~)+6%H5!$2K-L4hDm53Qi^rc;_m zQzuQ^qLH(UO`Y0qQ?+hWzixV0sjAjqOr4re-AylA<*L)7O^fyq?0x<6OOSTybI$La z=Q-zjAHVkef4|rEqVJ|Yl~?{#r%oMSJ~%wkRX25YUj4@WmfP9f(Y;}bP*C3Pu9IYR zhO`gk>I<9Pt-53~Md`1O%0Fr*NY`LP{oH+4mf5L`r2XhqM>g^>l9K(%A?aEyspq_! z>7HrQb(nRL`~GS9vLz{BHguD&M^ydT)s4xwb3yr4VuLiHNBz-8@B2HXJeZJI#tuja zP^aFiOo{EvOPQ$b`0C~9mNC*nB-HO*{hVxtQpZf@Nrw%RYW z(lIo61g7O`zb4&;n0mR=Ir5}z`&td~n0#E_PCAZN^|6=vy7n6B(^!9m;%-$??p4L) z-#ra-!n7Uzu-h%(tyF@w(zk2ax^o9Pw(NiHgNR>#pp<4aHCO-?Y?1!WBpT3N|8jg}~ zNBv_ov8+LpLWlaht+m>DDU+7{rl>Sdnh|N7ciM4E88??o8E#q987#Q#9*gloDIkZT z3#2PaTiCANOvNqp0_2HZ!O1W12G`W#T@A_l+<5s@}ZH<*R@gU zFe76lG5J#=DXCbDbPlcRZ8xDJpSxAxB;AdO`kCu#RZjAg;Z@Q-7*xMKQ7X3rYovS8 z=+L-Rk}Y z(u44+cWuOO(#gi?eF&Q#Hhb--NEa~dMI73{WDVLP20T^VAw7(4wg0$#;%<$3mLsTA zuiBv9&ZA?DqDg(?MfVDJXK6{tq7tc2CZD-{6 z{X6nWFd&~+HOU8wxHM!Eq^A(_Y-C;Ds7aYj7wKtqJ(l5K!MwsV*!C9UUh_fQHt8AU zm9nrZ@`)ICGR`!M8TD%yOjbO|JO=59?u-s*0XAJiwpm!G?GaH!{z z^}O>7(q-V0I;C;oTcj5-tzNSoESdfA0_jBr)jKv~U)TT9TLP&++w4PQ9ue9ny^Li~ zN%u&vpj~}*oOe4d${saJxVl~DDM)%1D~}vSn$pJC&LXKkt$bqczU{k8`W#NHU)sp+ ztdmf5$h^Ka3^^zBq;380{VubHb(FoG=M1g9fo*(s182NH2WLd?8pn463LfkonHw=g zHj#SletU(Yv5C+z_BLrqg-CB<%|lR@EB%ZHu3S3MPu$es$fJr!P|a=d@gQn=8-7lrmb0ki0P49N z#7hWp6hU4@h^NrNF@!mU2zR5AdlBV&#JCAfJc>9s<20W`GxsCGL9}oQt(-%W&!UYZ zx6sZjNbx4p+=mP&(7`EWc^;iShc2E*jyuuK!{}i`FXxfx8T7Fq{d^GvT*M&vV2IaH zV4%n?80G>-cpRe~Mv1#H#;q7TbNzbZf1%=H AqyPW_ diff --git a/testdoubles/fakes/callables.py b/testdoubles/fakes/callables.py index 45ce76f..a6d0101 100644 --- a/testdoubles/fakes/callables.py +++ b/testdoubles/fakes/callables.py @@ -6,6 +6,23 @@ python3 = sys.version_info[0] == 3 + +class CallableInternalAttributesBaseMixin(object): + @property + def __name__(self): + if not self.is_instance_method and not inspect.isfunction(self.live): + return self.live.__class__.__name__ + + return self.live.__name__ + + @property + def __self__(self): + try: + return self.live.__self__ + except AttributeError: + raise AttributeError("'function' object has no attribute '__self__'") + + if python3: class CallableIntrospectionMixin(object): @property @@ -22,13 +39,8 @@ def is_unbound_instance_method(self): def is_instance_method(self): return inspect.ismethod(self.live) or self.is_unbound_instance_method - class CallableInternalAttributesMixin(object): - @property - def __name__(self): - if not self.is_instance_method and not inspect.isfunction(self.live): - return self.live.__class__.__name__ - - return self.live.__name__ + class CallableInternalAttributesMixin(CallableInternalAttributesBaseMixin): + pass else: class CallableIntrospectionMixin(object): @property @@ -39,13 +51,10 @@ def is_unbound_instance_method(self): def is_instance_method(self): return inspect.ismethod(self.live) or self.is_unbound_instance_method - class CallableInternalAttributesMixin(object): + class CallableInternalAttributesMixin(CallableInternalAttributesBaseMixin): @property - def __name__(self): - if not self.is_instance_method and not inspect.isfunction(self.live): - return self.live.__class__.__name__ - - return self.live.__name__ + def im_self(self): + return self.__self__ class FakeCallable(CallableIntrospectionMixin, CallableInternalAttributesMixin): diff --git a/tests/unit/fakes/support/fakes.py b/tests/unit/fakes/support/fakes.py index d1627b6..cfcd58f 100644 --- a/tests/unit/fakes/support/fakes.py +++ b/tests/unit/fakes/support/fakes.py @@ -3,7 +3,7 @@ import mock -def fake_real_callable(): +def fake_live_bound_callable(): mocked_callable = mock.MagicMock() self = mock.PropertyMock() type(mocked_callable).__self__ = self diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 7f4af31..b16535d 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -7,7 +7,7 @@ from testdoubles.fakes import callables from tests.common.compat import mock from tests.common.layers import UnitTestsLayer -from tests.unit.fakes.support.fakes import fake_real_callable +from tests.unit.fakes.support.fakes import fake_live_bound_callable from tests.unit.fakes.support.mocks import mock_are_argspecs_identical, unmock_are_argspecs_identical from tests.unit.fakes.support.stubs import stub_callable, unstub_callable, stub_are_argspecs_identical, unstub_are_argspecs_identical, stub_python_version, unstub_python_version @@ -63,6 +63,33 @@ def test_should_have_the_same_name_as_the_live_object_when_the_live_object_is_a_ case.assertEqual(actual, expected) + @it.should("have a reference to the instance if the method is bound") + def test_should_have_a_reference_to_the_instance_if_the_method_is_bound(case): + live_callable, _ = fake_live_bound_callable() + expected = live_callable.__self__ + + sut = callables.FakeCallable(live_callable) + + actual = sut.__self__ + + case.assertEqual(actual, expected) + + @it.should("raise an attribute error when accessing __self__ and the method is not bound") + def test_should_raise_an_attribute_error_when_accessing_self_and_the_method_is_not_bound(case): + with case.assertRaisesRegexp(AttributeError, + r"'function' object has no attribute '__self__'"): + sut = callables.FakeCallable(mock.DEFAULT) + + _ = sut.__self__ + + @it.should("raise an attribute error when attempting to use the im_self alias") + def test_should_raise_an_attribute_error_when_attempting_to_use_the_im_self_alias(case): + with case.assertRaisesRegexp(AttributeError, + r"'FakeCallable' object has no attribute 'im_self'"): + sut = callables.FakeCallable(mock.DEFAULT) + + _ = sut.im_self + with it.having('a python 2.x runtime2'): @it.has_test_setup def setup(case): @@ -96,6 +123,36 @@ def test_should_have_the_same_name_as_the_live_object_when_the_live_object_is_a_ case.assertEqual(actual, expected) + @it.should("have a reference to the instance if the method is bound") + def test_should_have_a_reference_to_the_instance_if_the_method_is_bound(case): + live_callable, _ = fake_live_bound_callable() + expected = live_callable.__self__ + + sut = callables.FakeCallable(live_callable) + + actual = sut.__self__ + + case.assertEqual(actual, expected) + + @it.should("raise an attribute error when accessing __self__ and the method is not bound") + def test_should_raise_an_attribute_error_when_accessing_self_and_the_method_is_not_bound(case): + with case.assertRaisesRegexp(AttributeError, + r"'function' object has no attribute '__self__'"): + sut = callables.FakeCallable(mock.DEFAULT) + + _ = sut.__self__ + + @it.should("have an attribute named im self that is equal to the __self__ attribute") + def test_should_have_an_attribute_named_im_self_that_is_equal_to_the_self_attribute(case): + live_callable, _ = fake_live_bound_callable() + expected = live_callable.__self__ + + sut = callables.FakeCallable(live_callable) + + actual = sut.im_self + + case.assertEqual(actual, expected) + it.createTests(globals()) with such.A("Fake Function's initialization method") as it: @@ -277,7 +334,7 @@ def test_should_return_true_if_the_live_function_is_an_instance_method(case): @it.should("return true if the live function is an unbound instance method") def test_should_return_true_if_the_live_function_is_an_unbound_instance_method(case): - mocked_callable, self = fake_real_callable() + mocked_callable, self = fake_live_bound_callable() sut = callables.FakeCallable(mocked_callable) @@ -355,7 +412,7 @@ def test_should_detect_unbound_instance_methods_by_inspecting_the_arguments(case @it.should("not detect unbound instance methods by inspecting their self attribute") def test_should_not_detect_unbound_instance_methods_by_inspecting_their_self_attribute(case): - mocked_callable, self = fake_real_callable() + mocked_callable, self = fake_live_bound_callable() sut = callables.FakeCallable(mocked_callable) @@ -379,7 +436,7 @@ def teardown(case): @it.should("return true if the live function is an unbound instance method") def test_should_return_true_if_the_live_function_is_an_unbound_instance_method(case): - mocked_callable, self = fake_real_callable() + mocked_callable, self = fake_live_bound_callable() sut = callables.FakeCallable(mocked_callable) @@ -390,7 +447,7 @@ def test_should_return_true_if_the_live_function_is_an_unbound_instance_method(c @it.should("return false if the live function is a bound instance method") def test_should_return_false_if_the_live_function_is_a_bound_instance_method(case): - mocked_callable, self = fake_real_callable() + mocked_callable, self = fake_live_bound_callable() sut = callables.FakeCallable(mocked_callable) @@ -421,7 +478,7 @@ def test_should_not_detect_unbound_instance_methods_by_inspecting_the_arguments( @it.should("detect unbound instance methods by inspecting their self attribute") def test_should_detect_unbound_instance_methods_by_inspecting_their_self_attribute(case): - mocked_callable, self = fake_real_callable() + mocked_callable, self = fake_live_bound_callable() sut = callables.FakeCallable(mocked_callable) From b127ead384cadd4854d2e7b0d997ed677cf81b58 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 4 Nov 2013 18:11:47 +0200 Subject: [PATCH 35/46] Fake callables now contain a reference to the instance's type they are bound if we are faking a bound method on python 2.7. --- .noseids | 514 +++++++++++++------------ testdoubles/fakes/callables.py | 4 + tests/unit/fakes/test_fake_callable.py | 21 +- 3 files changed, 286 insertions(+), 253 deletions(-) diff --git a/.noseids b/.noseids index 75fbdbf..97c82b3 100644 --- a/.noseids +++ b/.noseids @@ -2,432 +2,442 @@ S'tests' p1 (dp2 -S'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' +S'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' p3 -I6 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" +I80 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' p4 -I15 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' +I72 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0000: should have the same name as the live object' p5 -I81 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' +I66 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p6 -I75 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' +I78 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' p7 -I21 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' +I29 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' p8 -I1 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' +I27 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0000: should have the same name as the live object' p9 -I80 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' +I17 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' p10 -I66 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" +I33 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' p11 -I13 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' +I32 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' p12 -I79 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not bound' +I38 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' p13 -I63 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' +I74 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not bound' p14 -I34 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' +I69 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' p15 -I73 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' +I3 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" p16 -I71 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." +I51 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' p17 -I16 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' +I76 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' p18 -I19 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" +I47 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" p19 -I58 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" +I53 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' p20 -I56 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" +I86 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' p21 -I10 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0000: should have the same name as the live object' +I87 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' p22 -I17 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" +I21 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' p23 -I11 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' +I1 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not bound' p24 -I35 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' +I63 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' p25 -I72 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" +I34 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' p26 -I76 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" +I85 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." p27 -I53 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' +I16 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' p28 -I25 +I35 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" p29 I8 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" p30 -I28 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' +I9 +sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' p31 -I27 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0002: should have a reference to the instance if the method is bound' +I59 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0002: should have a reference to the instance if the method is bound' p32 -I67 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' +I62 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' p33 -I24 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" +I75 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" p34 -I9 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' +I79 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" p35 -I33 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' +I54 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' p36 -I38 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' +I48 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0000: should have the same name as the live object' p37 -I23 -sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' +I60 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' p38 -I59 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' +I43 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0001: should have the same name as the live object when the live object is a callable class instance' p39 -I83 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' +I18 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' p40 -I50 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a value error when the provided live object matches the argspec" +I46 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' p41 -I55 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' +I77 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' p42 -I40 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" +I36 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' p43 -I52 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' +I22 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' p44 -I78 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' +I31 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p45 -I2 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' +I83 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" p46 -I26 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' +I13 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' p47 -I39 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" +I65 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' p48 -I77 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' +I19 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p49 -I82 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' +I58 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" p50 -I32 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' +I10 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' p51 -I37 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" +I25 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0002: should have a reference to the instance if the method is bound' p52 -I54 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0004: should raise an attribute error when attempting to use the im_self alias' +I68 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' p53 -I64 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' +I24 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' p54 -I61 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' +I44 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' p55 -I48 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0000: should have the same name as the live object' +I39 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' p56 -I60 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +I37 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' p57 -I14 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0000: should have the same name as the live object' +I61 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' p58 -I65 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' -p59 -I70 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p60 -I43 +I81 sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p61 +p59 I5 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' -p62 +p60 I30 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0004: should have an attribute named im self that is equal to the __self__ attribute' -p63 -I69 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' -p64 +p61 I42 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0001: should have the same name as the live object when the live object is a callable class instance' +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +p62 +I14 +sS"tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0005: should have an attribute named im_class that is equal to the __self__ attribute's type" +p63 +I71 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' +p64 +I7 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' p65 -I18 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" +I4 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a value error when the provided live object matches the argspec" p66 -I57 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not bound' +I55 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' p67 -I68 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' +I6 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" p68 -I3 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' +I15 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' p69 -I45 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' +I67 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' p70 -I46 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' +I26 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' p71 -I85 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" +I45 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' p72 -I51 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' +I73 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" p73 -I31 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' +I11 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" p74 -I44 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' +I56 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' p75 -I29 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0002: should have a reference to the instance if the method is bound' +I23 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' p76 -I62 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' +I40 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" p77 -I36 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' +I52 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' p78 -I47 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' +I82 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' p79 -I22 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' +I2 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' p80 -I7 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' +I84 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0004: should raise an attribute error when attempting to use the im_self alias' p81 -I20 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' +I64 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0004: should have an attribute named im_self that is equal to the __self__ attribute' p82 -I4 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' +I70 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' p83 -I84 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' +I50 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" p84 +I57 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' +p85 +I28 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' +p86 +I20 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' +p87 I49 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p85 +p88 I41 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p86 +p89 I12 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p87 -I74 ssS'ids' -p88 -(dp89 +p90 +(dp91 I1 -g8 +g23 sI2 -g45 +g79 sI3 -g68 +g15 sI4 -g82 +g65 sI5 -g61 +g59 sI6 -g3 +g67 sI7 -g80 +g64 sI8 g29 sI9 -g34 +g30 sI10 -g21 +g50 sI11 -g23 +g73 sI12 -g86 +g89 sI13 -g11 +g46 sI14 -g57 +g62 sI15 -g4 +g68 sI16 -g17 +g27 sI17 -g22 +g9 sI18 -g65 +g39 sI19 -g18 +g48 sI20 -g81 +g86 sI21 -g7 +g22 sI22 -g79 +g43 sI23 -g37 +g75 sI24 -g33 +g53 sI25 -g28 +g51 sI26 -g46 +g70 sI27 -g31 +g8 sI28 -g30 +g85 sI29 -g75 +g7 sI30 -g62 +g60 sI31 -g73 +g44 sI32 -g50 +g11 sI33 -g35 +g10 sI34 -g14 +g25 sI35 -g24 +g28 sI36 -g77 +g42 sI37 -g51 +g56 sI38 -g36 +g12 sI39 -g47 +g55 sI40 -g42 +g76 sI41 -g85 +g88 sI42 -g64 +g61 sI43 -g60 +g38 sI44 -g74 +g54 sI45 -g69 +g71 sI46 -g70 +g40 sI47 -g78 +g18 sI48 -g55 +g36 sI49 -g84 +g87 sI50 -g40 +g83 sI51 -g72 +g16 sI52 -g43 +g77 sI53 -g27 +g19 sI54 -g52 +g35 sI55 -g41 +g66 sI56 -g20 +g74 sI57 -g66 +g84 sI58 -g19 +g49 sI59 -g38 +g31 sI60 -g56 +g37 sI61 -g54 +g57 sI62 -g76 +g32 sI63 -g13 +g24 sI64 -g53 +g81 sI65 -g58 +g47 sI66 -g10 +g5 sI67 -g32 +g69 sI68 -g67 +g52 sI69 -g63 +g14 sI70 -g59 +g82 sI71 -g16 +g63 sI72 -g25 +g4 sI73 -g15 +g72 sI74 -g87 +g13 sI75 -g6 +g33 sI76 -g26 +g17 sI77 -g48 +g41 sI78 -g44 +g6 sI79 -g12 +g34 sI80 -g9 +g3 sI81 -g5 +g58 sI82 -g49 +g78 sI83 -g39 +g45 sI84 -g83 +g80 sI85 -g71 +g26 +sI86 +g20 +sI87 +g21 ss. \ No newline at end of file diff --git a/testdoubles/fakes/callables.py b/testdoubles/fakes/callables.py index a6d0101..811089c 100644 --- a/testdoubles/fakes/callables.py +++ b/testdoubles/fakes/callables.py @@ -56,6 +56,10 @@ class CallableInternalAttributesMixin(CallableInternalAttributesBaseMixin): def im_self(self): return self.__self__ + @property + def im_class(self): + return self.__self__.__class__ + class FakeCallable(CallableIntrospectionMixin, CallableInternalAttributesMixin): def __init__(self, live, inspect_args=False): diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index b16535d..178669b 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -90,6 +90,14 @@ def test_should_raise_an_attribute_error_when_attempting_to_use_the_im_self_alia _ = sut.im_self + @it.should("raise an attribute error when attempting to use the im_class internal attribute") + def test_should_raise_an_attribute_error_when_attempting_to_use_the_im_class_internal_attribute(case): + with case.assertRaisesRegexp(AttributeError, + r"'FakeCallable' object has no attribute 'im_class'"): + sut = callables.FakeCallable(mock.DEFAULT) + + _ = sut.im_class + with it.having('a python 2.x runtime2'): @it.has_test_setup def setup(case): @@ -142,7 +150,7 @@ def test_should_raise_an_attribute_error_when_accessing_self_and_the_method_is_n _ = sut.__self__ - @it.should("have an attribute named im self that is equal to the __self__ attribute") + @it.should("have an attribute named im_self that is equal to the __self__ attribute") def test_should_have_an_attribute_named_im_self_that_is_equal_to_the_self_attribute(case): live_callable, _ = fake_live_bound_callable() expected = live_callable.__self__ @@ -153,6 +161,17 @@ def test_should_have_an_attribute_named_im_self_that_is_equal_to_the_self_attrib case.assertEqual(actual, expected) + @it.should("have an attribute named im_class that is equal to the __self__ attribute's type") + def test_should_have_an_attribute_named_im_self_that_is_equal_to_the_self_attribute_type(case): + live_callable, _ = fake_live_bound_callable() + expected = live_callable.__self__.__class__ + + sut = callables.FakeCallable(live_callable) + + actual = sut.im_class + + case.assertEqual(actual, expected) + it.createTests(globals()) with such.A("Fake Function's initialization method") as it: From ddee2e581edf6caf758e1dcbf1d7d1f8256261c2 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Tue, 5 Nov 2013 09:59:15 +0200 Subject: [PATCH 36/46] Fake callables now contain a reference to the fake unbound version of the method if the method is bound. --- .noseids | 390 +++++++++++++------------ testdoubles/fakes/callables.py | 10 + tests/unit/fakes/support/fakes.py | 8 + tests/unit/fakes/test_fake_callable.py | 63 +++- 4 files changed, 290 insertions(+), 181 deletions(-) diff --git a/.noseids b/.noseids index 97c82b3..932e271 100644 --- a/.noseids +++ b/.noseids @@ -4,16 +4,16 @@ p1 (dp2 S'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' p3 -I80 +I86 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' p4 -I72 +I78 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0000: should have the same name as the live object' p5 -I66 +I69 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p6 -I78 +I84 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' p7 I29 @@ -34,410 +34,440 @@ p12 I38 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' p13 -I74 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not bound' +I80 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0007: should not have a reference to the fake unbound version of the method if the method is unbound' p14 -I69 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' +I67 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not bound' p15 +I72 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' +p16 I3 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" -p16 +p17 I51 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p17 -I76 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' p18 +I82 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' +p19 I47 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" -p19 +p20 I53 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' -p20 -I86 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' p21 -I87 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' +I92 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0006: should have a reference to the fake unbound version of the method if the method is bound' p22 +I66 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0008: should raise an attribute error when accessing __func__ and the method is not bound' +p23 +I77 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' +p24 +I93 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' +p25 I21 sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' -p23 +p26 I1 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not bound' -p24 +p27 I63 sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' -p25 +p28 I34 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' -p26 -I85 +p29 +I91 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." -p27 +p30 I16 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' -p28 +p31 I35 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" -p29 +p32 I8 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" -p30 +p33 I9 sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' -p31 +p34 I59 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0002: should have a reference to the instance if the method is bound' -p32 +p35 I62 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' -p33 -I75 +p36 +I81 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" -p34 -I79 +p37 +I85 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" -p35 +p38 I54 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' -p36 +p39 I48 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0000: should have the same name as the live object' -p37 +p40 I60 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p38 +p41 I43 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0001: should have the same name as the live object when the live object is a callable class instance' -p39 +p42 I18 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' -p40 +p43 I46 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' -p41 -I77 +p44 +I83 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p42 +p45 I36 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' -p43 +p46 I22 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' -p44 +p47 I31 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0008: should raise an attribute error when accessing __func__ and the method is not bound' +p48 +I68 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' -p45 -I83 +p49 +I89 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" -p46 +p50 I13 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' -p47 +p51 I65 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' -p48 +p52 I19 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" -p49 +p53 I58 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" -p50 +p54 I10 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' -p51 +p55 I25 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0002: should have a reference to the instance if the method is bound' -p52 -I68 +p56 +I71 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' -p53 +p57 I24 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' -p54 +p58 I44 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p55 +p59 I39 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' -p56 +p60 I37 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0006: should have a reference to the fake unbound version of the method if the method is bound' +p61 +I75 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' -p57 +p62 I61 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' -p58 -I81 +p63 +I87 sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p59 +p64 I5 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' -p60 +p65 I30 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' -p61 +p66 I42 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" -p62 +p67 I14 sS"tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0005: should have an attribute named im_class that is equal to the __self__ attribute's type" -p63 -I71 +p68 +I74 sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p64 +p69 I7 sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p65 +p70 I4 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a value error when the provided live object matches the argspec" -p66 +p71 I55 sS'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' -p67 +p72 I6 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" -p68 +p73 I15 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' -p69 -I67 +p74 +I70 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' -p70 +p75 I26 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' -p71 +p76 I45 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' -p72 -I73 +p77 +I79 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" -p73 +p78 I11 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" -p74 +p79 I56 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' -p75 +p80 I23 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' -p76 +p81 I40 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" -p77 +p82 I52 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' -p78 -I82 +p83 +I88 sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' -p79 +p84 I2 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' -p80 -I84 +p85 +I90 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0007: should not have a reference to the fake unbound version of the method if the method is unbound' +p86 +I76 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0004: should raise an attribute error when attempting to use the im_self alias' -p81 +p87 I64 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0004: should have an attribute named im_self that is equal to the __self__ attribute' -p82 -I70 +p88 +I73 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' -p83 +p89 I50 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" -p84 +p90 I57 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' -p85 +p91 I28 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' -p86 +p92 I20 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' -p87 +p93 I49 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p88 +p94 I41 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p89 +p95 I12 ssS'ids' -p90 -(dp91 +p96 +(dp97 I1 -g23 +g26 sI2 -g79 +g84 sI3 -g15 +g16 sI4 -g65 +g70 sI5 -g59 +g64 sI6 -g67 +g72 sI7 -g64 +g69 sI8 -g29 +g32 sI9 -g30 +g33 sI10 -g50 +g54 sI11 -g73 +g78 sI12 -g89 +g95 sI13 -g46 +g50 sI14 -g62 +g67 sI15 -g68 +g73 sI16 -g27 +g30 sI17 g9 sI18 -g39 +g42 sI19 -g48 +g52 sI20 -g86 +g92 sI21 -g22 +g25 sI22 -g43 +g46 sI23 -g75 +g80 sI24 -g53 +g57 sI25 -g51 +g55 sI26 -g70 +g75 sI27 g8 sI28 -g85 +g91 sI29 g7 sI30 -g60 +g65 sI31 -g44 +g47 sI32 g11 sI33 g10 sI34 -g25 -sI35 g28 +sI35 +g31 sI36 -g42 +g45 sI37 -g56 +g60 sI38 g12 sI39 -g55 +g59 sI40 -g76 +g81 sI41 -g88 +g94 sI42 -g61 +g66 sI43 -g38 +g41 sI44 -g54 +g58 sI45 -g71 +g76 sI46 -g40 +g43 sI47 -g18 +g19 sI48 -g36 +g39 sI49 -g87 +g93 sI50 -g83 +g89 sI51 -g16 +g17 sI52 -g77 +g82 sI53 -g19 +g20 sI54 -g35 +g38 sI55 -g66 +g71 sI56 -g74 +g79 sI57 -g84 +g90 sI58 -g49 +g53 sI59 -g31 +g34 sI60 -g37 +g40 sI61 -g57 +g62 sI62 -g32 +g35 sI63 -g24 +g27 sI64 -g81 +g87 sI65 -g47 +g51 sI66 -g5 +g22 sI67 -g69 +g14 sI68 -g52 +g48 sI69 -g14 +g5 sI70 -g82 +g74 sI71 -g63 +g56 sI72 -g4 +g15 sI73 -g72 +g88 sI74 -g13 +g68 sI75 -g33 +g61 sI76 -g17 +g86 sI77 -g41 +g23 sI78 -g6 +g4 sI79 -g34 +g77 sI80 -g3 +g13 sI81 -g58 +g36 sI82 -g78 +g18 sI83 -g45 +g44 sI84 -g80 +g6 sI85 -g26 +g37 sI86 -g20 +g3 sI87 +g63 +sI88 +g83 +sI89 +g49 +sI90 +g85 +sI91 +g29 +sI92 g21 +sI93 +g24 ss. \ No newline at end of file diff --git a/testdoubles/fakes/callables.py b/testdoubles/fakes/callables.py index 811089c..db50676 100644 --- a/testdoubles/fakes/callables.py +++ b/testdoubles/fakes/callables.py @@ -22,6 +22,16 @@ def __self__(self): except AttributeError: raise AttributeError("'function' object has no attribute '__self__'") + @property + def __func__(self): + if not self.is_instance_method: + raise AttributeError("'function' object has no attribute '__func__'") + + if self.is_unbound_instance_method: + return None + + return self.fake.__func__ + if python3: class CallableIntrospectionMixin(object): diff --git a/tests/unit/fakes/support/fakes.py b/tests/unit/fakes/support/fakes.py index cfcd58f..7ba914d 100644 --- a/tests/unit/fakes/support/fakes.py +++ b/tests/unit/fakes/support/fakes.py @@ -7,4 +7,12 @@ def fake_live_bound_callable(): mocked_callable = mock.MagicMock() self = mock.PropertyMock() type(mocked_callable).__self__ = self + return mocked_callable, self + + +def fake_live_unbound_callable(): + mocked_callable = mock.MagicMock() + self = mock.PropertyMock() + self.return_value = None + type(mocked_callable).__self__ = self return mocked_callable, self \ No newline at end of file diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 178669b..86a128f 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -7,7 +7,7 @@ from testdoubles.fakes import callables from tests.common.compat import mock from tests.common.layers import UnitTestsLayer -from tests.unit.fakes.support.fakes import fake_live_bound_callable +from tests.unit.fakes.support.fakes import fake_live_bound_callable, fake_live_unbound_callable from tests.unit.fakes.support.mocks import mock_are_argspecs_identical, unmock_are_argspecs_identical from tests.unit.fakes.support.stubs import stub_callable, unstub_callable, stub_are_argspecs_identical, unstub_are_argspecs_identical, stub_python_version, unstub_python_version @@ -98,6 +98,36 @@ def test_should_raise_an_attribute_error_when_attempting_to_use_the_im_class_int _ = sut.im_class + @it.should("have a reference to the fake unbound version of the method if the method is bound") + def test_should_have_a_reference_to_the_fake_unbound_version_of_the_method_if_the_method_is_bound(case): + live_callable, _ = fake_live_bound_callable() + + sut = callables.FakeCallable(live_callable) + expected = sut.fake.__func__ + with mock.patch('inspect.ismethod', return_value=True): + actual = sut.__func__ + + case.assertEqual(actual, expected) + + @it.should("not have a reference to the fake unbound version of the method if the method is unbound") + def test_should_not_have_a_reference_to_the_fake_unbound_version_of_the_method_if_the_method_is_unbound(case): + live_callable, _ = fake_live_unbound_callable() + sut = callables.FakeCallable(live_callable) + expected = None + with mock.patch('inspect.ismethod', return_value=False): + with mock.patch('inspect.getargspec', return_value=ArgSpec(['self'], None, None, None)): + actual = sut.__func__ + + case.assertEqual(actual, expected) + + @it.should("raise an attribute error when accessing __func__ and the method is not bound") + def test_should_raise_an_attribute_error_when_accessing_func_and_the_method_is_not_bound(case): + with case.assertRaisesRegexp(AttributeError, + r"'function' object has no attribute '__func__'"): + sut = callables.FakeCallable(mock.DEFAULT) + + _ = sut.__func__ + with it.having('a python 2.x runtime2'): @it.has_test_setup def setup(case): @@ -172,6 +202,37 @@ def test_should_have_an_attribute_named_im_self_that_is_equal_to_the_self_attrib case.assertEqual(actual, expected) + @it.should("have a reference to the fake unbound version of the method if the method is bound") + def test_should_have_a_reference_to_the_fake_unbound_version_of_the_method_if_the_method_is_bound(case): + live_callable, _ = fake_live_bound_callable() + + sut = callables.FakeCallable(live_callable) + expected = sut.fake.__func__ + with mock.patch('inspect.ismethod', return_value=True): + actual = sut.__func__ + + case.assertEqual(actual, expected) + + @it.should("not have a reference to the fake unbound version of the method if the method is unbound") + def test_should_not_have_a_reference_to_the_fake_unbound_version_of_the_method_if_the_method_is_unbound(case): + live_callable, _ = fake_live_unbound_callable() + sut = callables.FakeCallable(live_callable) + expected = None + + with mock.patch('inspect.ismethod', return_value=True): + actual = sut.__func__ + + case.assertEqual(actual, expected) + + @it.should("raise an attribute error when accessing __func__ and the method is not bound") + def test_should_raise_an_attribute_error_when_accessing_func_and_the_method_is_not_bound(case): + with case.assertRaisesRegexp(AttributeError, + r"'function' object has no attribute '__func__'"): + sut = callables.FakeCallable(mock.DEFAULT) + + with mock.patch('inspect.ismethod', return_value=False): + _ = sut.__func__ + it.createTests(globals()) with such.A("Fake Function's initialization method") as it: From bbcf8b583020cb68a445f48db3a7b789613b3b49 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Tue, 5 Nov 2013 10:14:33 +0200 Subject: [PATCH 37/46] Fix tests for python 3. I forgot to mock getargspec. --- .noseids | Bin 17134 -> 16327 bytes tests/unit/fakes/test_fake_callable.py | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.noseids b/.noseids index 932e27106d4a325b76499d55ec48ef494693a235..bcd8f96fcd22d339453274e7a06364f88facc5b5 100644 GIT binary patch delta 2534 zcmZuy+i#m^8E@*GUdM^;IC0_}96NCu$98PzU^_?W(46QH#PrX4h(+;9OGsSu}Wpsr|eF__3LATjL^fbzY5`Q%h^`906` zKF8nh_x(0PnBF($D{IH>zhBT%<;{hJ)s<^kYCgm z6^L*sQOj%DNuf$HAb+5(4~ECtUE}0LbX%x0Kz>78!+o>d7MKyL9C7)M$rs|6+gsRE zpWuUjFQ)^+SLQ1wX4 z7mY=~cJj{xPIl*fe6PGiC_hffA0Ex5*ZqFTIz$7U@)z23Cwq~12Aur&8V?8KJ$%Jc z#y_vMF42f>`Axgl?RbtqU*{GofRy~Mw%Xe{$T|7B#!7zEyD3x?+T~4?RbSw$P|aA9 zZ)%IZoov(nVIA-OSb(}r*TGnq7%*nqU z2~|J!}`tR-H z^_QOs?OuIi|LIGYEfE^PhS{6m(5DF}Uk)z`mBFN`{$Thup|a>R_tV=h@FIuqVlR#T zG5(vom7g0+2sMa08yEkFF+=Ehw69y;7K(>)PX6AW>{hphGPkRMw)IF}s1XE;EdL~G zv3wL`^1dB^;Jz%>80rnKH4pAKbr&@4&!wG0<>8e-vSXu}MWM#gV2iGfeMzVZ)XLx4 zF^4sF{aU{1@Ng>B%)Y3N?dL)0xhY9r-eF=tnt`rEbL(xr{o(Z=Nm%J z!69GQU*W#jg_=i?VTgWF&^@5buwAQL;dilsw5{1YoN!o7T|}$lVNp+>66y?G@~z^m zX$!Yb&ih&D?EdzKSA<%|+@oC=G{S*rauAQ3~7D)QI!cj|+5ue?R#j$#dsh delta 3429 zcmY*cO>9(E6wV;p=5< z(P)eb)U(h?gt|15bmL0J7~@aG1slT#5_Q`cl(ieb@7#Ix&2DnfyXT(!-S2$on_n9D z-%UL}adv4cI6l5|Zh2*SJXk6QSSVpZbJ-J`nJMU6l-3*B{71v-G~(sJ)xu!e;)A-d zt*Y00o@SsDxTt1Dz}_Ug@gfx&9v!a9PZmUXRjK(FuFuDyLxdNf!Hk+Nbt zA4H4#Rq-NsM1d=D$GAR-7WC_(6)x7W7}?_Lmb!j6zMqTrz!m*sDnGEgZ-?F(5A;mF zUB7v((200)DsbiU!~Dkw7j3nO)sn5o_5P9X)!Fnj7A+y_Z zKu}L+@>lpcb;_cEAoMRC1H=bC)oxcP;rfxkV4O8GDT$) zgIXCMx9orb=kt95LHugxW{oW+AmL;FWM5YkJP^QzK7aGQZ+E?JDFIB`^C&K9t@E@+ z07{(+M{(G!{v8bJ-1HHGQwBJ|on^#FZRCTP1!Z!i+T8aAsS3t8(t?Rz(+^8WY!O&^ zs;2T~uyR1JJkr5)QH`s{5wd_6Ic5v7db=yoe%G|#y`MfvdQ?e|*7}%ja^z+1Ltna(@8LBnvvWv?!%i)1?Xf7a z@mbl=cc%Nmmq5o-89m;;+p+_r>L#1wGl2;tE6)1fSQeXKm`k&CCI+WXPUs zqO+)ndJo&zWJ)W4=ei>Oz0Yuhin$6|61V?(q7Qj?Mc$W6xhc_;BY_^+F=t-@k;o%r zHGE*_1BjNoHhRpEn&6sgo`_3gjq4u zT-En-EZ^692KC?WtUj~TUKvW^YQB4$2vUm9?lTtv2jN!Z)U%J0kkT~jx`Oa114y??**@Q zm|_j!Uk5ftAc&L~&e93iLt4Q)+awV33HS<)8eEESXoBZL_MsnzsDQ;nTZ8@(x;;!v zp~b>*6dEwfns7vsS3hwzo?6@OA!@%0(OFM;PW{ef_K3$q^9NK#1+00 z1z9*E*tJ4#a;ORiGF_fGbm_t&PJ1Qv6SU7l+d}UloOvht2ShA{#GGdQlOwhXd1*JPJVLKRs~~JFDv8jK V(OU}ttk6vhT`di;aMUjE{U1H5YexV8 diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 86a128f..63df2df 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -105,7 +105,8 @@ def test_should_have_a_reference_to_the_fake_unbound_version_of_the_method_if_th sut = callables.FakeCallable(live_callable) expected = sut.fake.__func__ with mock.patch('inspect.ismethod', return_value=True): - actual = sut.__func__ + with mock.patch('inspect.getargspec', return_value=ArgSpec(['self'], None, None, None)): + actual = sut.__func__ case.assertEqual(actual, expected) From 77df8abaf7b6a622b47c21c5908c02f893234d60 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Tue, 5 Nov 2013 14:03:05 +0200 Subject: [PATCH 38/46] Renamed tests to clarify what is being tested. --- .noseids | Bin 16327 -> 18398 bytes tests/unit/fakes/test_fake_callable.py | 16 ++++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.noseids b/.noseids index bcd8f96fcd22d339453274e7a06364f88facc5b5..2c47a91f28e7b53a50104c232666c9f79c27841f 100644 GIT binary patch literal 18398 zcmcg!%W~t$5xny&5PO+DDfo~?$+r#L8_}2b!46*)5DB&5Aqg4)H7kF;GaKj!x*HG( zL36OBQk}D1{*q_=Bu(DZ5}#0+k4e(gUj0>-?F#(be3JUJ zQ(@l46KxjaakHq}Blew$pA{TPy*O~5rGK8fyqM!qTs{=SWa=4*tj-SaiBTG4yIqKf zJ5RQk^n2E7o4-Cmy@&MqklnndZ}~|=7w30q^^~k{{!GdXF5sB0jf$;Eczf1pC_QG$ ziT?+kQqhMT|57~vC)?GK;cg+e_mJTiWdeQrnRw$HUqk&jzAv)s^sUAfx^kz-0!K`W z7kj7r7|qT9vN+%4hF4aLFPGD<&WjVwvR9YCCBH+r$?xr3TWuIEI)<9&u+a3Bq;*~9 z&zCw&va&47tK~whwpIugqP>qtJXZGo59Q>> ztnG)DjaeuEdOv4>xAsiyML2!Q<)uuitb|?(?bS*4XI?Q}tX2zgyR;wwb$7fP4jy6P zPm^PTSR1|Q`V~IxqYRI;#+5$W`$T5eFzMFkamwa$_p=x{=qsOt2z%UTel zQ~<489~j2CkO7^35MB>@j(LEGTKoLvB`X2|El!cDK?SL@!rW-ZPC`T&|#d|?Xs#O zOgueR+2Q5s$?z8|DNnABMp=PrTgNQ5#e|sFUtG7`6J@3?$^dMmyw zUU7QYN`$l2w9RAQ2%WdCL-ptSDJnitQ~(o;g z7SerEoWP&-dljYGtG@>aSOI$O9y~t|J!T?}SsC+ek<@kRxp*r{MvLkR^$M_ga7ZM1)A^ zr8wY|;&HO6L<91@Ifik-8G^A6Z)@P&)=$cMg9aq{IPq}^;pkAzsQO_jUK8zn*!VK@ zaWaoFDY9z_1NK61(V4VoWr#Fu0OM-uc!+~G-a$1z=%oJFxQByFAvw}dM;t`P3OJ;j z`Drs;ybhS0O8mnr0S^ZxT|2%h8$ecX$5LUe=9DiTKv_`CLG#91@>ebc)3nn z%26XfA^Uqqc?j%d&kF@E-ug=Q%yhnR?&#a|$L9i9-auE?Fjm8nd-7-|*g?v?0hT_} zK3gp9x6dIKHH@g%>F88C_xm?d)wvRjq#9nquE7F}GZ}j5a%xiin3-5X z{mAW@^sM>P1^{@=qRQu#XtD*L^BB?@BPpI;(6U1=6=ZqTB~bA5H-ClDj-!UbHzu>r zwY&_KvI7-IGY*gS`_(oZVd3VQxWUsmz@_^+Y|SQY))V?@jX7$NNow+f3YWNd&OX6o zeGNEKW;A&jl}Bz^ZS zCQIhvr;TaW3sp?x?N-ArpIZRW{Tv0n`PBnhxpU&x3`S-hVw8HC#*P8;mfy2bYoIC7 z-JPav3#3A=R-ghkqrKTnjfB>~++b=wP)*^0S9gB0JsSoDj-g9qAwM>j8ENWKPGHre zbN9n>aTK+*cmH`U0(jsz=87H540Xwn+3hA@lOsE9Af#z+KyKQ~ALhti$YLifnk3%> zl8{&Zgu|@@dl{~ejq2%iP6x}b1cmdIgDt4Q3)HrafHPRRQ+=E!phm{X+yhvT*#4BkhvB@W6F_4HMyi%Y zL&sW&RU6tVO**tp>wL&_v;SUDK5QGCO-J)dnLY~AZA()q>A5W@*oYXchB9I?MxbVsSnQ1Wa!YbFyJe@kxu5 zX;`SSN>_w6(g!y&u(w8mewWxf2>68xcVb4!Rsw~GO6*s7a5>O7GEjjU+KyO#~G3hFK#_*nPJd(}ATAPkCC1YkcSu)2GY-Q92jEF4n4m&c7=9;?NLZD}tRaX46B?J1Y9NXj;?Xf3C(L;U)YH0h z7+H2cq#QMZTNh<6bIxtHvnDxa;JO_?`wui=pqsY-%my>tvMV-vAZAnu zv#{EPFn0o(QDJY#jP->Gd;MB(lOhq6ci z>0n^GYJW{JXV$vUJG||RNi$502*+fvmf9kH8FO~s%k6r4`zl-pvx8#v9fvu=aM|91 zDNReaXvdfCRmC1*s%0f@%^rmX0bXKI|7w+4E7V2%D~Lq{;iOgl z;tUo62Hn~TLv8=V?{iZ{QNJE+e{2CYm>@N(oPp?DQNIrKkpu{cZp3y}J~KEi?F_FE zPSkk70K!7#zyK5ILTs#?UP&Nx$~4#Ai$lgtLSQ)oUGeIqAZMs!na0Fj>_q_2PysWy z&_lgKa-h@UfrQsuQLA=cfOkScQ!P#p#{wHx?gA1}Ks-2Ufny#X67+hcU*xiptO2fY zjQivC73^AI{`Ir?KcZTAb)Uru-v9&9^nry!qUo1R!&=ayHMaSu8|HPjNHHuuj;5BA z^f0kbTD@@|iVjFaW@zlvx&FDMgY_!UOhe|H{h97+OnTFRRVOo62*BQ)!0c2^^r@C> zSxuki^2w$?aAnpAHxrn9ol{^NacLWK3f*SLh_6`m5Ey|qVqX_uqh$>nA!0xgWC}c6 zG)ur7h(ObDvg4^w(p1!he;ZHzDy<<6+D+&|fFINVyXx_Lr#0UhhRX+|RRm#u#~DCa zVo(2wF#59M(P2MY1Ecp*tX5qjsVVn$EE3C};sY?9PvwEJYIvO(w=nr59vwn9*`I9j z=x2lhtWXO8UDwWg11&;PXJX%>SypTZ5vDbpI^8gofdtae=Vw-y^QVMFa}N<~p5# z<3(3ZktcVI9?hyt431(^wL8Q;5L7ww?e)Uhxy8Jq9jf*% z)U6plcDfv&vy#NKCn>`+lEChRIpF85yi0?xw)9S?hPy5TE#8UZIl;_0p|$Ubngd2N z*r{190dKdg(|@+j>!m8XY-6`92aV$jso}4yB~vz_GL)L{)i;SOH~cP<)e?buwU9Ii zptj^UHDF&2CJmO{d**1Vwc&s@TnOgp&@BRRaq4G76z zH0RVLEr@M3$tcQYa>-#9_5dX_J`!iiL28;BbfO-FM{@;;6PS`6IrcLp>xV2}NWvBe z2_^f8-2arEEax<<$CX@WO3?vm}0;MBV0P#TwdC5syzc9hIt`0XW%ODnai6je=IsY{5ud`P!HAXOxP>=(E1@%rn)$KQSTopQTK{J&BYH7ATXin3MP2LABTE zSAQt@m|!59q_k>9d!j;g=KJ|Vaq#qwoaqv6n_?gW#G5H9%z6E&>7 zm!laDVI-@DoT#p~9v$*si~g?Q2CO(;T6JYoj=Fs6E6q)U8!;q*Y4caLD&p$X)p{af zEL+a9ifB5mnITTN5w~hi2Gq~vy@JmnZB=jjtSa6T+=>Z@<2!<*XqIm{FQq~=g4=M>D#O7$ zR!2K#<+Jt`XSXH=cc4dpU~k)LJ{;7-WX2*)~%VL|@L$^Fa7*9FIM$!fv${d&IM zlLQ*%t0t#w>{Y>CNXb8$FSBJo$=es)jez{KgOTt3ncyB=mcO!*Rdu%{t`59K>Z+%` z;;Frc-KRf!^Rw5U(yq~qb<2@q!5i5W+=p@dlI_x?jMAPRbF1GbwL1FIZD(ej;omWj z`e($i_6o{XaebBG0YtNP9o2YL!sFKt(56}@Is~6bxucW06L+;f2GNwQ^{Ay(9hNNX zT780tupxi%bb8eC8NtJ-$!_hJdbHL@Fe=}3a#Eoh^(dI9UyZ4s`ZV?^Dy*J4JgD|u zNx@?%l|OXyGu~2l+gGRtN3|xBsB#?C ztLHF*TKT}_TBl8DJ$ux>BF)?d^f~IX4sm^GN$@0E<-W;xJp04Mh~O#Y*$NHHje!>h zPvg9;%;G*Tcn1AW#H#z4i&;#|`&qm%3!X!+e9c76#LOJ)`m}4L(dl@at>%xR6~Vwc zyXo24>n`V!a6EcPeUPjF4+{v|z2xwY_2@+u$?u%(I~8)PkIIVFy{=KgOBj%^+f!R> zAgSFkgSpck{NIC@F`wP?j5nm(YxGX7V9lvx_kZqqP4GojTBmom^4RTHF>`wVtQzC$ ztKK&C*I~clHEd>gY_CD@*gERv+m<`y>OpnXy(V}AC00KU{;?-YOxeBRu+6pojtSm` z@3bFeQo8m_7?igyc7t~59l={TdvasbdPiCCWo)0G%l!#Gmu+;(8_sR>XE%Sq_EPQ5 zSCAtQ?a7Y%Pk-uwuflUv=IYS(kMHx&E#7TK4qd@n+CnbPA&;iuq9F3A7zLDzLMniu zBDkpv9=eJmT7;MCP)y}0p$+(G6Qwi;Kc!Gc0_Aib6*P)Ux`--DqMF80L&K=02?VJ7 z0CnU+kQNZ42}2TE#52V~#RN(>Z`#n5ShdPz;OIge3|fLvAcn7%S9( oi`0fyYQ`F^V4ZrgK|_$#iA`F=C5mIqOVzkcJ=mtpH*d!N3uy@7-v9sr diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 63df2df..1c7e032 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -74,8 +74,8 @@ def test_should_have_a_reference_to_the_instance_if_the_method_is_bound(case): case.assertEqual(actual, expected) - @it.should("raise an attribute error when accessing __self__ and the method is not bound") - def test_should_raise_an_attribute_error_when_accessing_self_and_the_method_is_not_bound(case): + @it.should("raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method") + def test_should_raise_an_attribute_error_when_accessing_self_and_the_method_is_not_a_bound_or_unbound_instance_method(case): with case.assertRaisesRegexp(AttributeError, r"'function' object has no attribute '__self__'"): sut = callables.FakeCallable(mock.DEFAULT) @@ -121,8 +121,8 @@ def test_should_not_have_a_reference_to_the_fake_unbound_version_of_the_method_i case.assertEqual(actual, expected) - @it.should("raise an attribute error when accessing __func__ and the method is not bound") - def test_should_raise_an_attribute_error_when_accessing_func_and_the_method_is_not_bound(case): + @it.should("raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method") + def test_should_raise_an_attribute_error_when_accessing_func_and_the_method_is_not_a_bound_or_unbound_instance_method(case): with case.assertRaisesRegexp(AttributeError, r"'function' object has no attribute '__func__'"): sut = callables.FakeCallable(mock.DEFAULT) @@ -173,8 +173,8 @@ def test_should_have_a_reference_to_the_instance_if_the_method_is_bound(case): case.assertEqual(actual, expected) - @it.should("raise an attribute error when accessing __self__ and the method is not bound") - def test_should_raise_an_attribute_error_when_accessing_self_and_the_method_is_not_bound(case): + @it.should("raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method") + def test_should_raise_an_attribute_error_when_accessing_self_and_the_method_is_not_a_bound_or_unbound_instance_method(case): with case.assertRaisesRegexp(AttributeError, r"'function' object has no attribute '__self__'"): sut = callables.FakeCallable(mock.DEFAULT) @@ -225,8 +225,8 @@ def test_should_not_have_a_reference_to_the_fake_unbound_version_of_the_method_i case.assertEqual(actual, expected) - @it.should("raise an attribute error when accessing __func__ and the method is not bound") - def test_should_raise_an_attribute_error_when_accessing_func_and_the_method_is_not_bound(case): + @it.should("raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method") + def test_should_raise_an_attribute_error_when_accessing_func_and_the_method_is_not_a_bound_or_unbound_instance_method(case): with case.assertRaisesRegexp(AttributeError, r"'function' object has no attribute '__func__'"): sut = callables.FakeCallable(mock.DEFAULT) From 923d65edfbb12ddb10fde86ce9fa415deb9b496b Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Tue, 5 Nov 2013 14:08:21 +0200 Subject: [PATCH 39/46] Added functional tests for the bound method's internal attributes. --- .noseids | Bin 18398 -> 18034 bytes tests/functional/fakes/test_fake_callable.py | 137 +++++++++++++++++++ 2 files changed, 137 insertions(+) diff --git a/.noseids b/.noseids index 2c47a91f28e7b53a50104c232666c9f79c27841f..ad12a9a28848e392527fb3fe63ab75148b0d740a 100644 GIT binary patch delta 2853 zcmZvd*>Bs&5yws4`=cn4l&Fg$bsyA0QMajsq-5P+9h59tE6b87S(3+TYk94xM_N|~ ziU!DKJJkn`dz6z0e?QBv&+6FL*8oWWx|C*{$8@>VZbVH z7LOU5m0NoUm$obSu1JTkgoz@!_$$f6$1PU*uEQ%s=_T@hjlo1Qip(^1Xm5uhE7Iqf zC_yoQJ=xb9w9Dr35EG>+N%eV8Jw{#FE#GhJVxkPC{D;YY-zqcYe~L;mmsfaDbkE4 zekHDXW+Y3x7`2N%>#DRsOTqDfhC~9r@A9 zUp6g&_o^J);OEyhxz0oYZKh|Je9&Z-6WLQtv?E}8Y5GU+0uvo*H$64I*r&R#6CM0! z{5*?)A}MyE%&RD7q6?k+B#ZxLCc4qZUoy3QO=_Hb(48O_pCY~J;jfvRXF`T7?;c~~ zBzkp}M?M|ebdBnv@?|RELdYOlKG;-|SS~HGy%x*5c&TBDGH@ zF`;KaPTq0MKQZuAnABI=9(sidU`nr_xZGB|!o)P7S5BN1=dCg^gXu)rsV+m_%vok) z7Bh)Jzs-9x&>UuU{`&1)x`rs`%v+9ki%ZurkEpK0)P7dW0_JrHlYUV>r?H?{t0{7a zRr@XCw64pfw%Vk%x`ahtqqeGra0W}MX?rMJ$w%RkRILm*nwTtSMHuuw)@IkG zy~@oi7Y@F%bLr`Qv58nhbzJXIr_L*torx`M@=vsXnar|HscgT>#CdF`QvLU6lP}ns z}&=%OMN(geoH1}o*lpmm%hhHRR~6jj1YdB`On8mI#Sa-o2l z&`8qL|WQp(<2RFS@A!4&pdNC(%O#=%ZOoQ#U%P9c>hVpF$X* zYE;q%?9duk$$@<8!$~@iO=?3c6~ajsIP}md3{f3wXc!SHLkXS1A}t_FHK?K-WYG$i z$&FGPLYOwNMpiJ|#ufpS)Q=!V5TaUC(-Kb8A{NL4H`Sw-8c;`J3{nY-C%k5Jic?zcfR}g_1N!U z#WttLr_#ZR?kf{BS7y3{sZ4-_EDm(OlGHB-O8TTNuIq;q`rSy2Zr|6UO&hoBr`5(r zJe&($B^S)t!^idEKvEauoxI2gu3WH->77-bECl*I+s}(a;7UbYbS;@*96aCH6-*Uj zDr0ZN>MFX}*rIovPVtRW;Idg>e7$W<8xxZ}D+ew|E8Ti6KBn(&p5b8yhxt_&ZuADa z*t@F7m~`Z#s_lJ&Ud@cz4YT&4MR45fd#CmM7$Kty}Q4p&j%XK zKcFc`nT+a}tt@DhPVGwZHVbG9jIK+kQ@3e73n+>Pg~mso+B3kS5?bi2>Vx!zodScB zuYZ(RD!ZIlmVo%Q<0IoM`lt^5lhYqY);H5Vz{#Y&H&%0Dc#Gw*7;n;>8{RNK04VFT zjQ~RNX3ttjWr2@xoM}Wx)K_AQ*IdaPx4I`kGlKvm?_XkMi-QUMH?dcbCSKKl4z}`% z96+hiWtYb4hV*g$1cAu`7*vamM`u5`uWE@LK+3aK`Of!j>Kp)yj9k>ARG@S1`|SeI zcsO5l=d9ar^tPE_pix}*(B600P60qM>JUF2FJle*F#qOK6XiH3K2hHhckD%^U-l71 zeR6;3yrlvNDn8ih)JaX(w`#ekM=#YUc#A=B#nt1uva-O=p>D+C_O2UrguGoLocOQ| zn0UJZ2E}MBM)l9GLv{)P3O?L$-e(^NTHE`+U9u&7y{C8Hv=abOh?vIH(!%f_Ee>t7 zTjXAeip;Vcw^QVv_wTT;_P;)9r^q{NP?Ar+-D(4hNL(&-$mp|YmT)Z~)sjz)t@8gV z+c!K)s|C)7=e1Z}Rqw66Kok+N%lHUc%Tnur~nOrNqF@`Q06c4 zBJuoc8vHeFkRTaX4&w^D=W@;}gIRDzA5+x8hpQi%cNX1S^Q2(g0?#_D7OVS5;w^iU zSuc0s68&}U;Vsy~<=GI?q$jb+8gwqT7Mo#%9_eY*2kX`o;1Z`lB+3xIWIE8@#iMo$ zG|JJ)cozSBjV&fnr1S10_Ieo`wADsH%ri%DVK~s<9%r`50v?a(mAg%Wu32-?ULz)} z0#4VzYp(&4OgMyLfFX=1t1I~!SlUlE%~UeVU zkChgC3Sg9dnWKfhqLolgmx(~-JajJYP5@cvTo5X5oRgT$K%ey-V+L3k4hbl^q%^igU7Hg8`oo_2B9J?r+RCGA%?=lMyyT6ZFI{j9r=le(>rrW_+G?&TTQy z!y)RRB}+;c_8o^& zs01lw#eQL#GK6wh>=$;a1h}q*3zQO7h&08kaH?vQHo_f8H6rAD?m=O-$iKn{p>`GS zCUUiK)AS3yMq5k7c3i*JH zFI?GNU&5X2$~9Q#R}r Date: Tue, 5 Nov 2013 14:33:16 +0200 Subject: [PATCH 40/46] Using the compat module so Python 2.6 will also be able to run tests. --- .noseids | Bin 18034 -> 14586 bytes tests/common/compat.py | 2 +- tests/functional/fakes/test_fake_callable.py | 11 +++++------ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.noseids b/.noseids index ad12a9a28848e392527fb3fe63ab75148b0d740a..559db428742393ea92cb44dfc341c94e626fbcda 100644 GIT binary patch delta 1763 zcmZWp>rYc>7#9vN(3V15%B@f+P@oiOOSzXqY0I@g?x=fXT;>JHW2Qp6#JOa{W!bVV zx{1$XmVFR0OJ-(bFj?CQz6kyDEcODls%Pn=v`n)7j5Mtx>d zLAqRAUk~wxM&tV7fRX`a{j(2+K!&`c!H2>oek1L5B@=@0rkxd8$dqTbLay1wndx@E zobDFc$dd1C;0?2p6(ueV$d=z|zz52TFv1`=_&vvQ-m&&6CK&l?(L4tXCjK{?%NAD# zKeL+oV!o5NZB0rJOqcQ>2{Ur!wl3N?Ly%Z`a+6v-vtta9>^^djv=@k38G=Q;yQ35q%Dye1qdksqs!7~d{8vbWF4 z8<}oV3Wr=zp);ZkrSj7~&XI~i;Y69H3dVTN^+Ht+r>4@;8Bu|9O_kzkDiy zM>S*1JuPZclSe(fYOQ*F_gPqA6-sqfDDja=Ja%2(Q&L==7UnvOaH8agRrh^qOTO3RNUrn-;w zYV$GCk9f*Y%O5~LU+KIo1~DMd^VQA+ugv22T~;xKLG^mI>eJ}%2W9Ij&YL|kKR>rL zcX}l`j3N26T6ghBq3dDO?zL!9@ZJ8IVOyXrM`qQyprkA2G5Zm-1kyEC}kxY!?-yklN8og|JgDa;P44G>Crk z!b4*KMbJZKa8M46G>u6rKt9D0rBam86eef{L)3>}@}QP#P)!wZ(l|!R1`E}~y}IiA E50b+$?*IS* delta 2672 zcma)6SxlqX6(0C~F_^{J#w<2AHW)CQ7j~FoUk3Qt8JG(L0|v|-MugQUP0|c~=|ie0 zB{@|h(I}nlUDPIhsZ=RaMp0WuZKX`rs;XM4iQ30JblSHjqfW04b|;31KK=js&Ue1^ z{rA7;e6jbh=TnXgQg(Stm-ph)iqMcMzi}E=urp;u=%C5h;y`;^CjVV?^8J)9A)u27 z@x*v)he(5vPsM>>r}k-jq;anHoJfaW{xF{SlNJ#fNS8l21&qAnHt_pSbL!^7O9h4e zbz3oisMB+xKAZn)HSxdA7GXe!eE(wlBSjBb^=xd&;-@XOA`=Gr;|r-7uHF5e-SB?o zDGsLD&h)(^3z_n6Qh|B%z_q!35D9IsgswN@#m0;#v!BZG~31!h5+e%JYWPw7JmMVR(QSi#vr0x$=#RxIVw(B}Z24DRqB;XW#WCg|}Uy{ac4mgtsHHv)T=> zMK*V~UCO}DZX~?!+BuB)_RKKJuYFb0$WtXYUUmw;U+xwbnBzAiei4kRt{u)zDdf=# zDe_>E-%1kDyLMJ@t9I%)TKG{#tFR(Zevm|pigc$I@rip=RLG1udn8}M4c#sQ+^Udef}ao&d{lhkH4Ab(Of9u*E2WxPLnA%cz*qiaKj~k5@Ua^ z9~Y%?%iqSL$zYV@;f;Anz!HOtn<&ahqNkq`IDRtzMZqGRijG1e=KTHE%(`Eaqw|U0pBAaM?AnH&npX1l_d->R8;NO^ggb#J{#WQ3^_~DZ;B=YTPro_Goz^^Jz zmeFXH7DRxJmRCeQf{GtSALD8bsORpymqjBQV%p#nQ(Vc!vsSy-ght*iY~vDhCOfPd ze9tti z{vtn^^S=?@yMoJnx9CK4;EH@&8Lf=2T>jFQ&o9{gS|>XAp6yw!3!U6;e^+#)OI^7* z>lu4|UyO<#bjx?Yl8J4H5z&ht_5U9)xznWfx?@W8p*PXetJ+obkyD6%^u^9GYGgwU zpkKga~35Q7*{t0Ve{x?BeSxFjI1Vo;enMYhBcuBy!t&p&kaYQq@f9`{Gu2!_?C zwsBW!NB|>h7UQf3UPEl4M*%flES<`N3g{u0;aG2d%;@Q1an{Ga;hd}i~fI;)t6l+PzJ(aAlkb!rQk z=exD9h#Odtzlde$>wY8_aYO#{ENWL%zAu)rD8HLPeEuPE6HD@E3FJJP*!Lh{dwb4$5@QmkS1EL!okv%RrH ztYc07G?w@IYxp0HWg?7q`B4nH)3mH@Ak3dN{YATl4fWjQ$)KOd>l;+9@o0|@rMPtI zQgjO+>}@`~ciT(NXrz4P(GUhH8<~^^1Kq?TWk64(7$Fy&l!Gj)LM7EBKvr0&8eY;v z&{Yf&VT0;WLm@0vEvm_YbaJAY7O_Bs=qCY Date: Tue, 5 Nov 2013 15:30:12 +0200 Subject: [PATCH 41/46] Tests will now run under Python 2.6. --- .noseids | Bin 14586 -> 18940 bytes tests/common/compat.py | 14 ++++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.noseids b/.noseids index 559db428742393ea92cb44dfc341c94e626fbcda..19a5228114c420948ce21d1f00dca4e9b9c0f4d7 100644 GIT binary patch literal 18940 zcmc&+O>^V86};ZCs8>*BS@H%XR!%PM?BZNDbT_8a}KI$xLgwf!dj zwtZ<|#U0(w(x>}b-EFaNNBpi}L;8;c`(8QZ+cx9^EH8rF6< zOCKM+wY_Fv^Um7*^%>^fW-r_P<}LeH>=kTrc!yQ@$@1n$QXO#syL@R)?3RR==dFdZ zU7qauf3PVHy)E!B<;%bGb%QnB&(eoStl<~!0)6(Gc;dIdh5Ao?Q|9&lOM@en>&|v1 zwwRQ!?o7=#+LQlfc39zrZ=DrikNb5~lzX^kuPuL1{(xtTLW@LU_>z%6}9!ac{Al zrFTCk5QkAPWUwsRl^~6%$2M;OBcCq09q`=UVybTnE?LB^+|sqAH%%hOZxT2kmKAX{ zFx=e-XM85Z31g0qm^$CSUKlZ;$w%M3V?fQyfPPuD9K*xeir%$gAc(5@6Q88IXGqm1th8h1*8IA4+Ed0$R=X&;+Yr7 zor-K*{I?|_FBb|a>|3@)_8`OgF(D0liQEzlx0p}%l_<)s>^^J+UIF2>?4omn{T@W_ z*^h6I13!>iPA`7Sg28f2vEa{jB9Uc{DF;Y*81Nd#jHw!UzQ!W~Q!eHrPQ;mnKzdRB zH5cp@>ZcQ0C&e<@{1O2Iy$QsgE^>qw5pE8AdMoHb?9GGJ9zJ!TR3BgJrf8V&lFO?c zS!`P}NWK@%n^>LwAJs*E5VaApe>Q-M_Mc0#uGeHkhZk#t9nup%eRR5v( zf(!)8Fj+ZIrl*>m>t7@+aVCzW40AyYLSU5#h_R$RHaFm@TV{Pi^To10w@{z(1&CiY zPq}3>cz3Z8t+@45A*<)COmU$WE6#*6CCIL5OE97+x1486p`Bd$(9uhG$bE&ctCk~f zSqBwLYoZIEVSNEPAvDK~Z*m+@Ch`!#nWIy$57^x~1pv#4J75-yPU&j$NsFLyC+$MI zPe|CUcJ+Ca&(*DB=CYW-`IsNF=)`oy8DmU3BJ+y=s-6@Fk@_Brm+6zh(ik^blsmiq zF)W%-_3zo$aILxNj-av=;Q8Z+L?Gg(qv{}QAu}U;{f0hAo3|R>U@LIDtXa1T zq7y+__8n+!<+HLUTKZ{0V3`G2=is9Nmc$kN=J zR>g3b_y&#nn>*A9T%AEFTpTFn{)04ZIt&GYVahzABDJ0wX~S`y?7WGyKhKCFG@O=m zXMedB!A`KGJz}9MLXNsD(+gC-F)0n$fn3`N{xH)!r2+P?qN&~;>yd(bKW}r3z+Z-I zJ)@czC%dF4F)0(7Ym9iWSG^i^vMUv@&>r<#wb<3=HXSybMS@_vhco#BgxPj9&@#Z?aISC4@8OJ-oJt-=+Hp(YskdwxuE;Vg|hHWC< z|9jBo1LfK0x5x(x=>(Kwr6-ye9Eqxq_10n2dZZ31Ne2l%(*+-LocupW6qdSXQroS5 z)-n&>x~`3+KgHxi^hl87ihAtQ80tys!WCaFmUQj$r<}d3Ye#4_KsX<%*v##lt_sFJ z*u{Z9PLaf0uO9Z40X5}<&>3Bez)0`WVqkB6dJmF(6s#h^>)HxHU`AL_2n-$?vESgq z;n3coOB8=5+FJ-On+`Yyv%#3!x-nf^pJ|Z%V}#8$raFPsrubMHx|1m|ZsN*>u6CZ_ z0ORx0ffZ=(VRC*Ymi;M87Ja=Gf^VWx#c{jUx$wFyJ4Vi)A`O_hG+{V*-VVF^B41O2 zf$x!12c{>tVy#isM+7EJ6*O*CqFu18nR5JT<0b;l%)troJwKcI6f_q+{8C>SSJ|hTyf20tI6OheAu#8|JrEM zAiFU$kD^xuGDs2A(PtcHUQ@cc;|uw^eh-)u#Vz_J^D@CyXPeACN#G7WDyg3UbuM z9tI23%X^B0VJ%>&>xTF(ahfO^*MrRvjAo~cILc4eD8e6yYZ{`lYg9>>3%dTFt`?1% zGsne}6cc_{9SWbgb^_)^m`_(cgFq96Mb&|v7Xl(Si_JJCwTY8D4~%2f=2QZ$e0DNc z5d2skvr-bbGRSZuGJC{WSOT|2qW(cZ5dvY}Yv0eH&9=J|_q*ivCk#}lk0P%T?lINR zU0&0dJbYX>cm!o(()LnCFrrF3SfUGMOl$@O+?wJhg$=RE9_SK;{|{CmDN7+1tks7% zaxUk&Ju$4h0)}KTQ*P8&H}+I5%a%xnZwS3@9n!O zdHo6q04zoOYO>#IhchBIlHvGOaw{jyQPBZGLnvXLn#Xg!?)0xP{5^v)h|!$%=@M1$*h)%FBgW6um$h(D_KG}VnQng zYfN0W(2Z`{f*FSGKdP;YEAuIG;E4;2)^*(iug420$fb~LmoL)-uUq9+v^U@?MYm=$ zJ7_lx*uf#Nbi|vfeA3b^+AT`eId$S<=Q5%@rPccIKGj`{Q&*KkK!x=H4q`l4R$^CKnl2;VY zJ=rmDYo)kvVRtxLw%PDJ)$wPCsJ(mG9spPnJ>rSW6DVw#=K?cg=U75#x>zLSmmCz^-I%jithV67%S`cVCNp2f z>N3Al@w@RGK9u!*7ReQ-(^*PWeA)r;ohS~?@v#GnNi#=474Lm8-&Z6Oma7z>hr*#E z#lcoStwZtM$UhXH*1~?AV!Fqxa*EgGh*64iic&=JStOjBQLMSp{jo597jEh(N)^uS zDYkQ&cq!g{U@u>hB{)Q(IBd+Kl43)e&zn&CCzs57K77K4((lG6b0(OBbBY-V@Bb?f zYw@`Tiig09PKp7@%Pop|9w#CdZ{)LUt2lAZ`}v9u1-6(KuaGjGQLM|*{qUuH5iF|M z(BrJH;`J$Z`4#UXv$Ui*WxAK%EH7& z@$x#auPQzog@fRV(}1ieD_)>vcCDzFNMec;bQ}RvoRQ_d2*rnTa6Ve`fevguDv}-V zCMW_d>k5iZUrHLqrvY&WOL0zt_cIk6th|V>_&5qa7z1nNFZg8rS{jf=>ca zEYMPWC^iMz;!vz!u(zyO2B*AJ9K`3%7RBKhKI%v5pZHupOMqAQ74Jgv&Vk~CQ+O3x zv0%!vTE)IPpKPP_Pkb($XndHF;==K@igQrRh!ig^aI#PlFsSSm=W_MMFvS~z_>G^; M_wg7MNwvQDA67#D0ssI2 delta 2302 zcmZvc$!}X#6vmsz8LneHv7O0I9A}>6#2M@iPHbmRzD!M9xTVk%DUnV~Ah}7yB!yOD z)zUzsgH+U1KoJtdqJ>R2AQdX0LIRZq-M}BfrX^yB5JFt%^%1*b`F`ISzH{$+_is-7 zOGPfEZ>mG}GX2n@LuVG(RobRHT#qz4slQ)XSzl@oEUzpqF0BQoR~9#xmnNQHU0FLf zx^QNBV{IwGc?AtZrQ@(%)!|$o471(UBa{W{@`6boMka*HfJMG*l6xU5-?cs?R3+y9I(q9rh21iMyOmkse z*3ha@`EZ+LfqzZcb_*|<=p zD3NcbDzifQP-<3+@~l~<3_i0;g3b%&N12%&<-J~=Sq{J4POi6CB6wy*cd9_SnQgdB zC?^`6yy_M_=dkde&BG4@E}<$>A-7U%=qs#3<>OTF&0#Bh<3av?*eX;ts^mMVd4jjQ z=7g$2wc#qww=GmHYE0MTk2%oGQ-@l!&z4a2s54!U>u!1(8&EIbHoA;+UR*DBBO2tZ z2C3%l++2RG&%>KxeP8i%`|_C=msArP;`p}!&^?Ziz8bO~iNkwde@1?a0)sKjg zogn*D44~hbB0=^ih+@E~l_2}>V~EPD2`3e?t3t&QGaM)Mgj+|Ob~}i;;Wk0{oep8} zpx3_3VGJEq-gh{HVPn68VqS00fKa0tk(U#_5+oYx6>1El#wG{Fj!@$mliwJ+k2jmc zI?JbDL>GTwtWSRe6g%xcCDc*O%ll^B1N#?39mCON zGP$$d%DWC5?={!y(z)l=@eP@wGtMoopIcW?Y^o>gsRv;Sql+TwrA%1J4JVCbl&Vol zgNV^l9HB{!lM}gAg$l}tiz?u!E_6^i%4h%)I*y|>i)kuDDcO-j{ph1HjF1I~$%7)A z!X!1J;XD7~Kb68uHdtvMb5sB~4Ixe?@X!&=(gemRh5@QaE!Cik{P58X OrpSdnszvq2M&Ms@MT-;w diff --git a/tests/common/compat.py b/tests/common/compat.py index 371793a..5dcd122 100644 --- a/tests/common/compat.py +++ b/tests/common/compat.py @@ -1,13 +1,19 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import six +import sys + try: from unittest import mock except ImportError: import mock -try: - import unittest -except ImportError: - import unittest2 as unittest +if not six.PY3 and sys.version_info[1] == 6: + import unittest2 as unittest +else: + try: + import unittest + except ImportError: + import unittest2 as unittest __all__ = ['mock', 'unittest'] \ No newline at end of file From b6a3e9bd9c6dc713666212a2ba50d7e6eca289dd Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Tue, 5 Nov 2013 16:54:28 +0200 Subject: [PATCH 42/46] Fake callables will now return the live callable's docstring instead of their own. --- .noseids | 561 ++++++++++--------- testdoubles/fakes/callables.py | 6 + tests/functional/fakes/test_fake_callable.py | 13 + tests/unit/fakes/test_fake_callable.py | 18 + 4 files changed, 325 insertions(+), 273 deletions(-) diff --git a/.noseids b/.noseids index 19a5228..5f6dd14 100644 --- a/.noseids +++ b/.noseids @@ -4,515 +4,530 @@ p1 (dp2 S'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' p3 -I95 +I98 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' p4 -I87 +I90 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0000: should have the same name as the live object' p5 -I78 +I80 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p6 -I93 +I96 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' p7 I22 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' p8 -I38 +I39 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' p9 -I36 +I37 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0008: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' p10 -I77 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0000: should have the same name as the live object' +I78 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0009: should have the same docstring as the live callable' p11 +I79 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0000: should have the same name as the live object' +p12 I17 sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' -p12 -I42 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' p13 -I41 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' +I43 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0009: should have the same docstring as the live callable' p14 -I47 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' +I89 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' p15 -I81 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' +I42 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' p16 -I89 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0007: should not have a reference to the fake unbound version of the method if the method is unbound' +I48 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' p17 -I76 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' +I83 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' p18 +I92 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0007: should not have a reference to the fake unbound version of the method if the method is unbound' +p19 +I77 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' +p20 I3 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" -p19 -I60 +p21 +I61 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p20 -I91 +p22 +I94 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' -p21 -I56 +p23 +I57 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" -p22 -I62 +p24 +I63 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' -p23 -I101 +p25 +I104 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0006: should have a reference to the fake unbound version of the method if the method is bound' -p24 -I75 +p26 +I76 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0008: should have a reference to the fake unbound version of the method if the method is bound' -p25 +p27 I25 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' -p26 -I102 +p28 +I105 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' -p27 -I30 +p29 +I31 sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' -p28 +p30 I1 sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' -p29 -I43 +p31 +I44 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' -p30 -I100 +p32 +I103 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." -p31 +p33 I16 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' -p32 -I44 +p34 +I45 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" -p33 +p35 I8 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0008: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' -p34 -I86 +p36 +I88 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" -p35 +p37 I9 sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' -p36 -I68 +p38 +I69 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0002: should have a reference to the instance if the method is bound' -p37 -I71 +p39 +I72 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' -p38 -I90 +p40 +I93 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" -p39 -I94 +p41 +I97 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" -p40 -I63 +p42 +I64 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' -p41 -I57 +p43 +I58 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0000: should have the same name as the live object' -p42 -I69 +p44 +I70 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p43 -I52 +p45 +I53 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0001: should have the same name as the live object when the live object is a callable class instance' -p44 +p46 I18 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' -p45 -I55 +p47 +I56 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' -p46 -I92 +p48 +I95 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p47 -I45 +p49 +I46 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' -p48 -I31 +p50 +I32 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' -p49 -I40 +p51 +I41 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' -p50 -I98 +p52 +I101 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" -p51 +p53 I13 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0004: should raise an attribute error when attempting to use the im_self alias' -p52 +p54 I21 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' -p53 -I74 +p55 +I75 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' -p54 -I28 +p56 +I29 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" -p55 -I67 +p57 +I68 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" -p56 +p58 I10 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' -p57 -I34 +p59 +I35 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0002: should have a reference to the instance if the method is bound' -p58 -I80 +p60 +I82 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' -p59 -I33 +p61 +I34 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' -p60 -I53 +p62 +I54 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' -p61 -I79 +p63 +I81 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p62 -I48 +p64 +I49 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' -p63 -I46 +p65 +I47 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0006: should have a reference to the fake unbound version of the method if the method is bound' -p64 -I84 +p66 +I86 sS"tests.functional.fakes.test_fake_callable.A Fake Function object.test 0007: should have an attribute named im_class that is equal to the __self__ attribute's type" -p65 +p67 I24 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' -p66 -I70 +p68 +I71 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' -p67 -I96 +p69 +I99 sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p68 +p70 I5 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' -p69 -I39 +p71 +I40 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' -p70 -I51 +p72 +I52 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" -p71 +p73 I14 sS"tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0005: should have an attribute named im_class that is equal to the __self__ attribute's type" -p72 -I83 +p74 +I85 sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p73 +p75 I7 sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p74 +p76 I4 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a value error when the provided live object matches the argspec" -p75 -I64 +p77 +I65 sS'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' -p76 +p78 I6 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" -p77 +p79 I15 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' -p78 +p80 I20 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' -p79 -I35 +p81 +I36 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' -p80 -I54 +p82 +I55 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' -p81 -I88 +p83 +I91 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0002: should have a reference to the instance if the method is bound' -p82 +p84 I19 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" -p83 +p85 I11 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' -p84 -I72 +p86 +I73 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" -p85 -I65 +p87 +I66 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' -p86 -I32 +p88 +I33 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0006: should have an attribute named im_self that is equal to the __self__ attribute' -p87 +p89 I23 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0011: should have the same docstring as the live callable' +p90 +I28 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' -p88 -I49 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" -p89 -I61 +p91 +I50 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" +p92 +I62 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' -p90 -I97 +p93 +I100 sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' -p91 +p94 I2 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' -p92 -I99 +p95 +I102 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0010: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' -p93 +p96 I27 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0007: should not have a reference to the fake unbound version of the method if the method is unbound' -p94 -I85 +p97 +I87 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0004: should raise an attribute error when attempting to use the im_self alias' -p95 -I73 +p98 +I74 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0004: should have an attribute named im_self that is equal to the __self__ attribute' -p96 -I82 +p99 +I84 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' -p97 -I59 +p100 +I60 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" -p98 -I66 +p101 +I67 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0009: should not have a reference to the fake unbound version of the method if the method is unbound' -p99 +p102 I26 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' -p100 -I37 +p103 +I38 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' -p101 -I29 +p104 +I30 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' -p102 -I58 +p105 +I59 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p103 -I50 +p106 +I51 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p104 +p107 I12 ssS'ids' -p105 -(dp106 +p108 +(dp109 I1 -g28 +g30 sI2 -g91 +g94 sI3 -g18 +g20 sI4 -g74 +g76 sI5 -g68 +g70 sI6 -g76 +g78 sI7 -g73 +g75 sI8 -g33 -sI9 g35 +sI9 +g37 sI10 -g56 +g58 sI11 -g83 +g85 sI12 -g104 +g107 sI13 -g51 +g53 sI14 -g71 +g73 sI15 -g77 +g79 sI16 -g31 +g33 sI17 -g11 +g12 sI18 -g44 +g46 sI19 -g82 +g84 sI20 -g78 +g80 sI21 -g52 +g54 sI22 g7 sI23 -g87 +g89 sI24 -g65 +g67 sI25 -g25 +g27 sI26 -g99 +g102 sI27 -g93 +g96 sI28 -g54 +g90 sI29 -g101 +g56 sI30 -g27 +g104 sI31 -g48 +g29 sI32 -g86 +g50 sI33 -g59 +g88 sI34 -g57 +g61 sI35 -g79 +g59 sI36 -g9 +g81 sI37 -g100 +g9 sI38 -g8 +g103 sI39 -g69 +g8 sI40 -g49 +g71 sI41 -g13 +g51 sI42 -g12 +g15 sI43 -g29 +g13 sI44 -g32 +g31 sI45 -g47 +g34 sI46 -g63 +g49 sI47 -g14 +g65 sI48 -g62 +g16 sI49 -g88 +g64 sI50 -g103 +g91 sI51 -g70 +g106 sI52 -g43 +g72 sI53 -g60 +g45 sI54 -g80 +g62 sI55 -g45 +g82 sI56 -g21 +g47 sI57 -g41 +g23 sI58 -g102 +g43 sI59 -g97 +g105 sI60 -g19 +g100 sI61 -g89 +g21 sI62 -g22 +g92 sI63 -g40 +g24 sI64 -g75 +g42 sI65 -g85 +g77 sI66 -g98 +g87 sI67 -g55 +g101 sI68 -g36 +g57 sI69 -g42 +g38 sI70 -g66 +g44 sI71 -g37 +g68 sI72 -g84 +g39 sI73 -g95 +g86 sI74 -g53 +g98 sI75 -g24 +g55 sI76 -g17 +g26 sI77 -g10 +g19 sI78 -g5 +g10 sI79 -g61 +g11 sI80 -g58 +g5 sI81 -g15 +g63 sI82 -g96 +g60 sI83 -g72 +g17 sI84 -g64 +g99 sI85 -g94 +g74 sI86 -g34 +g66 sI87 -g4 +g97 sI88 -g81 +g36 sI89 -g16 +g14 sI90 -g38 +g4 sI91 -g20 +g83 sI92 -g46 +g18 sI93 -g6 +g40 sI94 -g39 +g22 sI95 -g3 +g48 sI96 -g67 +g6 sI97 -g90 +g41 sI98 -g50 +g3 sI99 -g92 +g69 sI100 -g30 +g93 sI101 -g23 +g52 sI102 -g26 +g95 +sI103 +g32 +sI104 +g25 +sI105 +g28 ss. \ No newline at end of file diff --git a/testdoubles/fakes/callables.py b/testdoubles/fakes/callables.py index db50676..db3328a 100644 --- a/testdoubles/fakes/callables.py +++ b/testdoubles/fakes/callables.py @@ -32,6 +32,12 @@ def __func__(self): return self.fake.__func__ + def __getattribute__(self, item): + if item == '__doc__': + return self.live.__doc__ + + return super(CallableInternalAttributesBaseMixin, self).__getattribute__(item) + if python3: class CallableIntrospectionMixin(object): diff --git a/tests/functional/fakes/test_fake_callable.py b/tests/functional/fakes/test_fake_callable.py index 542951b..925e629 100644 --- a/tests/functional/fakes/test_fake_callable.py +++ b/tests/functional/fakes/test_fake_callable.py @@ -168,6 +168,19 @@ def foo(): _ = sut.__func__ + @it.should("have the same docstring as the live callable") + def test_should_have_the_same_docstring_as_the_live_callable(case): + def foo(): + """Docstring""" + pass + + sut = FakeCallable(foo) + expected = foo.__doc__ + + actual = sut.__doc__ + + case.assertEqual(actual, expected) + it.createTests(globals()) with such.A("Fake Function's initialization method") as it: diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 1c7e032..6d90d8d 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -129,6 +129,15 @@ def test_should_raise_an_attribute_error_when_accessing_func_and_the_method_is_n _ = sut.__func__ + @it.should("have the same docstring as the live callable") + def test_should_have_the_same_docstring_as_the_live_callable(case): + sut = callables.FakeCallable(mock.DEFAULT) + expected = mock.DEFAULT.__doc__ + + actual = sut.__doc__ + + case.assertEqual(actual, expected) + with it.having('a python 2.x runtime2'): @it.has_test_setup def setup(case): @@ -234,6 +243,15 @@ def test_should_raise_an_attribute_error_when_accessing_func_and_the_method_is_n with mock.patch('inspect.ismethod', return_value=False): _ = sut.__func__ + @it.should("have the same docstring as the live callable") + def test_should_have_the_same_docstring_as_the_live_callable(case): + sut = callables.FakeCallable(mock.DEFAULT) + expected = mock.DEFAULT.__doc__ + + actual = sut.__doc__ + + case.assertEqual(actual, expected) + it.createTests(globals()) with such.A("Fake Function's initialization method") as it: From 09a6f9fd18f2ef53b54070ccaa2d3c74b4156e98 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Tue, 5 Nov 2013 17:32:02 +0200 Subject: [PATCH 43/46] Fake callables will now return the fake callable's code object. Added Python 2.x aliases for doc and code internal attributes. --- .noseids | 649 ++++++++++--------- testdoubles/fakes/callables.py | 12 + tests/functional/fakes/test_fake_callable.py | 76 +++ tests/unit/fakes/test_fake_callable.py | 54 ++ 4 files changed, 494 insertions(+), 297 deletions(-) diff --git a/.noseids b/.noseids index 5f6dd14..0022833 100644 --- a/.noseids +++ b/.noseids @@ -4,530 +4,585 @@ p1 (dp2 S'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' p3 -I98 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' +I109 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0009: should not have a reference to the fake unbound version of the method if the method is unbound' p4 -I90 +I84 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0000: should have the same name as the live object' p5 -I80 +I88 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p6 -I96 +I107 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' p7 I22 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' p8 -I39 +I44 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' p9 -I37 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0008: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' +I42 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0008: should have a reference to the fake unbound version of the method if the method is bound' p10 -I78 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0009: should have the same docstring as the live callable' -p11 -I79 +I96 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0000: should have the same name as the live object' -p12 +p11 I17 sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' +p12 +I48 +sS"tests.functional.fakes.test_fake_callable.A Fake Function object.test 0009: should have an attribute named im_class that is equal to the __self__ attribute's type" p13 -I43 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0009: should have the same docstring as the live callable' +I26 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0006: should raise an attribute error when attempting to use the func_code internal attribute' p14 -I89 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' +I81 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0016: should have the same code object as the fake callable' p15 -I42 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' +I33 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' p16 -I48 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' +I47 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' p17 -I83 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' +I53 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' p18 -I92 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0007: should not have a reference to the fake unbound version of the method if the method is unbound' +I91 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0011: should have the same docstring as the live callable' p19 -I77 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' +I99 +sS"tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0007: should have an attribute named im_class that is equal to the __self__ attribute's type" p20 -I3 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" +I95 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0008: should have an attribute named im_self that is equal to the __self__ attribute' p21 -I61 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' +I25 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' p22 -I94 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' +I3 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" p23 -I57 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" +I66 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' p24 -I63 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' +I105 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' p25 -I104 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0006: should have a reference to the fake unbound version of the method if the method is bound' +I62 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" p26 -I76 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0008: should have a reference to the fake unbound version of the method if the method is bound' +I68 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' p27 -I25 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' +I115 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0012: should have a reference to the fake unbound version of the method if the method is bound' p28 -I105 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' +I29 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' p29 -I31 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' +I116 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' p30 +I36 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' +p31 I1 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0006: should have an attribute named func_doc that is equal to the __doc__ attribute' +p32 +I94 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0010: should have an attribute named func_code that is equal to the __code__ attribute' +p33 +I27 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' +p34 +I101 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0009: should not have a reference to the fake unbound version of the method if the method is unbound' +p35 +I97 sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' -p31 -I44 +p36 +I49 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' -p32 -I103 +p37 +I114 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." -p33 +p38 I16 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' -p34 -I45 +p39 +I50 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0011: should have the same docstring as the live callable' +p40 +I86 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" -p35 +p41 I8 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0008: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' -p36 -I88 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" -p37 +p42 I9 sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' -p38 -I69 +p43 +I74 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0002: should have a reference to the instance if the method is bound' -p39 -I72 +p44 +I77 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0013: should not have a reference to the fake unbound version of the method if the method is unbound' +p45 +I30 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' -p40 -I93 +p46 +I104 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" -p41 -I97 +p47 +I108 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0010: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' +p48 +I98 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" -p42 -I64 +p49 +I69 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' -p43 -I58 +p50 +I63 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0000: should have the same name as the live object' -p44 -I70 +p51 +I75 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p45 -I53 +p52 +I58 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0005: should have an attribute named func_code that is equal to the __code__ attribute' +p53 +I93 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0001: should have the same name as the live object when the live object is a callable class instance' -p46 +p54 I18 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' -p47 -I56 +p55 +I61 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' -p48 -I95 +p56 +I106 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p49 -I46 +p57 +I51 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' -p50 -I32 +p58 +I37 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' -p51 -I41 +p59 +I46 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' -p52 -I101 +p60 +I112 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" -p53 +p61 I13 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0004: should raise an attribute error when attempting to use the im_self alias' -p54 +p62 I21 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' -p55 -I75 +p63 +I80 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' -p56 -I29 +p64 +I34 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" -p57 -I68 +p65 +I73 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" -p58 +p66 I10 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' -p59 -I35 +p67 +I40 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0014: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' +p68 +I31 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0002: should have a reference to the instance if the method is bound' -p60 -I82 +p69 +I90 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' -p61 -I34 +p70 +I39 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' -p62 -I54 +p71 +I59 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0008: should have a reference to the fake unbound version of the method if the method is bound' +p72 +I83 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' -p63 -I81 +p73 +I89 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p64 -I49 +p74 +I54 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' -p65 -I47 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0006: should have a reference to the fake unbound version of the method if the method is bound' -p66 -I86 -sS"tests.functional.fakes.test_fake_callable.A Fake Function object.test 0007: should have an attribute named im_class that is equal to the __self__ attribute's type" -p67 -I24 +p75 +I52 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' -p68 -I71 +p76 +I76 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0007: should raise an attribute error when attempting to use the func_doc internal attribute' +p77 +I82 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' -p69 -I99 +p78 +I110 sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' -p70 +p79 I5 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' -p71 -I40 +p80 +I45 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' -p72 -I52 +p81 +I57 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0012: should have the same code object as the fake callable' +p82 +I100 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" -p73 +p83 I14 -sS"tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0005: should have an attribute named im_class that is equal to the __self__ attribute's type" -p74 -I85 sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p75 +p84 I7 sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p76 +p85 I4 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a value error when the provided live object matches the argspec" -p77 -I65 +p86 +I70 sS'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' -p78 +p87 I6 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" -p79 +p88 I15 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' -p80 +p89 I20 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' -p81 -I36 +p90 +I41 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0010: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' +p91 +I85 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' -p82 -I55 +p92 +I60 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' -p83 -I91 +p93 +I102 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0002: should have a reference to the instance if the method is bound' -p84 +p94 I19 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0007: should raise an attribute error when attempting to use the func_doc internal attribute' +p95 +I24 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" -p85 +p96 I11 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' -p86 -I73 +p97 +I78 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0011: should have an attribute named func_doc that is equal to the __doc__ attribute' +p98 +I28 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" -p87 -I66 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' -p88 -I33 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0006: should have an attribute named im_self that is equal to the __self__ attribute' -p89 +p99 +I71 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0006: should raise an attribute error when attempting to use the func_code internal attribute' +p100 I23 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0011: should have the same docstring as the live callable' -p90 -I28 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' +p101 +I38 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' -p91 -I50 +p102 +I55 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" -p92 -I62 +p103 +I67 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' -p93 -I100 +p104 +I111 sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' -p94 +p105 I2 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' -p95 -I102 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0010: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' -p96 -I27 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0007: should not have a reference to the fake unbound version of the method if the method is unbound' -p97 +p106 +I113 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0012: should have the same code object as the fake callable' +p107 I87 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0004: should raise an attribute error when attempting to use the im_self alias' -p98 -I74 +p108 +I79 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' +p109 +I103 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0004: should have an attribute named im_self that is equal to the __self__ attribute' -p99 -I84 +p110 +I92 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' -p100 -I60 +p111 +I65 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" -p101 -I67 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0009: should not have a reference to the fake unbound version of the method if the method is unbound' -p102 -I26 +p112 +I72 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0015: should have the same docstring as the live callable' +p113 +I32 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' -p103 -I38 +p114 +I43 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' -p104 -I30 +p115 +I35 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' -p105 -I59 +p116 +I64 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p106 -I51 +p117 +I56 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p107 +p118 I12 ssS'ids' -p108 -(dp109 +p119 +(dp120 I1 -g30 +g31 sI2 -g94 +g105 sI3 -g20 +g22 sI4 -g76 +g85 sI5 -g70 +g79 sI6 -g78 +g87 sI7 -g75 +g84 sI8 -g35 +g41 sI9 -g37 +g42 sI10 -g58 +g66 sI11 -g85 +g96 sI12 -g107 +g118 sI13 -g53 +g61 sI14 -g73 +g83 sI15 -g79 +g88 sI16 -g33 +g38 sI17 -g12 +g11 sI18 -g46 +g54 sI19 -g84 +g94 sI20 -g80 +g89 sI21 -g54 +g62 sI22 g7 sI23 -g89 +g100 sI24 -g67 +g95 sI25 -g27 +g21 sI26 -g102 +g13 sI27 -g96 +g33 sI28 -g90 +g98 sI29 -g56 +g28 sI30 -g104 +g45 sI31 -g29 +g68 sI32 -g50 +g113 sI33 -g88 +g15 sI34 -g61 +g64 sI35 -g59 +g115 sI36 -g81 +g30 sI37 -g9 +g58 sI38 -g103 +g101 sI39 -g8 +g70 sI40 -g71 +g67 sI41 -g51 +g90 sI42 -g15 +g9 sI43 -g13 +g114 sI44 -g31 +g8 sI45 -g34 +g80 sI46 -g49 +g59 sI47 -g65 -sI48 g16 +sI48 +g12 sI49 -g64 +g36 sI50 -g91 +g39 sI51 -g106 +g57 sI52 -g72 +g75 sI53 -g45 +g17 sI54 -g62 +g74 sI55 -g82 +g102 sI56 -g47 +g117 sI57 -g23 +g81 sI58 -g43 +g52 sI59 -g105 +g71 sI60 -g100 +g92 sI61 -g21 +g55 sI62 -g92 +g25 sI63 -g24 +g50 sI64 -g42 +g116 sI65 -g77 +g111 sI66 -g87 +g23 sI67 -g101 +g103 sI68 -g57 +g26 sI69 -g38 +g49 sI70 -g44 +g86 sI71 -g68 +g99 sI72 -g39 +g112 sI73 -g86 +g65 sI74 -g98 +g43 sI75 -g55 +g51 sI76 -g26 +g76 sI77 -g19 +g44 sI78 -g10 +g97 sI79 -g11 +g108 sI80 -g5 -sI81 g63 +sI81 +g14 sI82 -g60 +g77 sI83 -g17 +g72 sI84 -g99 +g4 sI85 -g74 +g91 sI86 -g66 +g40 sI87 -g97 +g107 sI88 -g36 +g5 sI89 -g14 +g73 sI90 -g4 +g69 sI91 -g83 -sI92 g18 +sI92 +g110 sI93 -g40 +g53 sI94 -g22 +g32 sI95 -g48 +g20 sI96 -g6 +g10 sI97 -g41 +g35 sI98 -g3 +g48 sI99 -g69 +g19 sI100 -g93 +g82 sI101 -g52 +g34 sI102 -g95 +g93 sI103 -g32 +g109 sI104 -g25 +g46 sI105 -g28 +g24 +sI106 +g56 +sI107 +g6 +sI108 +g47 +sI109 +g3 +sI110 +g78 +sI111 +g104 +sI112 +g60 +sI113 +g106 +sI114 +g37 +sI115 +g27 +sI116 +g29 ss. \ No newline at end of file diff --git a/testdoubles/fakes/callables.py b/testdoubles/fakes/callables.py index db3328a..4909575 100644 --- a/testdoubles/fakes/callables.py +++ b/testdoubles/fakes/callables.py @@ -32,6 +32,10 @@ def __func__(self): return self.fake.__func__ + @property + def __code__(self): + return self.fake.__code__ + def __getattribute__(self, item): if item == '__doc__': return self.live.__doc__ @@ -76,6 +80,14 @@ def im_self(self): def im_class(self): return self.__self__.__class__ + @property + def func_code(self): + return self.__code__ + + @property + def func_doc(self): + return self.__doc__ + class FakeCallable(CallableIntrospectionMixin, CallableInternalAttributesMixin): def __init__(self, live, inspect_args=False): diff --git a/tests/functional/fakes/test_fake_callable.py b/tests/functional/fakes/test_fake_callable.py index 925e629..fca380a 100644 --- a/tests/functional/fakes/test_fake_callable.py +++ b/tests/functional/fakes/test_fake_callable.py @@ -94,6 +94,38 @@ def bar(self): _ = sut.im_class + @it.should("raise an attribute error when attempting to use the func_code internal attribute") + @unittest.skipUnless(six.PY3, 'Test should only be run under Python 3.x') + def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_code_internal_attribute(case): + class Foo(object): + def bar(self): + pass + + live_unbound_method = Foo.bar + + sut = FakeCallable(live_unbound_method) + + with case.assertRaisesRegexp(AttributeError, + r"'FakeCallable' object has no attribute 'func_code'"): + + _ = sut.func_code + + @it.should("raise an attribute error when attempting to use the func_doc internal attribute") + @unittest.skipUnless(six.PY3, 'Test should only be run under Python 3.x') + def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_doc_internal_attribute(case): + class Foo(object): + def bar(self): + pass + + live_unbound_method = Foo.bar + + sut = FakeCallable(live_unbound_method) + + with case.assertRaisesRegexp(AttributeError, + r"'FakeCallable' object has no attribute 'func_doc'"): + + _ = sut.func_doc + @it.should("have an attribute named im_self that is equal to the __self__ attribute") @unittest.skipUnless(not six.PY3, 'Test should only be run under Python 2.x') def test_should_have_an_attribute_named_im_self_that_is_equal_to_the_self_attribute(case): @@ -126,6 +158,38 @@ def bar(self): case.assertEqual(actual, expected) + @it.should("have an attribute named func_code that is equal to the __code__ attribute") + @unittest.skipUnless(not six.PY3, 'Test should only be run under Python 2.x') + def test_should_have_an_attribute_named_func_code_that_is_equal_to_the_code_attribute(case): + class Foo(object): + def bar(self): + pass + + live_bound_method = Foo().bar + + sut = FakeCallable(live_bound_method) + expected = sut.__code__ + + actual = sut.func_code + + case.assertEqual(actual, expected) + + @it.should("have an attribute named func_doc that is equal to the __doc__ attribute") + @unittest.skipUnless(not six.PY3, 'Test should only be run under Python 2.x') + def test_should_have_an_attribute_named_func_doc_that_is_equal_to_the_doc_attribute(case): + class Foo(object): + def bar(self): + pass + + live_bound_method = Foo().bar + + sut = FakeCallable(live_bound_method) + expected = sut.__doc__ + + actual = sut.func_doc + + case.assertEqual(actual, expected) + @it.should("have a reference to the fake unbound version of the method if the method is bound") def test_should_have_a_reference_to_the_fake_unbound_version_of_the_method_if_the_method_is_bound(case): class Foo(object): @@ -181,6 +245,18 @@ def foo(): case.assertEqual(actual, expected) + @it.should("have the same code object as the fake callable") + def test_should_have_the_same_docstring_as_the_live_callable(case): + def foo(): + pass + + sut = FakeCallable(foo) + expected = sut.fake.__code__ + + actual = sut.__code__ + + case.assertEqual(actual, expected) + it.createTests(globals()) with such.A("Fake Function's initialization method") as it: diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 6d90d8d..d0644f1 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -98,6 +98,22 @@ def test_should_raise_an_attribute_error_when_attempting_to_use_the_im_class_int _ = sut.im_class + @it.should("raise an attribute error when attempting to use the func_code internal attribute") + def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_code_internal_attribute(case): + with case.assertRaisesRegexp(AttributeError, + r"'FakeCallable' object has no attribute 'func_code'"): + sut = callables.FakeCallable(mock.DEFAULT) + + _ = sut.func_code + + @it.should("raise an attribute error when attempting to use the func_doc internal attribute") + def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_doc_internal_attribute(case): + with case.assertRaisesRegexp(AttributeError, + r"'FakeCallable' object has no attribute 'func_doc'"): + sut = callables.FakeCallable(mock.DEFAULT) + + _ = sut.func_doc + @it.should("have a reference to the fake unbound version of the method if the method is bound") def test_should_have_a_reference_to_the_fake_unbound_version_of_the_method_if_the_method_is_bound(case): live_callable, _ = fake_live_bound_callable() @@ -138,6 +154,15 @@ def test_should_have_the_same_docstring_as_the_live_callable(case): case.assertEqual(actual, expected) + @it.should("have the same code object as the fake callable") + def test_should_have_the_same_docstring_as_the_live_callable(case): + sut = callables.FakeCallable(mock.DEFAULT) + expected = sut.fake.__code__ + + actual = sut.__code__ + + case.assertEqual(actual, expected) + with it.having('a python 2.x runtime2'): @it.has_test_setup def setup(case): @@ -201,6 +226,26 @@ def test_should_have_an_attribute_named_im_self_that_is_equal_to_the_self_attrib case.assertEqual(actual, expected) + @it.should("have an attribute named func_code that is equal to the __code__ attribute") + def test_should_have_an_attribute_named_func_code_that_is_equal_to_the_code_attribute(case): + + sut = callables.FakeCallable(mock.DEFAULT) + expected = sut.__code__ + + actual = sut.func_code + + case.assertEqual(actual, expected) + + @it.should("have an attribute named func_doc that is equal to the __doc__ attribute") + def test_should_have_an_attribute_named_func_doc_that_is_equal_to_the_doc_attribute(case): + + sut = callables.FakeCallable(mock.DEFAULT) + expected = sut.__doc__ + + actual = sut.func_doc + + case.assertEqual(actual, expected) + @it.should("have an attribute named im_class that is equal to the __self__ attribute's type") def test_should_have_an_attribute_named_im_self_that_is_equal_to_the_self_attribute_type(case): live_callable, _ = fake_live_bound_callable() @@ -252,6 +297,15 @@ def test_should_have_the_same_docstring_as_the_live_callable(case): case.assertEqual(actual, expected) + @it.should("have the same code object as the fake callable") + def test_should_have_the_same_docstring_as_the_live_callable(case): + sut = callables.FakeCallable(mock.DEFAULT) + expected = sut.fake.__code__ + + actual = sut.__code__ + + case.assertEqual(actual, expected) + it.createTests(globals()) with such.A("Fake Function's initialization method") as it: From 68e2db6c08c42ae1a1f673b47585cc4b160f2639 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Tue, 5 Nov 2013 18:21:22 +0200 Subject: [PATCH 44/46] Fake callables now have the func_name alias for Python 2.x. --- .noseids | 668 ++++++++++--------- testdoubles/fakes/callables.py | 4 + tests/functional/fakes/test_fake_callable.py | 32 + tests/unit/fakes/support/fakes.py | 1 + tests/unit/fakes/test_fake_callable.py | 19 + 5 files changed, 400 insertions(+), 324 deletions(-) diff --git a/.noseids b/.noseids index 0022833..5a22883 100644 --- a/.noseids +++ b/.noseids @@ -2,120 +2,120 @@ S'tests' p1 (dp2 -S'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' +S'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0012: should have the same docstring as the live callable' p3 -I109 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0009: should not have a reference to the fake unbound version of the method if the method is unbound' +I89 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' p4 -I84 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0000: should have the same name as the live object' +I113 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0010: should not have a reference to the fake unbound version of the method if the method is unbound' p5 -I88 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" +I101 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' p6 -I107 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' +I105 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0011: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' p7 -I22 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' +I88 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0000: should have the same name as the live object' p8 -I44 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' +I91 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p9 -I42 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0008: should have a reference to the fake unbound version of the method if the method is bound' +I111 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' p10 -I96 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0000: should have the same name as the live object' +I22 +sS"tests.functional.fakes.test_fake_callable.A Fake Function object.test 0010: should have an attribute named im_class that is equal to the __self__ attribute's type" p11 -I17 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' +I27 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' p12 -I48 -sS"tests.functional.fakes.test_fake_callable.A Fake Function object.test 0009: should have an attribute named im_class that is equal to the __self__ attribute's type" +I46 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' p13 -I26 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0006: should raise an attribute error when attempting to use the func_code internal attribute' +I44 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0000: should have the same name as the live object' p14 -I81 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0016: should have the same code object as the fake callable' +I17 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' p15 -I33 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' +I50 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0006: should raise an attribute error when attempting to use the func_code internal attribute' p16 -I47 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' +I83 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' p17 -I53 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' +I49 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' p18 -I91 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0011: should have the same docstring as the live callable' +I55 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' p19 -I99 -sS"tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0007: should have an attribute named im_class that is equal to the __self__ attribute's type" +I94 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' p20 -I95 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0008: should have an attribute named im_self that is equal to the __self__ attribute' +I107 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0016: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' p21 +I33 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0008: should raise an attribute error when attempting to use the func_name internal attribute' +p22 I25 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0011: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' +p23 +I102 sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' -p22 +p24 I3 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" -p23 -I66 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p24 -I105 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' p25 -I62 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" -p26 I68 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' +p26 +I109 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' p27 -I115 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0012: should have a reference to the fake unbound version of the method if the method is bound' +I64 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" p28 -I29 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' +I70 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' p29 -I116 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' +I119 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0008: should raise an attribute error when attempting to use the func_name internal attribute' p30 -I36 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' +I85 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0015: should not have a reference to the fake unbound version of the method if the method is unbound' p31 -I1 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0006: should have an attribute named func_doc that is equal to the __doc__ attribute' +I32 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' p32 -I94 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0010: should have an attribute named func_code that is equal to the __code__ attribute' +I120 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' p33 -I27 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' +I38 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' p34 -I101 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0009: should not have a reference to the fake unbound version of the method if the method is unbound' +I1 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0006: should have an attribute named func_doc that is equal to the __doc__ attribute' p35 I97 sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' p36 -I49 +I51 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' p37 -I114 +I118 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." p38 I16 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p39 -I50 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0011: should have the same docstring as the live callable' +I75 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' p40 -I86 +I52 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" p41 I8 @@ -124,465 +124,485 @@ p42 I9 sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' p43 -I74 +I76 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0002: should have a reference to the instance if the method is bound' p44 -I77 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0013: should not have a reference to the fake unbound version of the method if the method is unbound' -p45 -I30 +I79 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' -p46 -I104 +p45 +I108 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" +p46 +I112 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0013: should have the same code object as the fake callable' p47 -I108 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0010: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' -p48 -I98 +I104 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" -p49 -I69 +p48 +I71 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' -p50 -I63 +p49 +I65 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0000: should have the same name as the live object' -p51 -I75 +p50 +I77 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' -p52 -I58 +p51 +I60 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0005: should have an attribute named func_code that is equal to the __code__ attribute' -p53 -I93 +p52 +I96 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0001: should have the same name as the live object when the live object is a callable class instance' -p54 +p53 I18 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' -p55 -I61 +p54 +I63 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' -p56 -I106 +p55 +I110 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' -p57 -I51 +p56 +I53 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' -p58 -I37 +p57 +I39 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' +p58 +I48 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0010: should not have a reference to the fake unbound version of the method if the method is unbound' p59 -I46 +I87 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p60 -I112 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" +I116 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0013: should have the same code object as the fake callable' p61 +I90 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0012: should have an attribute named func_doc that is equal to the __doc__ attribute' +p62 +I29 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" +p63 I13 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0004: should raise an attribute error when attempting to use the im_self alias' -p62 +p64 I21 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' -p63 -I80 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' -p64 -I34 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p65 -I73 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" +I82 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0009: should have a reference to the fake unbound version of the method if the method is bound' p66 -I10 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' +I86 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' p67 -I40 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0014: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' +I36 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0017: should have the same docstring as the live callable' p68 -I31 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0002: should have a reference to the instance if the method is bound' +I34 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" p69 -I90 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' +I10 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' p70 -I39 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' +I42 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0002: should have a reference to the instance if the method is bound' p71 -I59 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0008: should have a reference to the fake unbound version of the method if the method is bound' +I93 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' p72 -I83 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' +I41 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' p73 -I89 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' +I61 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' p74 -I54 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' +I92 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' p75 -I52 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' +I56 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0009: should have a reference to the fake unbound version of the method if the method is bound' p76 -I76 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0007: should raise an attribute error when attempting to use the func_doc internal attribute' +I100 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' p77 -I82 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' +I54 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0009: should have an attribute named im_self that is equal to the __self__ attribute' p78 -I110 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' +I26 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' p79 -I5 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' +I78 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0007: should raise an attribute error when attempting to use the func_doc internal attribute' p80 -I45 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' +I84 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' p81 -I57 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0012: should have the same code object as the fake callable' +I114 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' p82 -I100 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +I5 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' p83 +I47 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' +p84 +I59 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +p85 I14 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0014: should have a reference to the fake unbound version of the method if the method is bound' +p86 +I31 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' +p87 +I106 sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' -p84 +p88 I7 sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' -p85 +p89 I4 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0011: should have an attribute named func_code that is equal to the __code__ attribute' +p90 +I28 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0008: should have an attribute named func_name that is equal to the __name__ attribute' +p91 +I99 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a value error when the provided live object matches the argspec" -p86 -I70 +p92 +I72 sS'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' -p87 +p93 I6 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" -p88 +p94 I15 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' -p89 +p95 I20 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' -p90 -I41 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0010: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' -p91 -I85 +p96 +I43 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' -p92 -I60 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' -p93 -I102 +p97 +I62 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0018: should have the same code object as the fake callable' +p98 +I35 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0002: should have a reference to the instance if the method is bound' -p94 +p99 I19 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0007: should raise an attribute error when attempting to use the func_doc internal attribute' -p95 +p100 I24 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" -p96 +p101 I11 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' -p97 -I78 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0011: should have an attribute named func_doc that is equal to the __doc__ attribute' -p98 -I28 +p102 +I80 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0012: should have the same docstring as the live callable' +p103 +I103 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" -p99 -I71 +p104 +I73 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0006: should raise an attribute error when attempting to use the func_code internal attribute' -p100 +p105 I23 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' -p101 -I38 +p106 +I40 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' -p102 -I55 +p107 +I57 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" -p103 -I67 +p108 +I69 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' -p104 -I111 +p109 +I115 sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' -p105 +p110 I2 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' -p106 -I113 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0012: should have the same code object as the fake callable' -p107 -I87 +p111 +I117 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0004: should raise an attribute error when attempting to use the im_self alias' -p108 -I79 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' -p109 -I103 +p112 +I81 +sS"tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0007: should have an attribute named im_class that is equal to the __self__ attribute's type" +p113 +I98 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0004: should have an attribute named im_self that is equal to the __self__ attribute' -p110 -I92 +p114 +I95 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' -p111 -I65 +p115 +I67 sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" -p112 -I72 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0015: should have the same docstring as the live callable' -p113 -I32 +p116 +I74 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0013: should have an attribute named func_name that is equal to the __name__ attribute' +p117 +I30 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' -p114 -I43 +p118 +I45 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' -p115 -I35 +p119 +I37 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' -p116 -I64 +p120 +I66 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p117 -I56 +p121 +I58 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p118 +p122 I12 ssS'ids' -p119 -(dp120 +p123 +(dp124 I1 -g31 +g34 sI2 -g105 +g110 sI3 -g22 +g24 sI4 -g85 +g89 sI5 -g79 +g82 sI6 -g87 +g93 sI7 -g84 +g88 sI8 g41 sI9 g42 sI10 -g66 +g69 sI11 -g96 +g101 sI12 -g118 +g122 sI13 -g61 +g63 sI14 -g83 +g85 sI15 -g88 +g94 sI16 g38 sI17 -g11 +g14 sI18 -g54 +g53 sI19 -g94 +g99 sI20 -g89 +g95 sI21 -g62 +g64 sI22 -g7 +g10 sI23 -g100 +g105 sI24 -g95 +g100 sI25 -g21 +g22 sI26 -g13 +g78 sI27 -g33 +g11 sI28 -g98 +g90 sI29 -g28 +g62 sI30 -g45 +g117 sI31 -g68 +g86 sI32 -g113 +g31 sI33 -g15 +g21 sI34 -g64 +g68 sI35 -g115 +g98 sI36 -g30 +g67 sI37 -g58 +g119 sI38 -g101 +g33 sI39 -g70 +g57 sI40 -g67 +g106 sI41 -g90 +g72 sI42 -g9 +g70 sI43 -g114 +g96 sI44 -g8 +g13 sI45 -g80 +g118 sI46 -g59 +g12 sI47 -g16 +g83 sI48 -g12 +g58 sI49 -g36 +g17 sI50 -g39 +g15 sI51 -g57 +g36 sI52 -g75 +g40 sI53 -g17 +g56 sI54 -g74 +g77 sI55 -g102 +g18 sI56 -g117 +g75 sI57 -g81 +g107 sI58 -g52 +g121 sI59 -g71 +g84 sI60 -g92 +g51 sI61 -g55 +g73 sI62 -g25 +g97 sI63 -g50 +g54 sI64 -g116 +g27 sI65 -g111 +g49 sI66 -g23 +g120 sI67 -g103 +g115 sI68 -g26 +g25 sI69 -g49 +g108 sI70 -g86 +g28 sI71 -g99 +g48 sI72 -g112 +g92 sI73 -g65 +g104 sI74 -g43 +g116 sI75 -g51 +g39 sI76 -g76 +g43 sI77 -g44 +g50 sI78 -g97 +g79 sI79 -g108 +g44 sI80 -g63 +g102 sI81 -g14 +g112 sI82 -g77 +g65 sI83 -g72 +g16 sI84 -g4 +g80 sI85 -g91 +g30 sI86 -g40 +g66 sI87 -g107 +g59 sI88 -g5 +g7 sI89 -g73 +g3 sI90 -g69 +g61 sI91 -g18 +g8 sI92 -g110 +g74 sI93 -g53 +g71 sI94 -g32 +g19 sI95 -g20 +g114 sI96 -g10 +g52 sI97 g35 sI98 -g48 +g113 sI99 -g19 +g91 sI100 -g82 +g76 sI101 -g34 +g5 sI102 -g93 +g23 sI103 -g109 +g103 sI104 -g46 +g47 sI105 -g24 +g6 sI106 -g56 +g87 sI107 -g6 +g20 sI108 -g47 +g45 sI109 -g3 +g26 sI110 -g78 +g55 sI111 -g104 +g9 sI112 -g60 +g46 sI113 -g106 +g4 sI114 -g37 +g81 sI115 -g27 +g109 sI116 +g60 +sI117 +g111 +sI118 +g37 +sI119 g29 +sI120 +g32 ss. \ No newline at end of file diff --git a/testdoubles/fakes/callables.py b/testdoubles/fakes/callables.py index 4909575..61c46a6 100644 --- a/testdoubles/fakes/callables.py +++ b/testdoubles/fakes/callables.py @@ -88,6 +88,10 @@ def func_code(self): def func_doc(self): return self.__doc__ + @property + def func_name(self): + return self.live.__name__ + class FakeCallable(CallableIntrospectionMixin, CallableInternalAttributesMixin): def __init__(self, live, inspect_args=False): diff --git a/tests/functional/fakes/test_fake_callable.py b/tests/functional/fakes/test_fake_callable.py index fca380a..81cdeb4 100644 --- a/tests/functional/fakes/test_fake_callable.py +++ b/tests/functional/fakes/test_fake_callable.py @@ -125,6 +125,22 @@ def bar(self): r"'FakeCallable' object has no attribute 'func_doc'"): _ = sut.func_doc + + @it.should("raise an attribute error when attempting to use the func_name internal attribute") + @unittest.skipUnless(six.PY3, 'Test should only be run under Python 3.x') + def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_name_internal_attribute(case): + class Foo(object): + def bar(self): + pass + + live_unbound_method = Foo.bar + + sut = FakeCallable(live_unbound_method) + + with case.assertRaisesRegexp(AttributeError, + r"'FakeCallable' object has no attribute 'func_name'"): + + _ = sut.func_name @it.should("have an attribute named im_self that is equal to the __self__ attribute") @unittest.skipUnless(not six.PY3, 'Test should only be run under Python 2.x') @@ -189,6 +205,22 @@ def bar(self): actual = sut.func_doc case.assertEqual(actual, expected) + + @it.should("have an attribute named func_name that is equal to the __name__ attribute") + @unittest.skipUnless(not six.PY3, 'Test should only be run under Python 2.x') + def test_should_have_an_attribute_named_func_name_that_is_equal_to_the_name_attribute(case): + class Foo(object): + def bar(self): + pass + + live_bound_method = Foo().bar + + sut = FakeCallable(live_bound_method) + expected = sut.__name__ + + actual = sut.func_name + + case.assertEqual(actual, expected) @it.should("have a reference to the fake unbound version of the method if the method is bound") def test_should_have_a_reference_to_the_fake_unbound_version_of_the_method_if_the_method_is_bound(case): diff --git a/tests/unit/fakes/support/fakes.py b/tests/unit/fakes/support/fakes.py index 7ba914d..f426c27 100644 --- a/tests/unit/fakes/support/fakes.py +++ b/tests/unit/fakes/support/fakes.py @@ -7,6 +7,7 @@ def fake_live_bound_callable(): mocked_callable = mock.MagicMock() self = mock.PropertyMock() type(mocked_callable).__self__ = self + mocked_callable.__name__ = 'fake_live_bound_callable' return mocked_callable, self diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index d0644f1..7704b29 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -113,6 +113,14 @@ def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_doc_int sut = callables.FakeCallable(mock.DEFAULT) _ = sut.func_doc + + @it.should("raise an attribute error when attempting to use the func_name internal attribute") + def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_name_internal_attribute(case): + with case.assertRaisesRegexp(AttributeError, + r"'FakeCallable' object has no attribute 'func_name'"): + sut = callables.FakeCallable(mock.DEFAULT) + + _ = sut.func_name @it.should("have a reference to the fake unbound version of the method if the method is bound") def test_should_have_a_reference_to_the_fake_unbound_version_of_the_method_if_the_method_is_bound(case): @@ -257,6 +265,17 @@ def test_should_have_an_attribute_named_im_self_that_is_equal_to_the_self_attrib case.assertEqual(actual, expected) + @it.should("have an attribute named func_name that is equal to the __name__ attribute") + def test_should_have_an_attribute_named_func_name_that_is_equal_to_the_name_attribute(case): + live_callable, _ = fake_live_bound_callable() + expected = live_callable.__name__ + + sut = callables.FakeCallable(live_callable) + + actual = sut.func_name + + case.assertEqual(actual, expected) + @it.should("have a reference to the fake unbound version of the method if the method is bound") def test_should_have_a_reference_to_the_fake_unbound_version_of_the_method_if_the_method_is_bound(case): live_callable, _ = fake_live_bound_callable() From 04d06c642b4fea9ac94c9619b4627521103e5f70 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Tue, 5 Nov 2013 18:32:59 +0200 Subject: [PATCH 45/46] Fake callables will now return the fake callable's default keyword arguments values. Added Python 2.x aliases for the defaults internal attributes. --- .noseids | 706 ++++++++++--------- testdoubles/fakes/callables.py | 8 + tests/functional/fakes/test_fake_callable.py | 44 ++ tests/unit/fakes/support/fakes.py | 4 +- tests/unit/fakes/test_fake_callable.py | 28 + 5 files changed, 451 insertions(+), 339 deletions(-) diff --git a/.noseids b/.noseids index 5a22883..9a8cb8a 100644 --- a/.noseids +++ b/.noseids @@ -2,607 +2,637 @@ S'tests' p1 (dp2 -S'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0012: should have the same docstring as the live callable' +S'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0013: should have the same docstring as the live callable' p3 -I89 +I109 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' p4 -I113 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0010: should not have a reference to the fake unbound version of the method if the method is unbound' +I119 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0012: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' p5 -I101 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' -p6 -I105 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0011: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' -p7 -I88 +I92 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0000: should have the same name as the live object' -p8 -I91 +p6 +I96 sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" -p9 -I111 +p7 +I117 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' -p10 +p8 I22 -sS"tests.functional.fakes.test_fake_callable.A Fake Function object.test 0010: should have an attribute named im_class that is equal to the __self__ attribute's type" -p11 -I27 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' -p12 -I46 +p9 +I49 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' -p13 -I44 +p10 +I47 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0000: should have the same name as the live object' -p14 +p11 I17 sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' -p15 -I50 +p12 +I53 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0014: should have the same code object as the fake callable' +p13 +I94 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0012: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' +p14 +I108 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0006: should raise an attribute error when attempting to use the func_code internal attribute' -p16 -I83 +p15 +I86 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' -p17 -I49 +p16 +I52 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' -p18 -I55 +p17 +I58 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' -p19 -I94 +p18 +I99 sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' +p19 +I113 +sS"tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0007: should have an attribute named im_class that is equal to the __self__ attribute's type" p20 -I107 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0016: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' +I103 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0010: should have a reference to the fake unbound version of the method if the method is bound' p21 -I33 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0008: should raise an attribute error when attempting to use the func_name internal attribute' -p22 -I25 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0011: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' -p23 -I102 +I106 sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' -p24 +p22 I3 sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" -p25 -I68 +p23 +I71 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' -p26 -I109 +p24 +I115 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0008: should raise an attribute error when attempting to use the func_defaults internal attribute' +p25 +I25 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' -p27 -I64 +p26 +I67 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" -p28 -I70 +p27 +I73 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' -p29 -I119 +p28 +I125 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0008: should raise an attribute error when attempting to use the func_name internal attribute' -p30 -I85 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0015: should not have a reference to the fake unbound version of the method if the method is unbound' -p31 -I32 +p29 +I88 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' -p32 -I120 +p30 +I126 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' -p33 -I38 +p31 +I41 sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' -p34 +p32 I1 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0006: should have an attribute named func_doc that is equal to the __doc__ attribute' +p33 +I102 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' +p34 +I111 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0010: should have a reference to the fake unbound version of the method if the method is bound' p35 -I97 +I90 sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' p36 -I51 +I54 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' p37 -I118 +I124 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." p38 I16 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" -p39 -I75 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' -p40 -I52 +p39 +I55 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" -p41 +p40 I8 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0013: should have the same docstring as the live callable' +p41 +I93 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" p42 I9 sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' p43 -I76 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0002: should have a reference to the instance if the method is bound' -p44 I79 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0011: should not have a reference to the fake unbound version of the method if the method is unbound' +p44 +I107 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0002: should have a reference to the instance if the method is bound' p45 -I108 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" +I82 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0019: should have the same docstring as the live callable' p46 -I112 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0013: should have the same code object as the fake callable' +I36 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' p47 -I104 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" +I114 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" p48 -I71 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' +I118 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" p49 -I65 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0000: should have the same name as the live object' +I74 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' p50 -I77 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' +I68 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0000: should have the same name as the live object' p51 -I60 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0005: should have an attribute named func_code that is equal to the __code__ attribute' +I80 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' p52 -I96 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0001: should have the same name as the live object when the live object is a callable class instance' +I63 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0005: should have an attribute named func_code that is equal to the __code__ attribute' p53 +I101 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0001: should have the same name as the live object when the live object is a callable class instance' +p54 I18 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' -p54 -I63 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' p55 -I110 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' +I66 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0013: should have an attribute named func_doc that is equal to the __doc__ attribute' p56 -I53 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' +I30 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' p57 -I39 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' +I56 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' p58 -I48 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0010: should not have a reference to the fake unbound version of the method if the method is unbound' +I42 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' p59 -I87 +I51 sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p60 -I116 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0013: should have the same code object as the fake callable' -p61 -I90 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0012: should have an attribute named func_doc that is equal to the __doc__ attribute' -p62 -I29 +I122 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" -p63 +p61 I13 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0015: should have the same default values for keyword arguments as the fake callable' +p62 +I95 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0004: should raise an attribute error when attempting to use the im_self alias' -p64 +p63 I21 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0018: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' +p64 +I35 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' p65 -I82 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0009: should have a reference to the fake unbound version of the method if the method is bound' -p66 -I86 +I85 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' +p66 +I39 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p67 -I36 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0017: should have the same docstring as the live callable' -p68 -I34 +I78 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" -p69 +p68 I10 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' +p69 +I45 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0009: should have an attribute named func_defaults that is equal to the __defaults__ attribute' p70 -I42 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0002: should have a reference to the instance if the method is bound' +I105 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0020: should have the same code object as the fake callable' p71 -I93 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' +I37 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0021: should have the same default values for keyword arguments as the fake callable' p72 -I41 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' +I38 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0002: should have a reference to the instance if the method is bound' p73 -I61 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' +I98 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' p74 -I92 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' +I44 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' p75 -I56 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0009: should have a reference to the fake unbound version of the method if the method is bound' +I64 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' p76 -I100 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' +I97 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' p77 -I54 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0009: should have an attribute named im_self that is equal to the __self__ attribute' +I59 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0010: should have an attribute named im_self that is equal to the __self__ attribute' p78 -I26 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' +I27 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' p79 -I78 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0007: should raise an attribute error when attempting to use the func_doc internal attribute' +I57 +sS"tests.functional.fakes.test_fake_callable.A Fake Function object.test 0011: should have an attribute named im_class that is equal to the __self__ attribute's type" p80 -I84 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' +I28 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' p81 -I114 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' +I81 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0007: should raise an attribute error when attempting to use the func_doc internal attribute' p82 -I5 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' +I87 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' p83 -I47 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' +I120 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' p84 -I59 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +I5 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' p85 -I14 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0014: should have a reference to the fake unbound version of the method if the method is bound' +I50 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' p86 -I31 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' +I62 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" p87 -I106 +I14 sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' p88 I7 sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' p89 I4 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0011: should have an attribute named func_code that is equal to the __code__ attribute' -p90 -I28 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0008: should have an attribute named func_name that is equal to the __name__ attribute' -p91 -I99 +p90 +I104 sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a value error when the provided live object matches the argspec" -p92 -I72 +p91 +I75 sS'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' -p93 +p92 I6 sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" -p94 +p93 I15 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0012: should have an attribute named func_code that is equal to the __code__ attribute' +p94 +I29 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' p95 +I116 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' +p96 I20 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' -p96 -I43 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' p97 -I62 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0018: should have the same code object as the fake callable' +I46 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' p98 -I35 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0002: should have a reference to the instance if the method is bound' +I65 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' p99 +I112 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0002: should have a reference to the instance if the method is bound' +p100 I19 sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0007: should raise an attribute error when attempting to use the func_doc internal attribute' -p100 +p101 I24 sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" -p101 +p102 I11 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' -p102 -I80 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0012: should have the same docstring as the live callable' p103 -I103 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" +I83 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0015: should have an attribute named func_name that is equal to the __name__ attribute' p104 -I73 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0006: should raise an attribute error when attempting to use the func_code internal attribute' +I32 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0014: should have the same code object as the fake callable' p105 -I23 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' +I110 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" p106 -I40 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' +I76 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0006: should raise an attribute error when attempting to use the func_code internal attribute' p107 -I57 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" +I23 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' p108 -I69 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' +I43 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0017: should not have a reference to the fake unbound version of the method if the method is unbound' p109 -I115 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' +I34 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' p110 -I2 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' +I60 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" p111 -I117 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0004: should raise an attribute error when attempting to use the im_self alias' +I72 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' p112 -I81 -sS"tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0007: should have an attribute named im_class that is equal to the __self__ attribute's type" +I121 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' p113 -I98 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0004: should have an attribute named im_self that is equal to the __self__ attribute' +I2 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' p114 -I95 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' +I123 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0009: should raise an attribute error when attempting to use the func_defaults internal attribute' p115 -I67 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" +I89 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0014: should have an attribute named func_defaults that is equal to the __defaults__ attribute' p116 -I74 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0013: should have an attribute named func_name that is equal to the __name__ attribute' +I31 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0004: should raise an attribute error when attempting to use the im_self alias' p117 -I30 +I84 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0004: should have an attribute named im_self that is equal to the __self__ attribute' +p118 +I100 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' +p119 +I70 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" +p120 +I77 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" +p121 +I12 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0011: should not have a reference to the fake unbound version of the method if the method is unbound' +p122 +I91 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0009: should raise an attribute error when attempting to use the func_name internal attribute' +p123 +I26 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' -p118 -I45 +p124 +I48 sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' -p119 -I37 +p125 +I40 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' -p120 -I66 +p126 +I69 sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' -p121 -I58 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" -p122 -I12 +p127 +I61 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0016: should have a reference to the fake unbound version of the method if the method is bound' +p128 +I33 ssS'ids' -p123 -(dp124 +p129 +(dp130 I1 -g34 +g32 sI2 -g110 +g113 sI3 -g24 +g22 sI4 g89 sI5 -g82 +g84 sI6 -g93 +g92 sI7 g88 sI8 -g41 +g40 sI9 g42 sI10 -g69 +g68 sI11 -g101 +g102 sI12 -g122 +g121 sI13 -g63 +g61 sI14 -g85 +g87 sI15 -g94 +g93 sI16 g38 sI17 -g14 +g11 sI18 -g53 +g54 sI19 -g99 +g100 sI20 -g95 +g96 sI21 -g64 +g63 sI22 -g10 +g8 sI23 -g105 +g107 sI24 -g100 +g101 sI25 -g22 +g25 sI26 -g78 +g123 sI27 -g11 +g78 sI28 -g90 +g80 sI29 -g62 +g94 sI30 -g117 +g56 sI31 -g86 +g116 sI32 -g31 +g104 sI33 -g21 +g128 sI34 -g68 +g109 sI35 -g98 +g64 sI36 -g67 +g46 sI37 -g119 +g71 sI38 -g33 +g72 sI39 -g57 +g66 sI40 -g106 +g125 sI41 -g72 +g31 sI42 -g70 +g58 sI43 -g96 +g108 sI44 -g13 +g74 sI45 -g118 +g69 sI46 -g12 +g97 sI47 -g83 +g10 sI48 -g58 +g124 sI49 -g17 +g9 sI50 -g15 +g85 sI51 -g36 +g59 sI52 -g40 +g16 sI53 -g56 +g12 sI54 -g77 +g36 sI55 -g18 +g39 sI56 -g75 +g57 sI57 -g107 +g79 sI58 -g121 +g17 sI59 -g84 +g77 sI60 -g51 +g110 sI61 -g73 +g127 sI62 -g97 +g86 sI63 -g54 +g52 sI64 -g27 +g75 sI65 -g49 +g98 sI66 -g120 +g55 sI67 -g115 +g26 sI68 -g25 +g50 sI69 -g108 +g126 sI70 -g28 +g119 sI71 -g48 +g23 sI72 -g92 +g111 sI73 -g104 +g27 sI74 -g116 +g49 sI75 -g39 +g91 sI76 -g43 +g106 sI77 -g50 +g120 sI78 -g79 +g67 sI79 -g44 +g43 sI80 -g102 +g51 sI81 -g112 +g81 sI82 -g65 +g45 sI83 -g16 +g103 sI84 -g80 +g117 sI85 -g30 +g65 sI86 -g66 +g15 sI87 -g59 +g82 sI88 -g7 +g29 sI89 -g3 +g115 sI90 -g61 +g35 sI91 -g8 +g122 sI92 -g74 +g5 sI93 -g71 +g41 sI94 -g19 +g13 sI95 -g114 +g62 sI96 -g52 +g6 sI97 -g35 +g76 sI98 -g113 +g73 sI99 -g91 +g18 sI100 -g76 +g118 sI101 -g5 +g53 sI102 -g23 +g33 sI103 -g103 +g20 sI104 -g47 +g90 sI105 -g6 +g70 sI106 -g87 +g21 sI107 -g20 +g44 sI108 -g45 +g14 sI109 -g26 +g3 sI110 -g55 +g105 sI111 -g9 +g34 sI112 -g46 +g99 sI113 -g4 +g19 sI114 -g81 +g47 sI115 -g109 +g24 sI116 -g60 +g95 sI117 -g111 +g7 sI118 -g37 +g48 sI119 -g29 +g4 sI120 -g32 +g83 +sI121 +g112 +sI122 +g60 +sI123 +g114 +sI124 +g37 +sI125 +g28 +sI126 +g30 ss. \ No newline at end of file diff --git a/testdoubles/fakes/callables.py b/testdoubles/fakes/callables.py index 61c46a6..ae62dfe 100644 --- a/testdoubles/fakes/callables.py +++ b/testdoubles/fakes/callables.py @@ -36,6 +36,10 @@ def __func__(self): def __code__(self): return self.fake.__code__ + @property + def __defaults__(self): + return self.fake.__defaults__ + def __getattribute__(self, item): if item == '__doc__': return self.live.__doc__ @@ -92,6 +96,10 @@ def func_doc(self): def func_name(self): return self.live.__name__ + @property + def func_defaults(self): + return self.__defaults__ + class FakeCallable(CallableIntrospectionMixin, CallableInternalAttributesMixin): def __init__(self, live, inspect_args=False): diff --git a/tests/functional/fakes/test_fake_callable.py b/tests/functional/fakes/test_fake_callable.py index 81cdeb4..caaa84f 100644 --- a/tests/functional/fakes/test_fake_callable.py +++ b/tests/functional/fakes/test_fake_callable.py @@ -126,6 +126,22 @@ def bar(self): _ = sut.func_doc + @it.should("raise an attribute error when attempting to use the func_defaults internal attribute") + @unittest.skipUnless(six.PY3, 'Test should only be run under Python 3.x') + def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_defaults_internal_attribute(case): + class Foo(object): + def bar(self): + pass + + live_unbound_method = Foo.bar + + sut = FakeCallable(live_unbound_method) + + with case.assertRaisesRegexp(AttributeError, + r"'FakeCallable' object has no attribute 'func_defaults'"): + + _ = sut.func_defaults + @it.should("raise an attribute error when attempting to use the func_name internal attribute") @unittest.skipUnless(six.PY3, 'Test should only be run under Python 3.x') def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_name_internal_attribute(case): @@ -206,6 +222,22 @@ def bar(self): case.assertEqual(actual, expected) + @it.should("have an attribute named func_defaults that is equal to the __defaults__ attribute") + @unittest.skipUnless(not six.PY3, 'Test should only be run under Python 2.x') + def test_should_have_an_attribute_named_func_defaults_that_is_equal_to_the_defaults_attribute(case): + class Foo(object): + def bar(self): + pass + + live_bound_method = Foo().bar + + sut = FakeCallable(live_bound_method) + expected = sut.__defaults__ + + actual = sut.func_defaults + + case.assertEqual(actual, expected) + @it.should("have an attribute named func_name that is equal to the __name__ attribute") @unittest.skipUnless(not six.PY3, 'Test should only be run under Python 2.x') def test_should_have_an_attribute_named_func_name_that_is_equal_to_the_name_attribute(case): @@ -289,6 +321,18 @@ def foo(): case.assertEqual(actual, expected) + @it.should("have the same default values for keyword arguments as the fake callable") + def test_should_have_the_same_default_values_for_keyword_arguments_as_the_fake_callable(case): + def foo(): + pass + + sut = FakeCallable(foo) + expected = sut.fake.__defaults__ + + actual = sut.__defaults__ + + case.assertEqual(actual, expected) + it.createTests(globals()) with such.A("Fake Function's initialization method") as it: diff --git a/tests/unit/fakes/support/fakes.py b/tests/unit/fakes/support/fakes.py index f426c27..e697f3e 100644 --- a/tests/unit/fakes/support/fakes.py +++ b/tests/unit/fakes/support/fakes.py @@ -1,12 +1,14 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import mock +from tests.common.compat import mock def fake_live_bound_callable(): mocked_callable = mock.MagicMock() self = mock.PropertyMock() type(mocked_callable).__self__ = self + defaults = mock.PropertyMock() + type(mocked_callable).__defaults__ = defaults mocked_callable.__name__ = 'fake_live_bound_callable' return mocked_callable, self diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index 7704b29..e66796c 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -121,7 +121,15 @@ def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_name_in sut = callables.FakeCallable(mock.DEFAULT) _ = sut.func_name + + @it.should("raise an attribute error when attempting to use the func_defaults internal attribute") + def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_defaults_internal_attribute(case): + with case.assertRaisesRegexp(AttributeError, + r"'FakeCallable' object has no attribute 'func_defaults'"): + sut = callables.FakeCallable(mock.DEFAULT) + _ = sut.func_defaults + @it.should("have a reference to the fake unbound version of the method if the method is bound") def test_should_have_a_reference_to_the_fake_unbound_version_of_the_method_if_the_method_is_bound(case): live_callable, _ = fake_live_bound_callable() @@ -171,6 +179,15 @@ def test_should_have_the_same_docstring_as_the_live_callable(case): case.assertEqual(actual, expected) + @it.should("have the same default values for keyword arguments as the fake callable") + def test_should_have_the_same_default_values_for_keyword_arguments_as_the_fake_callable(case): + sut = callables.FakeCallable(mock.DEFAULT) + expected = sut.fake.__defaults__ + + actual = sut.__defaults__ + + case.assertEqual(actual, expected) + with it.having('a python 2.x runtime2'): @it.has_test_setup def setup(case): @@ -276,6 +293,17 @@ def test_should_have_an_attribute_named_func_name_that_is_equal_to_the_name_attr case.assertEqual(actual, expected) + @it.should("have an attribute named func_defaults that is equal to the __defaults__ attribute") + def test_should_have_an_attribute_named_func_defaults_that_is_equal_to_the_defaults_attribute(case): + live_callable, _ = fake_live_bound_callable() + + sut = callables.FakeCallable(live_callable) + expected = sut.__defaults__ + + actual = sut.func_defaults + + case.assertEqual(actual, expected) + @it.should("have a reference to the fake unbound version of the method if the method is bound") def test_should_have_a_reference_to_the_fake_unbound_version_of_the_method_if_the_method_is_bound(case): live_callable, _ = fake_live_bound_callable() From 4fd159687b738622b179221662b3e42573cf3ad5 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Tue, 5 Nov 2013 18:40:51 +0200 Subject: [PATCH 46/46] Fake callables will now return the fake callable's globals. Added Python 2.x aliases for the globals internal attributes. --- .noseids | 791 ++++++++++--------- testdoubles/fakes/callables.py | 8 + tests/functional/fakes/test_fake_callable.py | 32 + tests/unit/fakes/test_fake_callable.py | 46 ++ 4 files changed, 499 insertions(+), 378 deletions(-) diff --git a/.noseids b/.noseids index 9a8cb8a..271385c 100644 --- a/.noseids +++ b/.noseids @@ -2,637 +2,672 @@ S'tests' p1 (dp2 -S'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0013: should have the same docstring as the live callable' +S'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0012: should not have a reference to the fake unbound version of the method if the method is unbound' p3 -I109 +I94 sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0005: should return false if the first method has specified a varargs argument and the second method has no arguments' p4 -I119 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0012: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' +I126 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' p5 -I92 +I118 sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0000: should have the same name as the live object' p6 -I96 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" +I100 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0015: should have the same code object as the fake callable' p7 -I117 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' +I115 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0003: should return false if the first method doesn't have the same amount of arguments as the second" p8 -I22 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' +I124 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' p9 -I49 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' +I22 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0014: should have the same docstring as the live callable' p10 -I47 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0000: should have the same name as the live object' +I96 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0011: should have a reference to the fake unbound version of the method if the method is bound' p11 -I17 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' +I93 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0010: should return false if the first method has no keyword arguments and the second method has a kwargs argument' p12 -I53 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0014: should have the same code object as the fake callable' +I51 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0008: should return false if the first method has no positional arguments and the second method has a varargs argument' p13 -I94 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0012: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' +I49 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0000: should have the same name as the live object' p14 -I108 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0006: should raise an attribute error when attempting to use the func_code internal attribute' +I17 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0000: should raise a TypeError when the configuration does not exist' p15 -I86 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' +I55 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0014: should have an attribute named func_doc that is equal to the __doc__ attribute' p16 -I52 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' +I31 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0018: should have a reference to the fake unbound version of the method if the method is bound' p17 -I58 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' +I35 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0011: should have a reference to the fake unbound version of the method if the method is bound' p18 -I99 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' +I111 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0011: should have an attribute named im_self that is equal to the __self__ attribute' p19 -I113 -sS"tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0007: should have an attribute named im_class that is equal to the __self__ attribute's type" +I28 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0013: should return false if the second method has a more positional arguments than the first method' p20 -I103 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0010: should have a reference to the fake unbound version of the method if the method is bound' +I54 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0000: should return true if the live function is an instance method' p21 -I106 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' +I60 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' p22 -I3 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" +I103 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0002: should return false if the argspecs are completely different' p23 -I71 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' +I120 +sS"tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0007: should have an attribute named im_class that is equal to the __self__ attribute's type" p24 -I115 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0008: should raise an attribute error when attempting to use the func_defaults internal attribute' +I107 +sS"tests.functional.fakes.test_fake_callable.A Fake Function object.test 0012: should have an attribute named im_class that is equal to the __self__ attribute's type" p25 -I25 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' +I29 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0022: should have the same code object as the fake callable' p26 -I67 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" +I39 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0002: should raise NotImplementedError when invoking any method that is missing in the fake implementation' p27 -I73 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' +I3 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0000: should have a read only property named live" p28 -I125 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0008: should raise an attribute error when attempting to use the func_name internal attribute' +I73 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0001: should return true if the first method has specified a varargs argument and the second method has an argument ' p29 -I88 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' +I122 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0008: should raise an attribute error when attempting to use the func_defaults internal attribute' p30 -I126 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' +I25 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0001: should return false if the live function is a bound instance method' p31 -I41 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' +I69 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a value error when inspecting arguments of a builtin callable" p32 -I1 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0006: should have an attribute named func_doc that is equal to the __doc__ attribute' +I75 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0004: should return false if the first method has specified a kwargs argument and the second method has no arguments' p33 -I102 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0000: should return true if the argspecs are completely identical' +I132 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0008: should raise an attribute error when attempting to use the func_name internal attribute' p34 -I111 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0010: should have a reference to the fake unbound version of the method if the method is bound' -p35 I90 -sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0005: should return false if the first method has no arguments and the second method has specified a kwargs argument' +p35 +I133 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0002: should return true if the argspecs are not completely identical but the first method has a varargs argument' p36 -I54 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' +I43 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0000: should substitute the real object with the fake object' p37 -I124 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." +I1 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0015: should have the same code object as the fake callable' p38 -I16 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' +I97 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0006: should have an attribute named func_doc that is equal to the __doc__ attribute' p39 -I55 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" +I106 +sS'tests.unit.fakes.test_fake.A Fake Object.test 0001: should raise a TestDoubleConfigurationError when the configuration does not contain the type to be faked' p40 -I8 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0013: should have the same docstring as the live callable' +I56 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0017: should have the same globals as the fake callable' p41 -I93 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" +I117 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a ValueError when arguments inspection is opted out." p42 -I9 -sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' +I16 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0010: should have an attribute named func_globals that is equal to the __globals__ attribute' p43 -I79 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0011: should not have a reference to the fake unbound version of the method if the method is unbound' +I110 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0000: should return true if the live function is an instance method' p44 -I107 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0002: should have a reference to the instance if the method is bound' +I57 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0000: should return false if the live function is an instance method" p45 -I82 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0019: should have the same docstring as the live callable' +I8 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0010: should raise an attribute error when attempting to use the func_globals internal attribute' p46 -I36 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' +I92 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0021: should have the same docstring as the live callable' p47 -I114 -sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" +I38 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0001: should return true if the live function is an unbound instance method" p48 -I118 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" +I9 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0006: should raise an attribute error when attempting to use the func_code internal attribute' p49 -I74 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' +I88 +sS'tests.unit.fakes.test_fake_callable.A Fake Function object.test 0000: should be callable' p50 -I68 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0000: should have the same name as the live object' +I81 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0016: should have an attribute named func_globals that is equal to the __globals__ attribute' p51 -I80 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' +I33 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0002: should have a reference to the instance if the method is bound' p52 -I63 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0005: should have an attribute named func_code that is equal to the __code__ attribute' +I84 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0000: should return true if the first method has an argument and the second method has specified a varargs argument' p53 -I101 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0001: should have the same name as the live object when the live object is a callable class instance' +I121 +sS"tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0004: should return false if the second method doesn't have the same amount of arguments as the first" p54 -I18 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' +I125 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a value error when the provided live object does not match the argspec" p55 -I66 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0013: should have an attribute named func_doc that is equal to the __doc__ attribute' +I76 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0010: should raise an attribute error when attempting to use the func_name internal attribute' p56 -I30 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' +I27 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0000: should have the same name as the live object' p57 -I56 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' +I82 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0006: should raise an attribute error when attempting to use the func_code internal attribute' p58 -I42 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' +I23 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0002: should return false if the live function is not an instance method' p59 -I51 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' +I65 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0005: should have an attribute named func_code that is equal to the __code__ attribute' p60 -I122 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" +I105 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0001: should have the same name as the live object when the live object is a callable class instance' p61 -I13 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0015: should have the same default values for keyword arguments as the fake callable' +I18 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0000: should return true if the live function is an unbound instance method' p62 -I95 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0004: should raise an attribute error when attempting to use the im_self alias' +I68 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0002: should return false if the live function is not an instance method' p63 -I21 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0018: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' +I70 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' p64 -I35 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' +I123 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0001: should return true if the live function is an unbound instance method' p65 -I85 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' +I58 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0013: should have an attribute named func_code that is equal to the __code__ attribute' p66 -I39 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" +I30 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0003: should return true if the argspecs are not completely identical but the second method has a varargs argument' p67 -I78 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" +I44 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0020: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' p68 -I10 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' +I37 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0012: should return false if the first method has a more positional arguments than the second method' p69 -I45 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0009: should have an attribute named func_defaults that is equal to the __defaults__ attribute' +I53 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0016: should have the same default values for keyword arguments as the fake callable' p70 -I105 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0020: should have the same code object as the fake callable' +I116 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0001: should return true if the first method has specified a kwargs argument and the second method has a keyword argument' p71 -I37 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0021: should have the same default values for keyword arguments as the fake callable' +I129 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0002: should return false if the live function is not an instance method" p72 -I38 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0002: should have a reference to the instance if the method is bound' +I13 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0004: should raise an attribute error when attempting to use the im_self alias' p73 -I98 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' +I21 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0005: should raise an attribute error when attempting to use the im_class internal attribute' p74 -I44 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' +I87 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0000: should return true if the argspecs are completely identical' p75 -I64 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' +I41 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0001: should be equal to the bound __call__ of the fake callable" p76 -I97 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' +I80 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is unbound instance method property.test 0002: should return false if the live function is not an instance method" p77 -I59 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0010: should have an attribute named im_self that is equal to the __self__ attribute' +I10 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0006: should return true if the first method has keyword arguments and the second method has a kwargs argument ' p78 -I27 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' +I47 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0009: should have an attribute named func_defaults that is equal to the __defaults__ attribute' p79 -I57 -sS"tests.functional.fakes.test_fake_callable.A Fake Function object.test 0011: should have an attribute named im_class that is equal to the __self__ attribute's type" +I109 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0017: should have the same globals as the fake callable' p80 -I28 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' +I99 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0002: should have a reference to the instance if the method is bound' p81 -I81 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0007: should raise an attribute error when attempting to use the func_doc internal attribute' +I102 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0005: should return true if the first method has a kwargs argument and the second method has keyword arguments' p82 -I87 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' +I46 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0003: should detect unbound instance methods by inspecting the arguments' p83 -I120 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' +I66 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' p84 -I5 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' +I101 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0012: should not have a reference to the fake unbound version of the method if the method is unbound' p85 -I50 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' +I112 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0013: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' p86 -I62 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" +I95 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0001: should return true if the live function is an unbound instance method' p87 -I14 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' +I61 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime1.test 0002: should return false if the live function is not an instance method' p88 -I7 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' +I59 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0001: should have the same name as the live object when the live object is a callable class instance' p89 -I4 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0008: should have an attribute named func_name that is equal to the __name__ attribute' +I83 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0007: should raise an attribute error when attempting to use the func_doc internal attribute' p90 -I104 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a value error when the provided live object matches the argspec" +I89 +sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0006: should return false if the first method has no arguments and the second method has specified a varargs argument' p91 -I75 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' +I127 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0004: should replace the original properties with the fake properties' p92 -I6 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" +I5 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0011: should return false if both methods have different keyword arguments' p93 -I15 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0012: should have an attribute named func_code that is equal to the __code__ attribute' +I52 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0001: should return false if the live function is a bound an instance method' p94 -I29 -sS'tests.unit.utils.test_are_arguments_identical.A arguments comparison method.test 0002: should return true if both methods have the same amount of arguments' +I64 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0000: should raise a TypeError when the provided live object is not callable" p95 -I116 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' +I14 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0023: should have the same default values for keyword arguments as the fake callable' p96 -I20 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' +I40 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0003: should return false if both methods have different keyword arguments and no kwargs argument' p97 -I46 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' +I131 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' p98 -I65 -sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' +I130 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0008: should have an attribute named func_name that is equal to the __name__ attribute' p99 -I112 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0002: should have a reference to the instance if the method is bound' +I108 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0006: should raise NotImplementedError when getting or setting any property that is missing in the fake implementation' p100 -I19 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0007: should raise an attribute error when attempting to use the func_doc internal attribute' +I7 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0003: should replace the original methods with the fake methods' p101 -I24 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" +I4 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0009: should raise an attribute error when attempting to use the func_globals internal attribute' p102 -I11 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' +I26 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0002: should not raise a value error when the provided live object matches the argspec" p103 -I83 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0015: should have an attribute named func_name that is equal to the __name__ attribute' +I77 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0005: should contain all properties that are missing in the fake implementation' p104 -I32 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0014: should have the same code object as the fake callable' +I6 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's initialization method.test 0001: should raise a ValueError when the provided live object does not match the argspec" p105 -I110 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" +I15 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0016: should have the same default values for keyword arguments as the fake callable' p106 -I76 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0006: should raise an attribute error when attempting to use the func_code internal attribute' +I98 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' p107 -I23 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' +I20 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0007: should return false if the first method has a varargs argument and the second method has no positional arguments' p108 -I43 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0017: should not have a reference to the fake unbound version of the method if the method is unbound' +I48 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0004: should not detect unbound instance methods by inspecting their self attribute' p109 -I34 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' +I67 +sS'tests.unit.utils.test_are_argspecs_identical.A argspecs comparison method.test 0001: should return true if the argspecs are almost identical' p110 -I60 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" +I119 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0019: should not have a reference to the fake unbound version of the method if the method is unbound' p111 -I72 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' +I36 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0002: should have a reference to the instance if the method is bound' p112 -I121 -sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' +I19 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0007: should raise an attribute error when attempting to use the func_doc internal attribute' p113 -I2 -sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0002: should return true if both methods have exactly the same keyword arguments' +I24 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0000: should return true if the live function is an instance method" p114 -I123 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0009: should raise an attribute error when attempting to use the func_defaults internal attribute' +I11 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0003: should raise an attribute error when accessing __self__ and the method is not a bound or unbound instance method' p115 -I89 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0014: should have an attribute named func_defaults that is equal to the __defaults__ attribute' +I85 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0017: should have an attribute named func_name that is equal to the __name__ attribute' p116 -I31 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0004: should raise an attribute error when attempting to use the im_self alias' +I34 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's initialization method.test 0003: should not inspect the argspec of the live object when argument inspection is opted out" p117 -I84 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0004: should have an attribute named im_self that is equal to the __self__ attribute' +I78 +sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0015: should have an attribute named func_defaults that is equal to the __defaults__ attribute' p118 -I100 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' +I32 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0004: should return true if both methods have exactly the same keyword arguments' p119 -I70 -sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" +I45 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime1.test 0002: should return false if the live function is not an instance method' p120 -I77 -sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" +I62 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's live property.test 0001: should be equal to the provided function" p121 -I12 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0011: should not have a reference to the fake unbound version of the method if the method is unbound' +I74 +sS'tests.unit.utils.test_are_keyword_arguments_identical.A keyword arguments comparison method.test 0000: should return true if the first method has a keyword argument and the second method has specified a kwargs argument' p122 -I91 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0009: should raise an attribute error when attempting to use the func_name internal attribute' +I128 +sS'tests.functional.fakes.test_fake.A Fake Object.test 0001: should contain all methods that are missing in the fake implementation' p123 -I26 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' +I2 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0014: should have the same docstring as the live callable' p124 -I48 -sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' +I114 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0009: should raise an attribute error when attempting to use the func_defaults internal attribute' p125 -I40 -sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' +I91 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime2.test 0004: should raise an attribute error when attempting to use the im_self alias' p126 -I69 -sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' +I86 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0004: should have an attribute named im_self that is equal to the __self__ attribute' p127 -I61 -sS'tests.functional.fakes.test_fake_callable.A Fake Function object.test 0016: should have a reference to the fake unbound version of the method if the method is bound' +I104 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0004: should detect unbound instance methods by inspecting their self attribute' p128 -I33 +I72 +sS"tests.unit.fakes.test_fake_callable.A Fake Function's fake property.test 0000: should have a read only property named fake" +p129 +I79 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0009: should return false if the first method has a kwargs argument and the second method has no keyword arguments' +p130 +I50 +sS'tests.functional.utils.test_are_argspecs_identical.A keyword arguments comparison method.test 0001: should return true if the argspecs are not completely identical but have the same number of positional arguments' +p131 +I42 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime2.test 0013: should raise an attribute error when accessing __func__ and the method is not a bound or unbound instance method' +p132 +I113 +sS'tests.unit.fakes.test_fake_callable.having a python 2.x runtime.test 0003: should not detect unbound instance methods by inspecting the arguments' +p133 +I71 +sS'tests.unit.fakes.test_fake_callable.having a python 3.x runtime.test 0000: should return true if the live function is an unbound instance method' +p134 +I63 +sS"tests.functional.fakes.test_fake_callable.A Fake Function's is instance method property.test 0001: should return true if the live function is an unbound instance method" +p135 +I12 ssS'ids' -p129 -(dp130 +p136 +(dp137 I1 -g32 +g37 sI2 -g113 +g123 sI3 -g22 +g27 sI4 -g89 +g101 sI5 -g84 -sI6 g92 +sI6 +g104 sI7 -g88 +g100 sI8 -g40 +g45 sI9 -g42 +g48 sI10 -g68 +g77 sI11 -g102 +g114 sI12 -g121 +g135 sI13 -g61 +g72 sI14 -g87 +g95 sI15 -g93 +g105 sI16 -g38 +g42 sI17 -g11 +g14 sI18 -g54 +g61 sI19 -g100 +g112 sI20 -g96 +g107 sI21 -g63 +g73 sI22 -g8 +g9 sI23 -g107 +g58 sI24 -g101 +g113 sI25 -g25 +g30 sI26 -g123 +g102 sI27 -g78 +g56 sI28 -g80 +g19 sI29 -g94 +g25 sI30 -g56 +g66 sI31 -g116 +g16 sI32 -g104 +g118 sI33 -g128 +g51 sI34 -g109 +g116 sI35 -g64 +g17 sI36 -g46 +g111 sI37 -g71 +g68 sI38 -g72 +g47 sI39 -g66 +g26 sI40 -g125 +g96 sI41 -g31 +g75 sI42 -g58 +g131 sI43 -g108 +g36 sI44 -g74 +g67 sI45 -g69 +g119 sI46 -g97 +g82 sI47 -g10 +g78 sI48 -g124 +g108 sI49 -g9 +g13 sI50 -g85 +g130 sI51 -g59 +g12 sI52 -g16 +g93 sI53 -g12 +g69 sI54 -g36 +g20 sI55 -g39 +g15 sI56 -g57 +g40 sI57 -g79 +g44 sI58 -g17 +g65 sI59 -g77 +g88 sI60 -g110 +g21 sI61 -g127 +g87 sI62 -g86 +g120 sI63 -g52 +g134 sI64 -g75 +g94 sI65 -g98 +g59 sI66 -g55 +g83 sI67 -g26 +g109 sI68 -g50 +g62 sI69 -g126 +g31 sI70 -g119 +g63 sI71 -g23 +g133 sI72 -g111 +g128 sI73 -g27 +g28 sI74 -g49 +g121 sI75 -g91 +g32 sI76 -g106 +g55 sI77 -g120 +g103 sI78 -g67 +g117 sI79 -g43 +g129 sI80 -g51 +g76 sI81 -g81 +g50 sI82 -g45 +g57 sI83 -g103 +g89 sI84 -g117 +g52 sI85 -g65 +g115 sI86 -g15 +g126 sI87 -g82 +g74 sI88 -g29 +g49 sI89 -g115 +g90 sI90 -g35 +g34 sI91 -g122 +g125 sI92 -g5 +g46 sI93 -g41 +g11 sI94 -g13 +g3 sI95 -g62 +g86 sI96 -g6 +g10 sI97 -g76 +g38 sI98 -g73 +g106 sI99 -g18 +g80 sI100 -g118 +g6 sI101 -g53 +g84 sI102 -g33 +g81 sI103 -g20 +g22 sI104 -g90 +g127 sI105 -g70 +g60 sI106 -g21 +g39 sI107 -g44 +g24 sI108 -g14 +g99 sI109 -g3 +g79 sI110 -g105 +g43 sI111 -g34 +g18 sI112 -g99 +g85 sI113 -g19 +g132 sI114 -g47 +g124 sI115 -g24 +g7 sI116 -g95 +g70 sI117 -g7 +g41 sI118 -g48 +g5 sI119 -g4 +g110 sI120 -g83 +g23 sI121 -g112 +g53 sI122 -g60 +g29 sI123 -g114 +g64 sI124 -g37 +g8 sI125 -g28 +g54 sI126 -g30 +g4 +sI127 +g91 +sI128 +g122 +sI129 +g71 +sI130 +g98 +sI131 +g97 +sI132 +g33 +sI133 +g35 ss. \ No newline at end of file diff --git a/testdoubles/fakes/callables.py b/testdoubles/fakes/callables.py index ae62dfe..7a47ffd 100644 --- a/testdoubles/fakes/callables.py +++ b/testdoubles/fakes/callables.py @@ -40,6 +40,10 @@ def __code__(self): def __defaults__(self): return self.fake.__defaults__ + @property + def __globals__(self): + return self.fake.__globals__ + def __getattribute__(self, item): if item == '__doc__': return self.live.__doc__ @@ -100,6 +104,10 @@ def func_name(self): def func_defaults(self): return self.__defaults__ + @property + def func_globals(self): + return self.__globals__ + class FakeCallable(CallableIntrospectionMixin, CallableInternalAttributesMixin): def __init__(self, live, inspect_args=False): diff --git a/tests/functional/fakes/test_fake_callable.py b/tests/functional/fakes/test_fake_callable.py index caaa84f..8badb56 100644 --- a/tests/functional/fakes/test_fake_callable.py +++ b/tests/functional/fakes/test_fake_callable.py @@ -142,6 +142,22 @@ def bar(self): _ = sut.func_defaults + @it.should("raise an attribute error when attempting to use the func_globals internal attribute") + @unittest.skipUnless(six.PY3, 'Test should only be run under Python 3.x') + def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_globals_internal_attribute(case): + class Foo(object): + def bar(self): + pass + + live_unbound_method = Foo.bar + + sut = FakeCallable(live_unbound_method) + + with case.assertRaisesRegexp(AttributeError, + r"'FakeCallable' object has no attribute 'func_globals'"): + + _ = sut.func_globals + @it.should("raise an attribute error when attempting to use the func_name internal attribute") @unittest.skipUnless(six.PY3, 'Test should only be run under Python 3.x') def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_name_internal_attribute(case): @@ -238,6 +254,22 @@ def bar(self): case.assertEqual(actual, expected) + @it.should("have an attribute named func_globals that is equal to the __globals__ attribute") + @unittest.skipUnless(not six.PY3, 'Test should only be run under Python 2.x') + def test_should_have_an_attribute_named_func_globals_that_is_equal_to_the_globals_attribute(case): + class Foo(object): + def bar(self): + pass + + live_bound_method = Foo().bar + + sut = FakeCallable(live_bound_method) + expected = sut.__globals__ + + actual = sut.func_globals + + case.assertEqual(actual, expected) + @it.should("have an attribute named func_name that is equal to the __name__ attribute") @unittest.skipUnless(not six.PY3, 'Test should only be run under Python 2.x') def test_should_have_an_attribute_named_func_name_that_is_equal_to_the_name_attribute(case): diff --git a/tests/unit/fakes/test_fake_callable.py b/tests/unit/fakes/test_fake_callable.py index e66796c..0f2237b 100644 --- a/tests/unit/fakes/test_fake_callable.py +++ b/tests/unit/fakes/test_fake_callable.py @@ -130,6 +130,14 @@ def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_default _ = sut.func_defaults + @it.should("raise an attribute error when attempting to use the func_globals internal attribute") + def test_should_raise_an_attribute_error_when_attempting_to_use_the_func_globals_internal_attribute(case): + with case.assertRaisesRegexp(AttributeError, + r"'FakeCallable' object has no attribute 'func_globals'"): + sut = callables.FakeCallable(mock.DEFAULT) + + _ = sut.func_globals + @it.should("have a reference to the fake unbound version of the method if the method is bound") def test_should_have_a_reference_to_the_fake_unbound_version_of_the_method_if_the_method_is_bound(case): live_callable, _ = fake_live_bound_callable() @@ -188,6 +196,15 @@ def test_should_have_the_same_default_values_for_keyword_arguments_as_the_fake_c case.assertEqual(actual, expected) + @it.should("have the same globals as the fake callable") + def test_should_have_the_same_default_values_for_keyword_arguments_as_the_fake_callable(case): + sut = callables.FakeCallable(mock.DEFAULT) + expected = sut.fake.__globals__ + + actual = sut.__globals__ + + case.assertEqual(actual, expected) + with it.having('a python 2.x runtime2'): @it.has_test_setup def setup(case): @@ -304,6 +321,17 @@ def test_should_have_an_attribute_named_func_defaults_that_is_equal_to_the_defau case.assertEqual(actual, expected) + @it.should("have an attribute named func_globals that is equal to the __globals__ attribute") + def test_should_have_an_attribute_named_func_globals_that_is_equal_to_the_globals_attribute(case): + live_callable, _ = fake_live_bound_callable() + + sut = callables.FakeCallable(live_callable) + expected = sut.__globals__ + + actual = sut.func_globals + + case.assertEqual(actual, expected) + @it.should("have a reference to the fake unbound version of the method if the method is bound") def test_should_have_a_reference_to_the_fake_unbound_version_of_the_method_if_the_method_is_bound(case): live_callable, _ = fake_live_bound_callable() @@ -353,6 +381,24 @@ def test_should_have_the_same_docstring_as_the_live_callable(case): case.assertEqual(actual, expected) + @it.should("have the same default values for keyword arguments as the fake callable") + def test_should_have_the_same_default_values_for_keyword_arguments_as_the_fake_callable(case): + sut = callables.FakeCallable(mock.DEFAULT) + expected = sut.fake.__defaults__ + + actual = sut.__defaults__ + + case.assertEqual(actual, expected) + + @it.should("have the same globals as the fake callable") + def test_should_have_the_same_default_values_for_keyword_arguments_as_the_fake_callable(case): + sut = callables.FakeCallable(mock.DEFAULT) + expected = sut.fake.__globals__ + + actual = sut.__globals__ + + case.assertEqual(actual, expected) + it.createTests(globals()) with such.A("Fake Function's initialization method") as it: