17.12.2012 Views

Programmation PYTHON - Zenk - Security - Repository

Programmation PYTHON - Zenk - Security - Repository

Programmation PYTHON - Zenk - Security - Repository

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

CHAPITRE 12<br />

concocte un fichier d’extension .cover, similaire au code exécuté, mais avec des<br />

informations ajoutées à chaque début de ligne.<br />

Exemple d’utilisation de trace<br />

#!/usr/bin/python<br />

# -*- coding: utf8 -*import<br />

trace<br />

import sys<br />

def methode2(x):<br />

if x % 2:<br />

return 'o'<br />

if x == 123:<br />

return 'O'<br />

return 'x'<br />

def methode():<br />

c = ''<br />

for i in range(100):<br />

c = c + methode2(i)<br />

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

traced = trace.Trace(ignoredirs=[sys.prefix,<br />

sys.exec_prefix,], trace=0,<br />

count=1)<br />

traced.run('methode()')<br />

[...]<br />

r = traced.results()<br />

r.write_results(show_missing=True)<br />

results = open('tracer.cover', 'r')<br />

print(''.join(results.readlines()))<br />

results.close()<br />

[tziade@Tarek Desktop]$ python tracer.py<br />

#!/usr/bin/python<br />

# -*- coding: utf8 -*import<br />

trace<br />

>>>>>> import sys<br />

>>>>>> def methode2(x):<br />

100: if x % 2:<br />

50: return 'o'<br />

50: if x == 123:<br />

>>>>>> return 'O'<br />

50: return 'x'<br />

425

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

Saved successfully!

Ooh no, something went wrong!