| 698 | | <div class="slide" id="the-plan"> |
| 699 | | <h1>The plan</h1> |
| 700 | | <ul class="simple"> |
| 701 | | <li><cite>A few definitions</cite></li> |
| 702 | | <li><cite>Part 1: doing TDD in Python</cite></li> |
| 703 | | <li><strong>Part 2: writing documents in reST</strong></li> |
| 704 | | <li><cite>Part 3: writing doctests</cite></li> |
| 705 | | <li><cite>Part 4: doing DDD in Python</cite></li> |
| 706 | | </ul> |
| 707 | | </div> |
| 708 | | <div class="slide" id="part-2"> |
| 709 | | <h1>Part 2</h1> |
| 710 | | <p>Writing documents in reST</p> |
| 711 | | <ul class="simple"> |
| 712 | | <li><strong>What is reST ?</strong></li> |
| 713 | | <li><cite>reST syntax overview</cite></li> |
| 714 | | <li><cite>reST tools</cite></li> |
| 715 | | </ul> |
| 716 | | </div> |
| 717 | | <div class="slide" id="what-is-rest"> |
| 718 | | <h1>What is reST ?</h1> |
| 719 | | <p>reSTructuredText (say reSt to be hype) is:</p> |
| 720 | | <ul class="simple"> |
| 721 | | <li>a plaintext markup syntax and parser system</li> |
| 722 | | <li>easy to read as-is, yet powerful</li> |
| 723 | | <li>the Pythonistas laTeX</li> |
| 724 | | <li>see <a class="reference" href="http://docutils.sf.net">http://docutils.sf.net</a></li> |
| 725 | | </ul> |
| 726 | | </div> |
| 756 | | <h1>Part 2</h1> |
| 757 | | <p>Writing documents in reST</p> |
| 758 | | <ul class="simple"> |
| 759 | | <li><cite>What is reST ?</cite></li> |
| 760 | | <li><strong>reST syntax overview</strong></li> |
| 761 | | <li><cite>reST tools</cite></li> |
| 762 | | </ul> |
| 763 | | </div> |
| 764 | | <div class="slide" id="rest-syntax-overview"> |
| 765 | | <h1>reST syntax overview</h1> |
| 766 | | <ul class="simple"> |
| 767 | | <li>punctuation signs to underline sections</li> |
| 768 | | <li>text enhancements<ul> |
| 769 | | <li><tt class="docutils literal"><span class="pre">*emphasis*</span></tt></li> |
| 770 | | <li><tt class="docutils literal"><span class="pre">**strong</span> <span class="pre">emphasis**</span></tt></li> |
| 771 | | <li><tt class="docutils literal"><span class="pre">`interpreted</span> <span class="pre">text`</span></tt></li> |
| 772 | | <li><tt class="docutils literal"><span class="pre">``inline</span> <span class="pre">literal</span> <span class="pre">text``</span></tt></li> |
| 773 | | </ul> |
| 774 | | </li> |
| 775 | | </ul> |
| | 709 | <h1>Partie 1</h1> |
| | 710 | <p>Avec les tests:</p> |
| | 711 | <div align="center" class="figure"> |
| | 712 | <img alt="media/happy_2.gif" src="media/happy_2.gif" style="width: 200px; height: 300px;" /> |
| | 713 | </div> |
| 778 | | <h1>reST syntax overview</h1> |
| 779 | | <ul class="simple"> |
| 780 | | <li>bullet list: use +, * or -</li> |
| 781 | | <li>enumerated list: use n. (1., 2., etc.) or #. (automatic)</li> |
| 782 | | </ul> |
| | 716 | <h1>Le plan</h1> |
| | 717 | <ul class="simple"> |
| | 718 | <li><cite>Quelques définitions</cite></li> |
| | 719 | <li><cite>Partie 1: le TDD avec Python</cite></li> |
| | 720 | <li><strong>Partie 2: les doctests</strong> <img alt="smile" src="media/smile.png" /></li> |
| | 721 | <li><cite>Partie 3: le DDD</cite></li> |
| | 722 | </ul> |
| | 723 | </div> |
| | 724 | <div class="slide" id="partie-2"> |
| | 725 | <h1>Partie 2</h1> |
| | 726 | <p>Les <cite>doctests</cite></p> |
| | 727 | <ul class="simple"> |
| | 728 | <li>basés sur le principe du <cite>literate programming</cite> (KNUTH)</li> |
| | 729 | <li>utilise le prompt Python</li> |
| | 730 | </ul> |
| | 731 | </div> |
| | 732 | <div class="slide" id="les-doctests"> |
| | 733 | <h1>Les doctests</h1> |
| | 734 | <p>Exemple de doctest <cite>inline</cite>:</p> |
| | 735 | <pre class="literal-block"> |
| | 736 | def somme(a, b): |
| | 737 | """ calcul la somme |
| | 738 | |
| | 739 | >>> somme(1, 3) |
| | 740 | 4 |
| | 741 | >>> somme(2, 2) |
| | 742 | 4 |
| | 743 | """ |
| | 744 | return a + b |
| | 745 | </pre> |
| 798 | | <h1>Part 2</h1> |
| 799 | | <p>Writing documents in reST</p> |
| 800 | | <ul class="simple"> |
| 801 | | <li><cite>What is reST ?</cite></li> |
| 802 | | <li><cite>reST syntax overview</cite></li> |
| 803 | | <li><cite>reST tools</cite></li> |
| 804 | | </ul> |
| 805 | | <p>reST can be:</p> |
| 806 | | <ul class="simple"> |
| 807 | | <li>used for all documentation needs</li> |
| 808 | | <li>manipulated like code (versioning, etc.)</li> |
| 809 | | <li>easily transformed into various shapes</li> |
| 810 | | </ul> |
| 811 | | <p>Python developers <img alt="love" src="media/love.png" /> reST</p> |
| | 753 | <h1>Les doctests</h1> |
| | 754 | <p>Solution: séparer les doctests dans un fichier texte</p> |
| | 755 | <ul class="simple"> |
| | 756 | <li>chaque module de code peut avoir son module de doctest</li> |
| | 757 | <li>un script <cite>execute</cite> ces modules de tests</li> |
| | 758 | </ul> |
| 814 | | <h1>The plan</h1> |
| 815 | | <ul class="simple"> |
| 816 | | <li><cite>A few definitions</cite></li> |
| 817 | | <li><cite>Part 1: doing TDD in Python</cite></li> |
| 818 | | <li><cite>Part 2: writing documents in reST</cite></li> |
| 819 | | <li><strong>Part 3: writing doctests</strong></li> |
| 820 | | <li><cite>Part 4: doing DDD in Python</cite></li> |
| 821 | | </ul> |
| 822 | | </div> |
| 823 | | <div class="slide" id="how-to-organise-tests-in-a-python-project"> |
| 824 | | <h1>How to organise tests in a Python project</h1> |
| 825 | | <p>By the way, how Python code is organized ?</p> |
| 826 | | <ul class="simple"> |
| 827 | | <li>a package == a folder with files</li> |
| 828 | | <li>a module == a file with classes, functions and variables</li> |
| 829 | | </ul> |
| 830 | | <p>Each package comes with</p> |
| 831 | | <ul class="simple"> |
| 832 | | <li>a <cite>doc</cite> subfolder</li> |
| 833 | | <li>a <cite>tests</cite> subfolder <--- let's put our unit tests here <img alt="wink" src="media/wink.png" /></li> |
| 834 | | </ul> |
| 835 | | <p>Following the TDD principles:</p> |
| 836 | | <ul class="simple"> |
| 837 | | <li>one code module <==> one test module</li> |
| 838 | | </ul> |
| | 761 | <h1>Les doctests</h1> |
| | 762 | <p>Exemple de doctest séparé. Fichier <em>calc.py</em>:</p> |
| | 763 | <pre class="literal-block"> |
| | 764 | def somme(a, b): |
| | 765 | """ calcul la somme |
| | 766 | """ |
| | 767 | return a + b |
| | 768 | </pre> |
| | 769 | <p>Fichier <em>calc.txt</em>:</p> |
| | 770 | <pre class="literal-block"> |
| | 771 | >>> from calc import somme |
| | 772 | >>> somme(1, 3) |
| | 773 | 4 |
| | 774 | >>> somme(2, 2) |
| | 775 | 4 |
| | 776 | </pre> |
| 841 | | <h1>How to organise tests in a Python project</h1> |
| 842 | | <p>Our division package will look like this:</p> |
| 843 | | <pre class="literal-block"> |
| 844 | | division |
| 845 | | | |
| 846 | | |-- division.py |
| 847 | | | |
| 848 | | |-- tests |
| 849 | | | | |
| 850 | | | |-- test_division.py |
| 851 | | | |
| 852 | | |-- doc |
| 853 | | | |
| 854 | | |-- division.txt <-- some cool doc |
| 855 | | </pre> |
| 856 | | </div> |
| 857 | | <div class="slide" id="part-1"> |
| 858 | | <h1>Part 1</h1> |
| 859 | | <p><cite>Doing TDD in Python</cite></p> |
| 860 | | <ul class="simple"> |
| 861 | | <li><cite>The TDD principles</cite></li> |
| 862 | | <li><cite>How to write tests in Python</cite></li> |
| 863 | | <li><cite>How to organise tests in a Python project</cite></li> |
| 864 | | </ul> |
| | 779 | <h1>Les doctests</h1> |
| | 780 | <p>Un fichier doctest devient un test unitaire grâce au module <cite>doctest</cite>:</p> |
| | 781 | <pre class="literal-block"> |
| | 782 | import doctest |
| | 783 | import unittest |
| | 784 | |
| | 785 | def test_suite(): |
| | 786 | suite.append(doctest.DocFileTest('calc.txt')) |
| | 787 | return unittest.TestSuite(suite) |
| | 788 | |
| | 789 | if __name__ == '__main__': |
| | 790 | unittest.main(defaultTest='test_suite') |
| | 791 | </pre> |
| 867 | | <h1>Part 1</h1> |
| 868 | | <p>Mettre une photo de matrix</p> |
| 869 | | <p>"I now TDD in Python now" -- Neo, The Matrix</p> |
| | 794 | <h1>Les doctests</h1> |
| | 795 | <p>doctests + tests classiques == campagne de test</p> |
| | 796 | </div> |
| | 797 | <div class="slide" id="id35"> |
| | 798 | <h1>Le plan</h1> |
| | 799 | <ul class="simple"> |
| | 800 | <li><cite>Quelques définitions</cite></li> |
| | 801 | <li><cite>Partie 1: le TDD avec Python</cite></li> |
| | 802 | <li><cite>Partie 2: les doctests</cite></li> |
| | 803 | <li><strong>Partie 3: le DDD</strong> <img alt="smile" src="media/smile.png" /></li> |
| | 804 | </ul> |
| | 805 | </div> |
| | 806 | <div class="slide" id="partie-3"> |
| | 807 | <h1>Partie 3</h1> |
| | 808 | <p>Le Document-Driven Development</p> |
| | 809 | <p>Principe:</p> |
| | 810 | <blockquote> |
| | 811 | Les doctests séparés peuvent <cite>aussi</cite> être des documents</blockquote> |
| | 812 | </div> |
| | 813 | <div class="slide" id="documentation"> |
| | 814 | <h1>Documentation</h1> |
| | 815 | <p>Chaque doctest == alternance de code et d'explications:</p> |
| | 816 | <pre class="literal-block"> |
| | 817 | Module calc |
| | 818 | |
| | 819 | Le module calc contient une fonction pour faire des sommes: |
| | 820 | |
| | 821 | >>> from calc import somme |
| | 822 | |
| | 823 | Cette fonction prends deux paramÚtres: |
| | 824 | |
| | 825 | >>> somme(1, 3) |
| | 826 | 4 |
| | 827 | >>> somme(2, 2) |
| | 828 | 4 |
| | 829 | </pre> |
| | 830 | </div> |
| | 831 | <div class="slide" id="id36"> |
| | 832 | <h1>Documentation</h1> |
| | 833 | <p><img alt="smile" src="media/smile.png" /> Promiscuité de la documentation</p> |
| | 834 | <p><img alt="smile" src="media/smile.png" /> La documentation évolue en même temps que le code</p> |
| | 835 | <p><img alt="smile" src="media/smile.png" /> Le développeur utilise la doc. pour concevoir les tests</p> |
| | 836 | <p><img alt="smile" src="media/smile.png" /> La documentation du projet est conçue en partie par ce biais</p> |
| | 837 | </div> |
| | 838 | <div class="slide" id="id37"> |
| | 839 | <h1>Documentation</h1> |
| | 840 | <p><img alt="important" src="media/important.png" /> Un doctest doit rester un document: ne pas le noyer dans des |
| | 841 | <cite>test fixtures</cite> (mise en place pour les tests)</p> |
| | 842 | <p><img alt="important" src="media/important.png" /> Les doctests montrent des exemples <strong>publics</strong> de code</p> |
| | 843 | <p><img alt="important" src="media/important.png" /> Les tests unitaires classiques s'occupent du reste</p> |
| | 844 | </div> |
| | 845 | <div class="slide" id="id38"> |
| | 846 | <h1>Documentation</h1> |
| | 847 | <p>-> Demo: construction d'un module de calcul</p> |
| | 848 | </div> |
| | 849 | <div class="slide" id="id39"> |
| | 850 | <h1>Documentation</h1> |
| | 851 | <p>Pour aller plus loin:</p> |
| | 852 | <p>-> utilisation du reSTructuredText dans les documents</p> |
| | 853 | </div> |
| | 854 | <div class="slide" id="conclusion"> |
| | 855 | <h1>Conclusion</h1> |
| | 856 | <p>Questions ?</p> |
| | 857 | </div> |
| | 858 | <div class="slide" id="ressources"> |
| | 859 | <h1>Ressources</h1> |
| | 860 | <ul class="simple"> |
| | 861 | <li><a class="reference" href="http://docs.python.org">http://docs.python.org</a> (doctest et unittest)</li> |
| | 862 | <li><a class="reference" href="http://programmation-python.org">http://programmation-python.org</a></li> |
| | 863 | </ul> |
| | 864 | </div> |
| | 865 | <div class="slide" id="id40"> |
| | 866 | <h1>Ressources</h1> |
| | 867 | <p>Sortie le 16 aout:</p> |
| | 868 | <div align="center" class="figure"> |
| | 869 | <img alt="media/guide.png" src="media/guide.png" style="width: 200px; height: 300px;" /> |
| | 870 | </div> |