Agile development. Agile development work cycle. Reacting to bugs

Similar documents
From theory to practice: Standard tools Software carpentry, Part II. Pietro Berkes, Brandeis University

Software Carpentry. Nicola Chiapolini. Physik-Institut University of Zurich. June 16, 2015

Software carpentry From theory to practice: Standard tools. Pietro Berkes, Enthought UK

Software carpentry From theory to practice: Python tools. Pietro Berkes, Enthought UK

Introduction to Problem Solving and Programming in Python.

Tools to efficiently build scientific code Mostly testing, some profiling, a little debugging. Pietro Berkes, Twitter #aspp2016

Practical Unit Testing junit. Atul Prakash

Representing Documents; Unit Testing II

Testing My Patience. Automated Testing for Python Projects. Adam Lowry Portland Python Users Group

CS Programming Languages: Python

CSE : Python Programming. Packages (Tutorial, Section 6.4) Announcements. Today. Packages: Concretely. Packages: Overview

Testing and Debugging C Programming and Software Tools. N.C. State Department of Computer Science

CSCA08 Winter Week 12: Exceptions & Testing. Marzieh Ahmadzadeh, Brian Harrington University of Toronto Scarborough

Lotus IT Hub. Module-1: Python Foundation (Mandatory)

COMP1730/COMP6730 Programming for Scientists. Testing and Debugging.

Making Programs Fail. Andreas Zeller

pytest-benchmark Release 2.5.0

Instrumental Documentation

Binghamton University. CS-140 Fall Unit Testing

Programming in Python Advanced

Binghamton University. CS-140 Fall Unit Testing

Unit 2: Python extras

Unit Testing In Python

Slides from INF3331 lectures optimizing Python code

Python INTRODUCTION: Understanding the Open source Installation of python in Linux/windows. Understanding Interpreters * ipython.

Lecture 27. Lecture 27: Regular Expressions and Python Identifiers

Assignment 5: Testing and Debugging

Computational Mathematics with Python

Specter Documentation

The WSGI Reference Library

Flow Control: Branches and loops

CIS192 Python Programming

Test-Driven Data Science: Writing Unit Tests for SASPy Python Data Processes

Python Utils Documentation

Bug Hunting For Dummies

CS2: Debugging in Java

Anders Fröberg TDDD80 STORAGE AND TESTING

Python. ECE 650 Methods & Tools for Software Engineering (MTSE) Fall Prof. Arie Gurfinkel

pytest Documentation Release 3.1 holger krekel, trainer and consultant,

Day 6: 24/May/2012. TDD (Test Driven Development)

flake8 Documentation Release Tarek Ziade

Unit Tests. # Store the result of a boolean expression in a variable. >>> result = str(5)=='5'

HotPy (2) Binary Compatible High Performance VM for Python. Mark Shannon

About Python. Python Duration. Training Objectives. Training Pre - Requisites & Who Should Learn Python

Ensure Documentation. Release Andrey Kislyuk

Decorators in Python

Object Oriented Software Design - I

pvextractor Documentation

Downloaded from Chapter 2. Functions

Introduction to Computer Programming for Non-Majors

doubles Documentation

Lecture 9: GUI and debugging

CS150 - Sample Final

Spyder Documentation. Release 3. Pierre Raybaut

Lecture Writing Programs. Richard E Sarkis CSC 161: The Art of Programming

EECS 4313 Software Engineering Testing

print statements, debugger expressions, test scripts. Writing expressions in a debugger only that t a program works now. An application typically

Python Utils Documentation

Getting Started with Python

Sage Reference Manual: Python technicalities

CS150 Sample Final. Name: Section: A / B

Django Test Utils Documentation

funcsigs Documentation

An Introduction to Komodo

Software testing A.A. 2018/2019

Where is the bottleneck. Manuel Miranda Software Engineer

PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital

Programming in Python 3

Macro #clojureconj

Introduction to Python programming, II

