Beyond coverage

It looks like the­re are a lot of opi­nions or as­sump­tions about unit tes­ts an­d ­co­de co­ve­ra­ge, most of them con­fu­sing of bia­sed in se­ve­ral wa­ys. For exam­ple, I’­ve heard or read things like “this is fi­ne, it has X% co­ve­ra­ge”, or “che­ckin­g ­for co­ve­ra­ge on pu­ll re­ques­ts does­n’t hel­p”, or “dro­pping the co­ve­ra­ge le­vel is ­not an is­sue”, and many mo­re of the like.

This arti­cle ai­ms to shed so­me li­ght on the is­sue of unit tes­ting wi­th and co­de ­co­ve­ra­ge. Ho­pe­fu­lly by the end of it, we’­ll get an idea of whi­ch of the ­pre­vious sta­te­men­ts are ri­ght and whi­ch are wrong (s­poi­ler aler­t: the­y’­re all w­ron­g, but for di­ffe­rent rea­son­s).

Leer más…

PyCon CZ - Day 1

The day started at 9.00, and at first it was ti­me of che­ck-i­n, etc. After tha­t, I sol­ved one ri­dd­le by kiwi.­com, and ear­ned a dis­count in fli­gh­ts, whi­ch was a ni­ce way to start the con­fe­ren­ce.

Then after break­fast and so­me ne­two­rking going th­rou­gh the booths of the s­pon­sor­s, it was ti­me for the first ta­lk of the da­y: “When bugs bi­te - wh­y ­ne­glec­ting edge ca­ses can ki­ll“.

It was a great ta­lk, a ca­se for so­ftwa­re en­gi­nee­ring in ge­ne­ral (i­t’s no­t ­P­y­tho­n-s­pe­ci­fi­c, whi­ch is what makes the to­pic mo­re in­te­res­tin­g). The bes­t ­thing I liked about the ta­lk was the re­ma­rks, and the idea of shi­fting the ­min­d­set when it co­mes to de­ve­lo­p­men­t, so we should do so­me “ne­ga­ti­ve thi­nkin­g” in the form of what can go wrong wi­th this? How can this fai­l?, and su­ch. I­t’s im­por­tan­t, be­cau­se this is cri­ti­cal in or­der to make ro­bust so­ftwa­re. Mos­t ­pro­ble­ms I ha­ve seen on so­ftwa­re bugs we­re re­lated to so­me op­ti­mis­tic thi­nkin­g, and even wor­se, op­ti­mis­tic unit tes­tin­g, in the way that de­ve­lo­pers on­ly tes­t ­for ha­pp­y-­pa­th sce­na­rio­s, wi­thout thi­nking all sort of things that can go­ w­ron­g.

Afte­rwar­d­s, was the ti­me for the ta­lk about pa­ra­llel pro­ce­s­sing (poor per­so­n’s ­pa­ra­llel pro­ce­s­sing), whi­ch was fi­ne. Then I spent so­me ti­me ta­ck­ling so­me of ­the cha­llen­ges spon­sors had avai­la­ble, so I did so­me co­ding and re­cap of the e­ven­ts so fa­r.

Then I lis­te­ned to a ta­lk about wol­fcr­ypt whi­ch is a tool fo­r cr­yp­to in Py­tho­n. The ta­lk in­tro­du­ced so­me cr­yp­to con­cep­ts (s­y­m­me­tri­c cr­yp­to, pu­blic ke­y, etc.), whi­ch was good. Most of the ques­tions re­vol­ve­d a­round com­pa­ri­son wi­th other tools in py­thon (de­fault li­bra­rie­s, py­cr­yp­to, e­tc.).

Then it was ti­me for lun­ch and do so­me mo­re co­din­g, and the next ta­lk I a­tten­ded to was ca­lled “should I mo­ck or should I no­t?“, whi­ch I liked ve­r­y ­mu­ch and ga­ve so­me food for thou­gh­t.

Then it ca­me one mo­re ta­lk, after whi­ch it was ti­me for mi­ne, so I pre­sen­te­d clean co­de in Py­thon. The­re we­re so­me in­te­res­ting ques­tion­s, and the en­ti­re ­pre­sen­ta­tion went re­la­ti­ve­ly qui­ck­l­y.

On­ce the ta­lk ses­sions we­re ove­r, the­re was one last tra­ck for li­gh­tning ta­lks, whi­ch are alwa­ys su­per en­ter­tai­nin­g.

After the fi­nish of the first da­y, I atten­ded the speake­r’s din­ne­r, whi­ch was a ­ni­ce oppor­tu­ni­ty to ne­two­rk wi­th the co­m­mu­ni­ty, whi­ch is alwa­ys grea­t.

Looking fo­rward to so­me mo­re in­te­res­ting ta­lks to­mo­rro­w, and to see the re­sul­ts of the cha­llen­ges.

The __set_name__ method for descriptors

Des­crip­tors ge­ne­ra­lly ha­ve to in­te­ract wi­th attri­bu­tes of the ma­na­ged ob­jec­t, and this is do­ne by ins­pec­ting __­dic­t__ on that ob­ject (or ca­llin­g ge­ta­ttr/se­ta­ttr, but the pro­blem is the sa­me), and fin­ding the key un­de­r ­the spe­ci­fic na­me.

For this rea­so­n, the des­crip­tor wi­ll ha­ve to know the na­me of the key to look ­fo­r, whi­ch is re­lated to the na­me of the attri­bu­te is ma­na­gin­g.

On pre­vious ver­sions of Py­thon this had to be do­ne ex­pli­ci­tl­y. If we wanted to­ wo­rk around it, the­re we­re so­me mo­re ad­van­ced wa­ys to do so. Lu­cki­l­y, afte­r PE­P-487 (a­dded in Py­thon 3.6), ­the­re are so­me enhan­ce­men­ts re­gar­ding cla­ss crea­tio­n, whi­ch al­so affec­ts ­des­crip­tor­s.

Le­t’s re­view the pro­ble­m, the pre­vious appro­aches to ta­ck­le it, and the mo­der­n way of sol­ving it.

Leer más…