Show
Ignore:
Timestamp:
06/08/07 11:04:36 (15 months ago)
Author:
Tarek Ziad?? <tarek@…>
Message:

fixed apis

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • JFP/slides.txt

    r105 r112  
    2727- Expliquer comment les tests fonctionnent en Python 
    2828- Sensibiliser les développeurs au **DDD** 
    29 - Expliquer pourquoi le **reST** et les **doctests** c'est merveilleux 
     29- Expliquer pourquoi les **doctests** c'est merveilleux 
    3030 
    3131|important| En un mot: comment développer `agile` en Python 
     
    7676 
    7777- coder (-> TDD) 
    78 - faire de la documentation (->DDD) 
     78- faire de la documentation (-> DDD) 
    7979- passer la tondeuse 
    8080- etc. 
     81 
     82Quelques définitions 
     83==================== 
     84 
     85TDD == Test-Driven Development == Développement Dirigé par les Tests 
    8186 
    8287Le plan 
     
    255260`unittest` fourni des outils pour l'écriture des tests: 
    256261 
    257 - une classe `TestCase`, pour les assertions et les `test fixture`; 
     262- une classe `TestCase`, pour les assertions et les `test fixture` 
     263  (environnement pour le test); 
    258264- une classe `TestSuite`, pour créér des séquences de tests; 
    259265- quelques fonctions pour lancer des *test campaign*. 
     
    359365    FAILED (failures=1) 
    360366 
    361 Comment écrire des tests 
    362 ======================== 
    363  
    364 .. figure:: media/magnum.jpg 
    365    :alt: "TDD with Python rocks" -- Magnum 
     367Partie 1 
     368======== 
     369 
     370Pour aller plus loin: 
     371 
     372    -> Comment organiser les tests dans un projet Python 
     373 
     374 
     375Partie 1 
     376======== 
     377 
     378Sans les tests: 
     379 
     380.. figure:: media/sleeping.jpg 
    366381   :align: center 
    367382   :height: 300 
    368    :width: 400 
    369  
    370    "Doing TDD with Python is so cool !" -- Magnum 
     383   :width: 300 
    371384 
    372385Partie 1 
    373386======== 
    374387 
    375 Pour aller plus loin: 
    376  
    377     -> Comment organiser les tests dans un projet Python 
    378  
    379  
    380 La mi-temps 
    381 =========== 
    382  
    383 XXX mettre un truc drole 
     388Avec les tests: 
     389 
     390.. figure:: media/happy_1.jpg 
     391   :align: center 
     392   :height: 300 
     393   :width: 300 
     394 
     395Partie 1 
     396======== 
     397 
     398Avec les tests: 
     399 
     400.. figure:: media/happy_2.gif 
     401   :align: center 
     402   :height: 300 
     403   :width: 200 
    384404 
    385405Le plan 
     
    388408- `Quelques définitions` 
    389409- `Partie 1: le TDD avec Python` 
    390 - **Part 2: les doctests** |smile| 
    391 - `Part 3: le DDD` 
    392  
    393  
    394 XXXXXXXXX 
    395  
    396 The 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  
    405 Part 2 
    406 ====== 
    407  
    408 Writing documents in reST 
    409  
    410 - **What is reST ?** 
    411 - `reST syntax overview` 
    412 - `reST tools` 
    413  
    414 What is reST ? 
    415 ============== 
    416  
    417 reSTructuredText (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  
    424 What is reST ? 
    425 ============== 
    426  
    427 Example:: 
    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  
    444 What is reST ? 
    445 ============== 
    446  
    447 Several remarks: 
    448  
    449 - the reST syntax doesn't obfuscate the text 
    450 - punctuation signs are used to underline section titles 
    451  
    452 Part 2 
    453 ====== 
    454  
    455 Writing documents in reST 
    456  
    457 - `What is reST ?` 
    458 - **reST syntax overview** 
    459 - `reST tools` 
    460  
    461 reST 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  
    472 reST syntax overview 
    473 ==================== 
    474  
    475 - bullet list: use +, * or - 
    476 - enumerated list: use n. (1., 2., etc.) or #. (automatic) 
    477  
    478 Part 2 
    479 ====== 
    480  
    481 Writing documents in reST 
    482  
    483 - `What is reST ?` 
    484 - `reST syntax overview` 
    485 - **reST tools** 
    486  
    487 reST tools 
     410- **Partie 2: les doctests** |smile| 
     411- `Partie 3: le DDD` 
     412 
     413Partie 2 
     414======== 
     415 
     416Les `doctests` 
     417 
     418- basés sur le principe du `literate programming` (KNUTH) 
     419- utilise le prompt Python 
     420 
     421Les doctests 
     422============ 
     423 
     424Exemple de doctest `inline`:: 
     425 
     426    def somme(a, b): 
     427        """ calcul la somme 
     428 
     429        >>> somme(1, 3) 
     430        4 
     431        >>> somme(2, 2) 
     432        4 
     433        """ 
     434        return a + b 
     435 
     436 
     437Les doctests 
     438============ 
     439 
     440|smile| Les exemples sont directement disponibles 
     441 
     442|sad| Le code devient dur à lire 
     443 
     444Les doctests 
     445============ 
     446 
     447Solution: séparer les doctests dans un fichier texte 
     448 
     449- chaque module de code peut avoir son module de doctest 
     450- un script `execute` ces modules de tests 
     451 
     452Les doctests 
     453============ 
     454 
     455Exemple de doctest séparé. Fichier *calc.py*:: 
     456 
     457    def somme(a, b): 
     458        """ calcul la somme 
     459        """ 
     460        return a + b 
     461 
     462Fichier *calc.txt*:: 
     463 
     464    >>> from calc import somme 
     465    >>> somme(1, 3) 
     466    4 
     467    >>> somme(2, 2) 
     468    4 
     469 
     470Les doctests 
     471============ 
     472 
     473Un fichier doctest devient un test unitaire grâce au module `doctest`:: 
     474 
     475    import doctest 
     476    import unittest 
     477 
     478    def test_suite(): 
     479        suite.append(doctest.DocFileTest('calc.txt')) 
     480        return unittest.TestSuite(suite) 
     481 
     482    if __name__ == '__main__': 
     483        unittest.main(defaultTest='test_suite') 
     484 
     485Les doctests 
     486============ 
     487 
     488doctests + tests classiques == campagne de test 
     489 
     490Le plan 
     491======= 
     492 
     493- `Quelques définitions` 
     494- `Partie 1: le TDD avec Python` 
     495- `Partie 2: les doctests` 
     496- **Partie 3: le DDD** |smile| 
     497 
     498Partie 3 
     499======== 
     500 
     501Le Document-Driven Development 
     502 
     503Principe: 
     504 
     505    Les doctests séparés peuvent `aussi` être des documents 
     506 
     507Documentation 
     508============= 
     509 
     510Chaque doctest == alternance de code et d'explications:: 
     511 
     512    Module calc 
     513 
     514    Le module calc contient une fonction pour faire des sommes: 
     515 
     516        >>> from calc import somme 
     517 
     518    Cette fonction prends deux paramÚtres: 
     519 
     520        >>> somme(1, 3) 
     521        4 
     522        >>> somme(2, 2) 
     523        4 
     524 
     525Documentation 
     526============= 
     527 
     528|smile| Promiscuité de la documentation 
     529 
     530|smile| La documentation évolue en même temps que le code 
     531 
     532|smile| Le développeur utilise la doc. pour concevoir les tests 
     533 
     534|smile| La documentation du projet est conçue en partie par ce biais 
     535 
     536Documentation 
     537============= 
     538 
     539|important| Un doctest doit rester un document: ne pas le noyer dans des 
     540`test fixtures` (mise en place pour les tests) 
     541 
     542|important| Les doctests montrent des exemples **publics** de code 
     543 
     544|important| Les tests unitaires classiques s'occupent du reste 
     545 
     546Documentation 
     547============= 
     548 
     549-> Demo: construction d'un module de calcul 
     550 
     551 
     552Documentation 
     553============= 
     554 
     555Pour aller plus loin: 
     556 
     557-> utilisation du reSTructuredText dans les documents 
     558 
     559 
     560Conclusion 
    488561========== 
    489562 
    490 XXX 
    491  
    492 Part 2 
    493 ====== 
    494  
    495 Writing documents in reST 
    496  
    497 - `What is reST ?` 
    498 - `reST syntax overview` 
    499 -  `reST tools` 
    500  
    501 reST can be: 
    502  
    503 - used for all documentation needs 
    504 - manipulated like code (versioning, etc.) 
    505 - easily transformed into various shapes 
    506  
    507 Python developers |love| reST 
    508  
    509 The 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` 
    517  
    518 How to organise tests in a Python project 
    519 ========================================= 
    520  
    521 By the way, how Python code is organized ? 
    522  
    523 - a package == a folder with files 
    524 - a module == a file with classes, functions and variables 
    525  
    526 Each package comes with 
    527  
    528 - a `doc` subfolder 
    529 - a `tests` subfolder <--- let's put our unit tests here |wink| 
    530  
    531 Following the TDD principles: 
    532  
    533 - one code module <==> one test module 
    534  
    535 How to organise tests in a Python project 
    536 ========================================= 
    537  
    538 Our division package will look like this:: 
    539  
    540     division 
    541        | 
    542        |-- division.py 
    543        | 
    544        |-- tests 
    545        |     | 
    546        |     |-- test_division.py 
    547        | 
    548        |--  doc 
    549              | 
    550              |-- division.txt <-- some cool doc 
    551  
    552 Part 1 
    553 ====== 
    554  
    555 `Doing TDD in Python` 
    556  
    557 - `The TDD principles` 
    558 - `How to write tests in Python` 
    559 - `How to organise tests in a Python project` 
    560  
    561  
    562 Part 1 
    563 ====== 
    564  
    565 Mettre une photo de matrix 
    566  
    567 "I now TDD in Python now" -- Neo, The Matrix 
     563Questions ? 
     564 
     565Ressources 
     566========== 
     567 
     568- http://docs.python.org (doctest et unittest) 
     569- http://programmation-python.org 
     570 
     571Ressources 
     572========== 
     573 
     574Sortie le 16 aout: 
     575 
     576.. figure:: media/guide.png 
     577   :align: center 
     578   :height: 300 
     579   :width: 200 
    568580 
    569581