DECOMPOSITION, ABSTRACTION, FUNCTIONS

Tuesday, November 15. Testing

Overview.

Table of Contents EVALUATION COPY

COMP519 Web Programming Lecture 20: Python (Part 4) Handouts

doit Documentation Release

Enterprise Architect. User Guide Series. Profiling

Enterprise Architect. User Guide Series. Profiling. Author: Sparx Systems. Date: 10/05/2018. Version: 1.0 CREATED WITH

Flask-Testing Documentation

dicompyler-core Documentation

Fundamentals of Programming (Python) Getting Started with Programming

Testing. Topics. Types of Testing. Types of Testing

Java Programming. Atul Prakash

Topic 16: Validation. CITS3403 Agile Web Development. Express, Angular and Node, Chapter 11

Keil uvision development story (Adapted from (Valvano, 2014a))

pytest Documentation Release 3.2 holger krekel, trainer and consultant,

Python Unit Testing and CI Workflow. Tim Scott, Python Meetup 11/07/17

Debug for GDB Users. Action Description Debug GDB $debug <program> <args> >create <program> <args>

Python Programming: An Introduction to Computer Science

LuaUnit Documentation

SECTION 5: STRUCTURED PROGRAMMING IN MATLAB. ENGR 112 Introduction to Engineering Computing

A Tutorial for ECE 175

Data Science with Python Course Catalog

CIS192 Python Programming

TestCenter Manual. TestCenter Manual Copyright MeVis Medical Solutions, Published

django-idioticon Documentation

UNIT IV -MACROPROCESSOR

Review. Input, Processing and Output. Review. Review. Designing a Program. Typical Software Development cycle. Bonita Sharif

Introducing a new tool set. Sean Patrick Santos. 19th Annual CESM Workshop, 2014

Software Engineering Chair November 26, 2008

Transcription:

Agile development Agile development work cycle Repeat until all features are implemented: 1. Write a test that defines your next feature 2. Write the simplest version of code that makes your test 3. Run the tests and debug until all tests 4. Refactor (remove duplication, reorganize the code) 5. Go back to 3 until necessary If speed or memory are an issue: 6. Optimize only at this point 7. Go back to 3 until necessary Reacting to bugs 1. Use debugger to isolate bug 2. Write test case that reproduces bug 3. Correct the bug 4. Check that all tests

