Show
Ignore:
Timestamp:
06/01/07 16:36:20 (18 months ago)
Author:
Tarek Ziad?? <tarek@…>
Message:

fin partie 1

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • JFP/slides.txt

    r104 r105  
    1 ======= 
    2 RuPy'07 
    3 ======= 
    4  
    5 Agile documentation in Python projects 
     1====== 
     2JPF'07 
     3====== 
     4 
     5Le Document-Driven Developpement (DDD) 
    66 
    77:Author: Tarek Ziadé <tarek@ziade.org> 
     
    1111.. contents: 
    1212 
    13 How am I ? 
    14 ========== 
    15  
    16 - Python developer since 2000 
    17 - Core developer in Nuxeo CPS (Zope) for 3 years 
    18 - Involved in Zope sprints 
    19 - Author of 
    20  
    21   - a French book "Programmation Python" (Eyrolles, 2006) 
    22   - another one coming up this summer 
    23   - articles in magazines 
    24  
    25 - Creator of AFPY (french speaking PUG) 
    26 - CTO at Emencia, for a Python e-commerce framework 
    27  
    28 What are the goals of this presentation ? 
    29 ========================================= 
    30  
    31 The main goal is to understand how Agile documentation works in Python, 
    32 through: 
    33  
    34 - Understanding how Test-Driven Development works in Python 
    35  
    36 - Discovering reStructuredText and doctests 
    37  
    38 - Understanding how Document-Driven Developement works 
    39  
    40 - Learning a few patterns 
    41  
    42 What are the goals of this presentation ? 
    43 ========================================= 
    44  
    45 My secret goal is to come to RuPy to see how Ruby works... 
    46  
    47 The plan 
     13Qui suis-je ? 
     14============= 
     15 
     16- Développeur Python depuis 2000 
     17- Auteur d'articles et de livres sur Python 
     18- Président de l'AFPY 
     19- Passionné par les méthodologies **agiles** 
     20 
     21Pourquoi cette présentation? 
     22============================ 
     23 
     24Objectifs: 
     25 
     26- Sensibiliser les développeurs aux tests 
     27- Expliquer comment les tests fonctionnent en Python 
     28- Sensibiliser les développeurs au **DDD** 
     29- Expliquer pourquoi le **reST** et les **doctests** c'est merveilleux 
     30 
     31|important| En un mot: comment développer `agile` en Python 
     32 
     33Pourquoi cette présentation? 
     34============================ 
     35 
     36Objectifs secrets (ne pas montrer ce slide): 
     37 
     38- Ridiculiser Java 
     39- Déprimer les développeurs Ruby 
     40- Rendre les chefs de projet C# jaloux 
     41- Augmenter le nombre d'adhérents à l'association 
     42 
     43Le plan 
     44======= 
     45 
     46- **Quelques définitions** |smile| 
     47- `Partie 1: le TDD avec Python` 
     48- `Part 2: les doctests` 
     49- `Part 3: le DDD` 
     50 
     51Quelques définitions 
     52==================== 
     53 
     54Que veux dire le mot **agile** ? 
     55 
     56Quelques définitions 
     57==================== 
     58 
     59Tentative de définition appliqué au développement: 
     60 
     61**C'est une méthodologie de programmation qui permet de 
     62rester réactif aux fréquentes modifications d'une base 
     63de code** 
     64 
     65Viens de l'`Agile Manifesto` (http://agilemanifesto.org/ [#]_) 
     66 
     67- créé par le GoF (Beck, etc.) et co 
     68- XP est une méthode agile populaire 
     69 
     70.. [#] Le site ressemble à celui d'une secte, mais c'est une bonne secte |wink| 
     71 
     72Quelques définitions 
     73==================== 
     74 
     75Les principes agiles peuvent s'appliquer à tout processus répétitif: 
     76 
     77- coder (-> TDD) 
     78- faire de la documentation (->DDD) 
     79- passer la tondeuse 
     80- etc. 
     81 
     82Le plan 
     83======= 
     84 
     85- `Quelques définitions` 
     86- **Partie 1: le TDD avec Python** |smile| 
     87- `Part 2: les doctests` 
     88- `Part 3: le DDD` 
     89 
     90Partie 1 
    4891======== 
    4992 
    50 - **A few definitions** 
    51 - `Part 1: doing TDD in Python` 
    52 - `Part 2: writing documents in reST` 
    53 - `Part 3: writing doctests` 
    54 - `Part 4: doing DDD in Python` 
    55  
    56 A few definitions 
    57 ================= 
    58  
    59 What kind of documentation are we talking about ? 
    60  
    61 A few definitions 
    62 ================= 
    63  
    64 Technical documentation that helps to understand how a codebase 
    65 works and how it can be used. This can be: 
    66  
    67 - a document describing a package [1]_, a module [1]_ or a 
    68   serie of package 
    69 - a glossary 
    70 - a tutorial 
    71 - a recipe 
    72  
    73 .. [1] Python folders and files 
    74  
    75 A few definitions 
    76 ================= 
    77  
    78 What **Agile** means ? 
    79  
    80 A few definitions 
    81 ================= 
    82  
    83 **A lightweight process to stay reactive to frequent changes** 
    84  
    85 - Comes from the Agile Manifesto 
    86  
    87   - http://agilemanifesto.org/ [#]_ 
    88   - created by members of the GoF (Beck, etc.) and others 
    89   - XP is one popular agile method 
    90  
    91 .. [#] The website looks a bit like some sect site but it's a good sect 
    92  
    93 A few definitions 
    94 ================= 
    95  
    96 Agile principles can be applied to any repeating process: 
    97  
    98 - coding 
    99 - documenting 
    100 - lawn-mowing 
    101 - etc. 
    102  
    103 The plan 
    104 ======== 
    105  
    106 - `A few definitions` 
    107 - **Part 1: doing TDD in Python** 
    108 - `Part 2: writing documents in reST` 
    109 - `Part 3: writing doctests` 
    110 - `Part 4: doing DDD in Python` 
    111  
    112 Part 1 
    113 ====== 
    114  
    115 **Doing TDD in Python** 
    116  
    117 This part is composed of: 
    118  
    119 - **The TDD principles** 
    120 - `How to write tests in Python` 
    121 - `How to organise tests in a Python project` 
    122  
    123 TDD Principles 
    124 ============== 
    125  
    126 - Each function or method can have one or several sample use case 
    127 - A sample use case == a test 
    128  
    129 TDD Principles 
    130 ============== 
    131  
    132 Example:: 
     93**Le TDD avec Python** 
     94 
     95- **Les principes du TDD** 
     96- `Comment écrire des tests` 
     97 
     98Les principes du TDD 
     99==================== 
     100 
     101- Chaque fonction == un ou plusieurs cas d'utilisation 
     102- Un cas d'utilisation == un test possible 
     103 
     104Les principes du TDD 
     105==================== 
     106 
     107Exemple:: 
    133108 
    134109    >>> def division(a, b): 
    135110    ...     return a / b 
    136111 
    137 Let's test it ! 
     112Essayons ! 
    138113:: 
    139114 
     
    142117    ...         return 'OK' 
    143118    ...     else: 
    144     ...         return 'SHUT DOWN THE COMPUTER NOW !' 
     119    ...         return 'Le processeur est moisi' 
    145120    >>> test_division() 
    146121    'OK' 
    147122 
    148 TDD Principles 
    149 ============== 
    150  
    151 Each use case tests one aspect of the code 
    152  
    153 Let's try this one:: 
     123Les principes du TDD 
     124==================== 
     125 
     126Chaque test concerne un aspect du code. 
     127 
     128En voici un autre:: 
    154129 
    155130    >>> def test_division2(): 
     
    157132    ...         return 'OK' 
    158133    ...     else: 
    159     ...         return 'I WANT ZERO' 
     134    ...         return "C'est discutable..." 
    160135    >>> test_division2() 
    161136    Traceback (most recent call last): 
     
    163138    ZeroDivisionError: integer division or modulo by zero 
    164139 
    165 TDD Principles 
    166 ============== 
    167  
    168 The function fails, let's change it:: 
     140Les principes du TDD 
     141==================== 
     142 
     143Ca plante, changeons la fonction:: 
    169144 
    170145    >>> def division(a, b): 
     
    173148    ...     return a / b 
    174149 
    175 and rerun the test:: 
     150relancons le test:: 
    176151 
    177152    >>> test_division2() 
    178153    'OK' 
    179154 
    180 TDD Principles 
    181 ============== 
    182  
    183 - The tests now validate several use cases for the function 
    184 - Running all those tests == test suite 
    185 - The function is now tighted to its test suite 
    186  
    187 TDD Principles 
    188 ============== 
    189  
    190 Let's write the tests before the code:: 
     155Les principes du TDD 
     156==================== 
     157 
     158- Plusieurs cas testés pour la fonction 
     159- Lancer l'ensemble des tests == campagne de tests == `test suite` 
     160- La fonction est `mariée` à ses tests 
     161 
     162*Je change la fonction, je revalide les tests* 
     163 
     164Les principes du TDD 
     165==================== 
     166 
     167Encore plus fort: le test est écrit `avant` le code:: 
    191168 
    192169    >>> def test_average(): 
     
    200177    NameError: global name 'average' is not defined 
    201178 
    202 TDD Principles 
    203 ============== 
    204  
    205 Now let's code `average`:: 
     179Les principes du TDD 
     180==================== 
     181 
     182Le code à présent:: 
    206183 
    207184    >>> def average(*args): 
    208185    ...     return sum(args) / len(args) 
    209186 
    210 And run the test again:: 
     187Le test à nouveau:: 
    211188 
    212189    >>> test_average() 
    213190    'OK' 
    214191 
    215 - Tests should be written *before* the code 
    216 - In the real world they are written at the same time |wink| 
    217  
    218 TDD Principles 
    219 ============== 
    220  
    221 TDD brings: 
    222  
    223 - **Quality** 
    224  
    225   - the developers naturally review their code 
    226   - refactoring is made easier 
    227  
    228 - **Non-regression**: all tests are run on every change 
    229 - **A primer documentation**: reading tests helps understanding the code 
    230  
    231 TDD Principles 
    232 ============== 
    233  
    234 Jean-Charles says: 
    235  
    236     "Tests are a waste of time, just a toy for interpreted 
    237     languages" 
    238  
    239 Bruce Eckel says: 
    240  
    241     "If it's not tested, it's broken" 
    242  
    243 Bruce's the one who's right: 
    244  
    245 - untested code does not last long 
    246 - all metrics have proven you waste way more time 
    247   debugging untested code than writing tests 
    248  
    249 Part 1 
    250 ====== 
    251  
    252 **Doing TDD in Python** 
    253  
    254 - `The TDD principles` 
    255 - **How to write tests in Python** 
    256 - `How to organise tests in a Python project` 
    257  
    258 How to write tests in Python 
    259 ============================ 
    260  
    261 Python is *battery included*. The standard library provides: 
    262  
    263 - `unittest`: a JUnit-like test framework 
    264 - `doctest`: a literate-programming-kind-of test tool 
    265  
    266 |important| There are many other test framework projects  out there 
    267  
    268 How to write tests in Python 
    269 ============================ 
    270  
    271 `unittest` provides helpers to write tests: 
    272  
    273 - a `TestCase` class, that provides assertion methods and test fixture 
    274 - a `TestSuite` class, to create a sequence of tests 
    275 - a few functions to run a *test campaign* 
    276  
    277 How to write tests in Python 
    278 ============================ 
    279  
    280 `TestCase` provides two things: 
    281  
    282 - two methods to manage the `test fixture` 
    283  
    284   - setUp: runs when the test starts 
    285   - tearDown: runs when the tests stops 
    286  
    287 - a serie of methods to make assertions: 
     192-> Les tests devraient être écrits *avant* le code 
     193 
     194-> Bien souvent ils le sont en même temps ou juste aprÚs 
     195 
     196 
     197Les principes du TDD 
     198==================== 
     199 
     200Le TDD offre: 
     201 
     202- La **Qualité** 
     203 
     204  - les développeurs révisent naturellement leur code 
     205  - les refontes de code sont plus faciles 
     206 
     207- La **non-régression**: on relance les tests à chaque modification 
     208- **Une documentation de base**: lire les tests aide à comprendre le code 
     209 
     210Les principes du TDD 
     211==================== 
     212 
     213Jean-Charles dit: 
     214 
     215    "Les tests. Quelle perte de temps. C'est juste un jouet 
     216    pour les langages interprétés" 
     217 
     218Bruce Eckel dit: 
     219 
     220    *"If it's not tested, it's broken"* 
     221 
     222Les principes du TDD 
     223==================== 
     224 
     225Bruce a raison. 
     226 
     227- Le code non-testé est voué à mourir 
     228- Toutes les mesures ont prouvé que l'on passe 
     229  plus de temps à débugguer du code non-testé qu'à écrire 
     230  les tests. 
     231- Un compilateur valide la syntaxe, pas le fonctionnement. 
     232 
     233Partie 1 
     234======== 
     235 
     236**Le TDD avec Python** 
     237 
     238- `Les principes du TDD` 
     239- **Comment écrire des tests** 
     240 
     241 
     242Comment écrire des tests 
     243======================== 
     244 
     245Python est *batteries included*. On y trouve: 
     246 
     247- `unittest`: un framework de test à la **JUnit** 
     248- `doctest`: un outil de tests à la **literate-programming-un-peu** 
     249 
     250|important| Il existe plein d'autres outils tiers de tests 
     251 
     252Comment écrire des tests 
     253======================== 
     254 
     255`unittest` fourni des outils pour l'écriture des tests: 
     256 
     257- une classe `TestCase`, pour les assertions et les `test fixture`; 
     258- une classe `TestSuite`, pour créér des séquences de tests; 
     259- quelques fonctions pour lancer des *test campaign*. 
     260 
     261Comment écrire des tests 
     262======================== 
     263 
     264`TestCase` fourni: 
     265 
     266- deux méthodes pour les `test fixture` 
     267 
     268  - setUp: au début du test 
     269  - tearDown: aprÚs le test 
     270 
     271- des méhodes pour les assertions: 
    288272 
    289273  - ``assert_`` 
     
    292276  - etc.. 
    293277 
    294 How to write tests in Python 
    295 ============================ 
    296  
    297 Writing a test case == deriving from `TestCase`:: 
     278Comment écrire des tests 
     279======================== 
     280 
     281Ecrire une suite de tests == dériver de `TestCase`:: 
    298282 
    299283    >>> import unittest 
     
    307291    ... 
    308292 
    309 Each test is a method with a `test` prefix. 
    310  
    311 How to write tests in Python 
    312 ============================ 
    313  
    314 The test can be: 
    315  
    316 - saved into a file (e.g. a module) 
    317 - added to a `test suite` (e.g. a `TestSuite` class) 
    318 - run with a default `runner` provided (e.g. the `main` function) 
    319  
    320 How to write tests in Python 
    321 ============================ 
    322  
    323 Example of test module:: 
     293Un test == une méthode préfixée de `test` 
     294 
     295Comment écrire des tests 
     296======================== 
     297 
     298Les tests peuvent être: 
     299 
     300- sauvegardés dans des fichiers (e.g. un module) 
     301- ajoutés à un `test suite` (e.g. une classe `TestSuite`) 
     302- lancés par un `runner` fourni par défaut (e.g. la fonction `main`) 
     303 
     304Comment écrire des tests 
     305======================== 
     306 
     307Exemple de module:: 
    324308 
    325309    import unittest 
     
    342326        unittest.main(defaultTest='test_suite') 
    343327 
    344 How to write tests in Python 
    345 ============================ 
    346  
    347 Running the tests with the Python interpreter:: 
    348  
     328 
     329Comment écrire des tests 
     330======================== 
     331 
     332Lancement des tests:: 
    349333 
    350334    dabox:~ tarek$ python test_division.py 
     
    355339    OK 
    356340 
    357 How to write tests in Python 
    358 ============================ 
    359  
    360 Running the tests with the Python interpreter, with a failure:: 
     341Comment écrire des tests 
     342======================== 
     343 
     344Lancement des tests, avec une erreur:: 
    361345 
    362346    dabox:~ tarek$ python test_division.py 
     
    375359    FAILED (failures=1) 
    376360 
    377 How to write tests in Python 
    378 ============================ 
    379  
     361Comment écrire des tests 
     362======================== 
    380363 
    381364.. figure:: media/magnum.jpg 
     
    387370   "Doing TDD with Python is so cool !" -- Magnum 
    388371 
    389 Part 1 
    390 ====== 
    391  
    392 **Doing TDD in Python** 
    393  
    394 - `The TDD principles` 
    395 - `How to write tests in Python` 
    396 - **How to organise tests in a Python project** 
     372Partie 1 
     373======== 
     374 
     375Pour aller plus loin: 
     376 
     377    -> Comment organiser les tests dans un projet Python 
     378 
     379 
     380La mi-temps 
     381=========== 
     382 
     383XXX mettre un truc drole 
     384 
     385Le plan 
     386======= 
     387 
     388- `Quelques définitions` 
     389- `Partie 1: le TDD avec Python` 
     390- **Part 2: les doctests** |smile| 
     391- `Part 3: le DDD` 
     392 
     393 
     394XXXXXXXXX 
     395 
     396The plan 
     397======== 
     398 
     399- `A few definitions` 
     400- `Part 1: doing TDD in Python` 
     401- **Part 2: writing documents in reST** 
     402- `Part 3: writing doctests` 
     403- `Part 4: doing DDD in Python` 
     404 
     405Part 2 
     406====== 
     407 
     408Writing documents in reST 
     409 
     410- **What is reST ?** 
     411- `reST syntax overview` 
     412- `reST tools` 
     413 
     414What is reST ? 
     415============== 
     416 
     417reSTructuredText (say reSt to be hype) is: 
     418 
     419- a plaintext markup syntax and parser system 
     420- easy to read as-is, yet powerful 
     421- the Pythonistas laTeX 
     422- see http://docutils.sf.net 
     423 
     424What is reST ? 
     425============== 
     426 
     427Example:: 
     428 
     429    ================== 
     430    I am the reST file 
     431    ================== 
     432 
     433    I am the first section 
     434    ====================== 
     435 
     436    I am the content of the first section. 
     437    I have things to say. 
     438 
     439    I am the second section 
     440    ======================= 
     441 
     442    I am, what I am, what I aammmm... 
     443 
     444What is reST ? 
     445============== 
     446 
     447Several remarks: 
     448 
     449- the reST syntax doesn't obfuscate the text 
     450- punctuation signs are used to underline section titles 
     451 
     452Part 2 
     453====== 
     454 
     455Writing documents in reST 
     456 
     457- `What is reST ?` 
     458- **reST syntax overview** 
     459- `reST tools` 
     460 
     461reST syntax overview 
     462==================== 
     463 
     464- punctuation signs to underline sections 
     465- text enhancements 
     466 
     467  - ``*emphasis*`` 
     468  - ``**strong emphasis**`` 
     469  - ```interpreted text``` 
     470  - ````inline literal text```` 
     471 
     472reST syntax overview 
     473==================== 
     474 
     475- bullet list: use +, * or - 
     476- enumerated list: use n. (1., 2., etc.) or #. (automatic) 
     477 
     478Part 2 
     479====== 
     480 
     481Writing documents in reST 
     482 
     483- `What is reST ?` 
     484- `reST syntax overview` 
     485- **reST tools** 
     486 
     487reST tools 
     488========== 
     489 
     490XXX 
     491 
     492Part 2 
     493====== 
     494 
     495Writing documents in reST 
     496 
     497- `What is reST ?` 
     498- `reST syntax overview` 
     499-  `reST tools` 
     500 
     501reST can be: 
     502 
     503- used for all documentation needs 
     504- manipulated like code (versioning, etc.) 
     505- easily transformed into various shapes 
     506 
     507Python developers |love| reST 
     508 
     509The plan 
     510======== 
     511 
     512- `A few definitions` 
     513- `Part 1: doing TDD in Python` 
     514- `Part 2: writing documents in reST` 
     515- **Part 3: writing doctests** 
     516- `Part 4: doing DDD in Python` 
    397517 
    398518How to organise tests in a Python project 
     
    447567"I now TDD in Python now" -- Neo, The Matrix 
    448568 
    449 The plan 
    450 ======== 
    451  
    452 - `A few definitions` 
    453 - `Part 1: doing TDD in Python` 
    454 - **Part 2: writing documents in reST** 
    455 - `Part 3: writing doctests` 
    456 - `Part 4: doing DDD in Python` 
    457  
    458 Part 2 
    459 ====== 
    460  
    461 Writing documents in reST 
    462  
    463 - **What is reST ?** 
    464 - `reST syntax overview` 
    465 - `reST tools` 
    466  
    467 What is reST ? 
    468 ============== 
    469  
    470 reSTructuredText (say reSt to be hype) is: 
    471  
    472 - a plaintext markup syntax and parser system 
    473 - easy to read as-is, yet powerful 
    474 - the Pythonistas laTeX 
    475 - see http://docutils.sf.net 
    476  
    477 What is reST ? 
    478 ============== 
    479  
    480 Example:: 
    481  
    482     ================== 
    483     I am the reST file 
    484     ================== 
    485  
    486     I am the first section 
    487     ====================== 
    488  
    489     I am the content of the first section. 
    490     I have things to say. 
    491  
    492     I am the second section 
    493     ======================= 
    494  
    495     I am, what I am, what I aammmm... 
    496  
    497 What is reST ? 
    498 ============== 
    499  
    500 Several remarks: 
    501  
    502 - the reST syntax doesn't obfuscate the text 
    503 - punctuation signs are used to underline section titles 
    504  
    505 Part 2 
    506 ====== 
    507  
    508 Writing documents in reST 
    509  
    510 - `What is reST ?` 
    511 - **reST syntax overview** 
    512 - `reST tools` 
    513  
    514 reST syntax overview 
    515 ==================== 
    516  
    517 - punctuation signs to underline sections 
    518 - text enhancements 
    519  
    520   - ``*emphasis*`` 
    521   - ``**strong emphasis**`` 
    522   - ```interpreted text``` 
    523   - ````inline literal text```` 
    524  
    525 reST syntax overview 
    526 ==================== 
    527  
    528 - bullet list: use +, * or - 
    529 - enumerated list: use n. (1., 2., etc.) or #. (automatic) 
    530  
    531 Part 2 
    532 ====== 
    533  
    534 Writing documents in reST 
    535  
    536 - `What is reST ?` 
    537 - `reST syntax overview` 
    538 - **reST tools** 
    539  
    540 reST tools 
    541 ========== 
    542  
    543 XXX 
    544  
    545 Part 2 
    546 ====== 
    547  
    548 Writing documents in reST 
    549  
    550 - `What is reST ?` 
    551 - `reST syntax overview` 
    552 -  `reST tools` 
    553  
    554 reST can be: 
    555  
    556 - used for all documentation needs 
    557 - manipulated like code (versioning, etc.) 
    558 - easily transformed into various shapes 
    559  
    560 Python developers |love| reST 
    561  
    562 The plan 
    563 ======== 
    564  
    565 - `A few definitions` 
    566 - `Part 1: doing TDD in Python` 
    567 - `Part 2: writing documents in reST` 
    568 - **Part 3: writing doctests** 
    569 - `Part 4: doing DDD in Python` 
    570  
    571569 
    572570.. |wink| image:: media/wink.png