17.12.2012 Views

Programmation PYTHON - Zenk - Security - Repository

Programmation PYTHON - Zenk - Security - Repository

Programmation PYTHON - Zenk - Security - Repository

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Programmation</strong> dirigée par les tests<br />

CHAPITRE 12<br />

la ligne qui contient le type d’erreur, en ne conservant que ce type.<br />

Exception détail<br />

def error():<br />

"""<br />

>>> error() #doctest: +IGNORE_EXCEPTION_DETAIL<br />

Traceback (most recent call last):<br />

ZeroDivisionError: xx<br />

"""<br />

return 3 / 0<br />

REPORT_NDIFF<br />

Si ce flag est fourni au lancement des tests, les différences entre le retour et le résultat<br />

attendu sont affichées sous forme de différences, suivant le format renvoyé par le<br />

module difflib, qui fournit un algorithme de comparaison intra-ligne.<br />

Hortograffe<br />

def test_orthographe():<br />

"""<br />

>>> test_orthographe()<br />

L'orthographe de ce texte est valide.<br />

"""<br />

return "L'horthografe de ce tecste est validde."<br />

if __name__ == "__main__":<br />

flags = doctest.REPORT_NDIFF<br />

doctest.testmod(optionflags=flags)<br />

[...]<br />

[tziade@Tarek tests]$ python test_doctests.py<br />

**********************************************************************<br />

File "test_doctests.py", line 7, in __main__.test_orthographe<br />

Failed example:<br />

test_orthographe()<br />

Differences (ndiff with -expected +actual):<br />

- L'orthographe de ce texte est valide.<br />

? ^^ ^<br />

+ "L'horthografe de ce tecste est validde."<br />

? + + ^ ^^ + +<br />

**********************************************************************<br />

1 items had failures:<br />

1 of 1 in __main__.test_orthographe<br />

***Test Failed*** 1 failures.<br />

417

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!