From b56d1cab1c656445d5dc91d09fae9b45fbd0ae36 Mon Sep 17 00:00:00 2001 From: asabrina messikh Date: Wed, 6 Mar 2024 16:00:53 +0100 Subject: [PATCH] fix bugs in test_cartepizza class --- CartePizzeria.py | 8 +++- TestsUnitaires.py | 41 ----------------- __pycache__/CartePizzeria.cpython-312.pyc | Bin 0 -> 1510 bytes .../CartePizzeriaException.cpython-312.pyc | Bin 0 -> 593 bytes ...st_cartePizza.cpython-312-pytest-8.0.2.pyc | Bin 0 -> 5926 bytes test_cartePizza.py | 43 ++++++++++++++++++ 6 files changed, 49 insertions(+), 43 deletions(-) delete mode 100644 TestsUnitaires.py create mode 100644 __pycache__/CartePizzeria.cpython-312.pyc create mode 100644 __pycache__/CartePizzeriaException.cpython-312.pyc create mode 100644 __pycache__/test_cartePizza.cpython-312-pytest-8.0.2.pyc create mode 100644 test_cartePizza.py diff --git a/CartePizzeria.py b/CartePizzeria.py index 5c0008c..c70816f 100644 --- a/CartePizzeria.py +++ b/CartePizzeria.py @@ -1,3 +1,6 @@ +from CartePizzeriaException import CartePizzeriaException + + class CartePizzeria: def __init__(self): self.pizzas=[] @@ -14,7 +17,8 @@ def add_pizza(self,pizza): def remove_pizza(self,name): for p in self.pizzas: if(p.name==name): - self.pizzas.remove(p) + self.pizzas.remove(p) + return - raise CartePizzeriaException("Pizza not found: " + name) + raise CartePizzeriaException("Pizza not found: " + name) \ No newline at end of file diff --git a/TestsUnitaires.py b/TestsUnitaires.py deleted file mode 100644 index 82bfb65..0000000 --- a/TestsUnitaires.py +++ /dev/null @@ -1,41 +0,0 @@ -import pytest -from unittest.mock import MagicMock -from CartePizzeria import CartePizzeria, CartePizzeriaException - -def test_is_empty(): - carte_pizza=CartePizzeria() - assert carte_pizza.is_empty()==True - - pizza_mock=MagicMock() - pizza_mock.add(Campionne) - assert pizza_mock.is_empty()==False - -def test_nb_pizzas(): - carte_pizza=CartePizzeria() - assert carte_pizza.nb_pizzas==0 - - pizza_mock=MagicMock() - pizza_mock.add(Campionne) - pizza_mock.add(Marguarita) - assert pizza_mock.nb_pizzas==2 - -def test_add_pizza(): - carte_pizza=CartePizzeria() - pizza_mock=MagicMock() - pizza_mock.add_pizza(Campionne) - assert pizza_mock.nb_pizza()==1 - -def test_remove_pizza(): - carte_pizza=CartePizzeria - pizza_mock_1=MagicMock() - pizza_mock_1.name="vegetarienne" - pizza_mock_2=MagicMock() - pizza_mock_2.name="marguarita" - carte_pizza.add(pizza_mock_1) - carte_pizza.add(pizza_mock_2) - - carte_pizza.remove_pizza(pizza_mock_1) - assert carte_pizza.nb_pizzas==1 - - with pytest.raises(CartePizzeriaException): - carte_pizza.remove_pizza("Hawaiiane") diff --git a/__pycache__/CartePizzeria.cpython-312.pyc b/__pycache__/CartePizzeria.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..93fd10d005794c973d38edc965124e68b36cff26 GIT binary patch literal 1510 zcma)6%}*0i5TCc*E?WwAp$HL8SWpsc6rv?@uO9p#yg<;18$Ef^o1rEqoSfP1BCV1*Nq?PvGjHB+emig9wYRqd+M9)M z<~0f6D?J1z*PYrCbR6KoSq}1$0tOOX2QDoD552}+WGPmb6XEaVCYakjkrB3eD_g0U zBAdDTaLO#%*kdioCfK-Tzr(_;N409P#;bFv{u?gX?)`{T2eW-$go^NGXWl3bGl#p1)T4kCq~nEEK^wN;o);< z&!xF(&DzCM+U6&0)3VbIhYpp>u4)+BLe@5nN@Kf2!Fm|$S`mcDu-VnUC_j(Zh)4rr zBI^-8jgABMPBT@QsY^?H0()JLb2fVv;5H6;Hbfn*uh@$JNS<5i< zCA-{AG+3uyRyV?9_^id3C!L!sH#ao>RsXtncr9{Rv}5SstdC>l|5@J#(SjR9jG&oi zq;SvhUreQ^QR|%mbz^lPAkSFm@`!VB<>E%HZ%ysPUujzl-K3b^`k_-ReTXsZiTqM3SGe_4goxps?xuPrs@rg#h%6YP=N-u$*R&H6-Wme zY zU5S3w2G+HKSEt@nvlU{4YlG+Cj;s$}+1NL>rjB{)Cle}NZQ^VgZmVJB zi+nCeew$%Dn9Jn+h-kxu1yK-jf*yiH2&>?g@#aC0vL4WDv?#m)TM`TRY$+^!gg_@4 zs3}T#ocSARPZDR0MDYvg- Dw}LJk literal 0 HcmV?d00001 diff --git a/__pycache__/CartePizzeriaException.cpython-312.pyc b/__pycache__/CartePizzeriaException.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c970c5595cf58c530bdd089af8853c818d783854 GIT binary patch literal 593 zcmZ`$J4?hs5T4n1UQP|Dg^GeNY*J_=sECLlVkd%F7y?U3Rte@F?&iQduCO>z3ro?z zApR693!7kPV=0`XSUH99L^@9L&c; z#qQs77itaJOAO7afACy`UP}#<`#OVX)4D7^nq#-4Pv%UAdSDl{+KN{eoF{#pm#aZN z()j@ACv`8%ko2X*>T35z6wz)dOPX3AVMFR)D)mOG(>-O8`)b1{!@}$vkdys6u5VTP my?i=y2N|r1zRk5v$GRM*GG!a0_Mhmhcv zqLxd=p$86d=%Lpre?A`3*n4sfGzK+37_jXn16vV-A5_MKem(#;(s3)$I;SNg!*=Z#~W-J|K*Az8Uk8!{ugZilp=2)?C zp<1{Mjm&A2yY{EW>1mr6P3YLz)N$r&!LGT*YNZgquDB#Ys_=jI8^~M4rSj%nSg8|_ zjLR>SH{n{R3h`*9rC7ACdWxrB?uUEKW6lq5LaL8zvKC)0#bcw?63>h(b1MQh=73!%{&q{p9 zreU7y2}`q*UZO}vOLKeV8#j!&R`$hLPm`A9^()wcS81KXUx7cXtL_G=FXyqIgw@?7 zd*iE@lve0U*I$3L{tff@uU!8rVx)#Xo25(2sZ$1>{;;pVHg(i+($~UD_EZ*Yhh-O3 z!mdMxlPfxTyIgap()E5LUC*8hlusCr-%&u%ldpm6F=v^t)}{`jIE>;biW5s+rsLS$ z74`?=5$GH|YjkqNy{}8te)|2|lxsU~-sFByzF?M0d2ZKup<1q)-1a-+cK*^tvE&vj zj<1!fpyBwN^UjymiIOE$^JAszC9{;Tm}T2fMhkw|2jT_5|DEBy%Kdfu(JC*S zZr;9HE14A&JtId?=%-A}3ckhAIeH_%1BVShV4$&aq_J_lv2iSD1Vfw*-aBXv9P-m* zqVi>M+l~(Qvtd~pIQ{m>=P*sq$dMx_j-ME@Z0E9Dt&OVzVap1 z0V~#?I$T@~QKC?pf^&(I19=w`jVL7$p>ms4r>;P%q(pX9NR^nUdQ7BB2`>Su(y~bp zq)G{qD#0^NsZvJ1MLX!q@kFW=+sBRCQkqhwShHP{5hYb3Ra#y*4uO}~i&CJ5S!g#l zlP)?+l{AqmX<@3Aj0vH^5(2HI#L11c7^X^?CaLgG)ET%AedsY}kivEFJy^r63%L7dkd_8KtsH3<^=KZw zsVHr*r~oFESObuW4!)(dAhVrDv_}PYqkS41vYOG|=18Kh0=iX+wmP%adctE~LZDmo zG(h*VIJKCk0lLLA4d`x2{Kwm%L5?TT9ot8OX(>(Ujy2oiq7mI%!&|r0jZwS2%?P!x zu$Pcnw36XLNYc`+l$Q+At-HvPqBK}SwrnY06v|19A-WOS4E|a@;Ub@kGLEF$QrxWU zkQR=Sm+p_W)Dg#baKtwk?psQx$SyKK96AXHfEU36_FPpjl1XZG4Edc`>@nK~`nG|! zxdB7+gD7yDzSQ0LsdMI}SuC0r+vpL=bC9z#Om{`>;CFJnT)h%z$4_4j&FcI@;X&1+&uaciHyaU(B-ue@AG6u}!M`+um<_=QkbvIhFg9&_r%g zU$>xV@9Np_x6SJZpR3UI9Q(!1B?k{G@9bE6W>CE|m^iB>jc#9;=NTe8^ta@LMaTu` z4G`1ixIGC$9-L-GU4Am`3y9_@SoJd#m7vg-la`+y8SWg0b}uF>h9r|TKr L^Q<#NbHdbLjmOzq literal 0 HcmV?d00001 diff --git a/test_cartePizza.py b/test_cartePizza.py new file mode 100644 index 0000000..5384c4a --- /dev/null +++ b/test_cartePizza.py @@ -0,0 +1,43 @@ +import pytest +from unittest.mock import MagicMock +from CartePizzeria import CartePizzeria +from CartePizzeriaException import CartePizzeriaException + +def test_is_empty(): + carte_pizza=CartePizzeria() + assert carte_pizza.is_empty()==True + + pizza_mock=MagicMock() + carte_pizza.add_pizza(pizza_mock) + assert carte_pizza.is_empty()==False + +def test_nb_pizzas(): + carte_pizza=CartePizzeria() + assert carte_pizza.nb_pizzas()==0 + + marguarita=MagicMock() + campionne=MagicMock() + carte_pizza.add_pizza(marguarita) + carte_pizza.add_pizza(campionne) + assert carte_pizza.nb_pizzas()==2 + +def test_add_pizza(): + carte_pizza=CartePizzeria() + campionne=MagicMock() + carte_pizza.add_pizza(campionne) + assert carte_pizza.nb_pizzas()==1 + +def test_remove_pizza(): + carte_pizza=CartePizzeria() + pizza_mock_1=MagicMock() + pizza_mock_1.name="vegetarienne" + pizza_mock_2=MagicMock() + pizza_mock_2.name="marguarita" + carte_pizza.add_pizza(pizza_mock_1) + carte_pizza.add_pizza(pizza_mock_2) + + carte_pizza.remove_pizza("vegetarienne") + assert carte_pizza.nb_pizzas()==1 + + with pytest.raises(CartePizzeriaException): + carte_pizza.remove_pizza("Hawaiiane")