| 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 |
| | 13 | Qui 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 | |
| | 21 | Pourquoi cette présentation? |
| | 22 | ============================ |
| | 23 | |
| | 24 | Objectifs: |
| | 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 | |
| | 33 | Pourquoi cette présentation? |
| | 34 | ============================ |
| | 35 | |
| | 36 | Objectifs 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 | |
| | 43 | Le 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 | |
| | 51 | Quelques définitions |
| | 52 | ==================== |
| | 53 | |
| | 54 | Que veux dire le mot **agile** ? |
| | 55 | |
| | 56 | Quelques définitions |
| | 57 | ==================== |
| | 58 | |
| | 59 | Tentative de définition appliqué au développement: |
| | 60 | |
| | 61 | **C'est une méthodologie de programmation qui permet de |
| | 62 | rester réactif aux fréquentes modifications d'une base |
| | 63 | de code** |
| | 64 | |
| | 65 | Viens 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 | |
| | 72 | Quelques définitions |
| | 73 | ==================== |
| | 74 | |
| | 75 | Les 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 | |
| | 82 | Le 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 | |
| | 90 | Partie 1 |
| 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 | |
| | 98 | Les principes du TDD |
| | 99 | ==================== |
| | 100 | |
| | 101 | - Chaque fonction == un ou plusieurs cas d'utilisation |
| | 102 | - Un cas d'utilisation == un test possible |
| | 103 | |
| | 104 | Les principes du TDD |
| | 105 | ==================== |
| | 106 | |
| | 107 | Exemple:: |
| 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 | |
| | 197 | Les principes du TDD |
| | 198 | ==================== |
| | 199 | |
| | 200 | Le 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 | |
| | 210 | Les principes du TDD |
| | 211 | ==================== |
| | 212 | |
| | 213 | Jean-Charles dit: |
| | 214 | |
| | 215 | "Les tests. Quelle perte de temps. C'est juste un jouet |
| | 216 | pour les langages interprétés" |
| | 217 | |
| | 218 | Bruce Eckel dit: |
| | 219 | |
| | 220 | *"If it's not tested, it's broken"* |
| | 221 | |
| | 222 | Les principes du TDD |
| | 223 | ==================== |
| | 224 | |
| | 225 | Bruce 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 | |
| | 233 | Partie 1 |
| | 234 | ======== |
| | 235 | |
| | 236 | **Le TDD avec Python** |
| | 237 | |
| | 238 | - `Les principes du TDD` |
| | 239 | - **Comment écrire des tests** |
| | 240 | |
| | 241 | |
| | 242 | Comment écrire des tests |
| | 243 | ======================== |
| | 244 | |
| | 245 | Python 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 | |
| | 252 | Comment é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 | |
| | 261 | Comment é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: |
| 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:: |
| | 293 | Un test == une méthode préfixée de `test` |
| | 294 | |
| | 295 | Comment écrire des tests |
| | 296 | ======================== |
| | 297 | |
| | 298 | Les 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 | |
| | 304 | Comment écrire des tests |
| | 305 | ======================== |
| | 306 | |
| | 307 | Exemple de module:: |
| 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** |
| | 372 | Partie 1 |
| | 373 | ======== |
| | 374 | |
| | 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 |
| | 384 | |
| | 385 | Le 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 | |
| | 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 |
| | 488 | ========== |
| | 489 | |
| | 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` |
| 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 | | |