Software carpentry tools pyflakes Static analysis of Python code pyflakes path pep8 Static analysis of Python code pep8 path Analyze all the Python files in path and subdirectories, checking for errors. The module is not executed, don t worry about side effects. Analyze all the Python files in path and subdirectories, reporting the parts of the code that do not comply with the Python style standard, PEP8. pydoc Generate documentation pages from Python docstrings pydoc module_name pydoc w module_name pydoc g coverage.py Code coverage for testing text output html output open graphical interface Execute my_program.py with arguments arg1 and arg2 with plain coverage analysis: coverage run my_program.py arg1 arg2 With branch coverage analysis: coverage run --branch my_program.py arg1 arg2 Coverage information is saved in a file called.coverage, or as specified in the environment variable COVERAGE_FILE. Print coverage report (-m show the lines that were not executed): coverage report m Generate HTML coverage report: coverage html d html_directory Remove coverage information: coverage erase Generate annotated version of source code: coverage annotate Legend: > executed! missing (not executed) - excluded doctest Test code in docstrings From the command line: python -m doctest v filename.ext From interactive shell / code: import doctest doctest.testfile("example.txt ) # test examples in a file doctest.testmod([module]) # test docstrings in module

unittest Basic structure of a test suite import unittest class FirstTestCase(unittest.TestCase): def setup(self): """setup is called before every test""" def teardown(self): """teardown is called at the end of every test""" @classmethod def setupclass(self): """Called once before all tests in this class. [Python 2.7]""" define if necessary to create fixtures @classmethod def teardownclass(self): """Called once after all tests in this class. [Python 2.7]""" def test_truisms(self): """All methods beginning with test are executed""" self.asserttrue(true) self.assertfalse(false) #... more tests here... class SecondTestCase(unittest.TestCase): def test_approximation(self): self.assertalmostequal(1.1, 1.15, 1) if name == ' main ': # run all TestCase's in this module unittest.main()

Assert methods in unittest.testcase Most assert methods accept an optional msg argument, which is printed in case the assertion fails to facilitate debugging. A complete list of all available assert methods is available at http://tinyurl.com/cmohfrc. Most methods also have a negated counterpart, e.g. assertequal and assertnotequal. assert_(expr[, msg) asserttrue(expr[, msg]) assertfalse(expr[, msg]) assertequal(first, second[, msg]) assertalmostequal(first, second [, places[, msg]]) assertraises(exception, callable,...) assertregexpmatches(text, regexp) assertgreater(a, b) assertless(a, b) Fail if expr is False Fail if expr is True Fail if first is not equal to second Fail if first is equal to second up to the decimal place indicated by places (default: 7) Fail if the function callable does not raise an exception of class exception. If additional positional or keyword arguments are given, they are ed to callable. Fail if text does not match the regular expression regexp Fail if a smaller or equal to b Fail if a greater or equal to b assertin(value, sequence) assertisnone(value) Fail if value is not an element of sequence Fail if value is not None assertisinstance(obj, cls) Fail if obj is not an instance of cls assertitemsequals(actual, expected) assertdictcontainssubset(subset, full) fail([msg]) Fail if the members of actual are not equal to the members of expected (order is ignored) Fail if the entries in dictionary subset are not a subset of those in dictionary full. Always fail

cprofile Invoking the profiler From the command line: python -m cprofile [-o output_file] [-s sort_order] myscript.py sort_order is one of calls, cumulative, name, (see cprofile documentation for more) From interactive shell / code: import cprofile cprofile.run(expression[, "filename.profile"]) From ipython: %prun D<filename> statement %run p [profiler_options] myscript.py Looking at saved statistics From interactive shell / code: import pstat p = pstat.stats("filename.profile") p.sort_stats(sort_order) p.print_stats() Simple graphical description (needs RunSnakeRun): runsnake filename.profile timing Execute expression one million times, return elapsed time in seconds: from timeit import Timer Timer("module.function(arg1, arg2)", "import module").timeit() For a more precise control of timing, use the repeat method; it returns a list of repeated measurements, in seconds: t = Timer("module.function(arg1, arg2)", "import module") # make 3 measurements of timing, repeat 2 million times t.repeat(3, 2000000) In ipython: %timeit n<n> -r<r> statement Time the execution of statement, executing it <N> times (default: adapt to speed of statement). The operation is repeated <R> times, and the best run is reported. %time statement Execute statement once and report CPU and wall clock time

pdb Invoking the debugger Enter at the start of a program, from the command line: python m pdb mycode.py Enter in a statement or function: import pdb # your code here if name == ' main ': # start debugger at the beginning of a function pdb.runcall(function[, argument,...]) # execute an expression (string) under the debugger pdb.run(expression) Enter at a specific point in the code: import pdb # some code here # the debugger starts here pdb.set_trace() # rest of the code In ipython: %pdb enter the debugger automatically after an exception is raised %debug enter the debugger post- mortem where the exception was thrown %run d b<l> myscript.py execute the script and enter the debugger and at line <L> Debugger commands h (help) [command] n (next) c (continue) s (step into) l (list) w (where) p (print) q (quit) b (break) [lineno function[, condition]] print help about command execute current line of code, go to next line continue executing the program until next breakpoint, exception, or end of the program execute current line of code; if a function is called, follow execution inside the function print code around the current line show a trace of the function call that led to the current line print the value of a variable leave the debugger set a breakpoint at a given line number or function, stop execution there if condition is fulfilled clear a breakpoint cl (clear)! (execute) execute a python command <enter> repeat last command