Self-review 9.3 What is PyUnit? PyUnit is the unit testing framework that comes as standard issue with the Python system.
|
|
|
- Arlene Allen
- 10 years ago
- Views:
Transcription
1 Testing, Testing 9 Self-Review Questions Self-review 9.1 What is unit testing? It is testing the functions, classes and methods of our applications in order to ascertain whether there are bugs in the code. Self-review 9.2 Why is unit testing important? Without unit tests, we cannot tell whether the code we have written for our application does what it should. Self-review 9.3 What is PyUnit? PyUnit is the unit testing framework that comes as standard issue with the Python system. Self-review 9.4 What is unittest? unittest is the module name for PyUnit. Self-review 9.5 What does this line of code mean? class Fibonacci_Test ( unittest.testcase : It means that the class Fibonacci_Test is a subclass of unittest.testcase ans will be a class containing unit tests to be executed as and when. Self-review 9.6 What is an assertion? It is a statement expressing the fact that a condition must be true. Self-review 9.7 What does the following line mean: self.assertequal ( 55, fibonacci ( 10 It is asserting that the result of executing fibonacci ( 10 should be the value 55. The unit test only succeeds if this is the case. Self-review 9.8 When is a method a unit test method? When the method is in a class that is a subclass of unittest.testcase and the method has a name beginning with test. Self-review 9.9 What do Red and Green mean in the context of unit testing?
2 70 Testing, Testing Red means that the test has failed, i.e. one or more of the test methods failed. Green means that all the test methods passed and the test passed. Self-review 9.10 Why are the terms Red and Green used in the context of unit testing? Because in tools originating with sunit and JUnit, red was used to indicate a failed test and green used for a non-failing test. This tradition is continued in Eclipse tools for JUnit and TestNG with Java and PyDev with Python. Self-review 9.11 What is coverage? It is a measure of the number of different cases associated with an application that the unit tests for that application test. Self-review 9.12 What is refactoring? It is the process of changing the application to make is better internally without changing what it does as seen from the outside. Self-review 9.13 Why is unit testing important for refactoring? Without a unit test structure, it would not be possible to tell whether the behavior of the application after refactoring is the same as before. Self-review 9.14 Using the Web, look up the term extreme programming, which has been mentioned in this chapter. What are the main features of this method and how does unit testing fit into it? Self-review 9.15 Debugging code thoroughly usually gives rise to a few exceptions. To debug code efficiently, it s important that you understand what Python s different exception types mean. What are the following exceptions used for in Python: AssertionError ImportError IndexError KeyError NameError TypeError ValueError Programming Exercises Exercise 9.1 Although much of this chapter has been about testing, another fundamental skill is being able to identify and correct errors once your testing has uncovered them. The following pieces of code all contain simple errors. Identify the errors in each program and suggest possible tests to detect them and solutions to fix them: 1. for i in range(1, -10, 1: print i
3 Programming Exercises l = [1, 2, 3, 4, 5] l[6] = 6 3. print [1, 2, 3].append([4, 5] Hint: In most cases there will be more than one possible solution. Give some consideration to which fixes would be best to use in different situations. Exercise 9.2 Complete the Matrix class test by adding test methods to deal with the subtraction and multiplication operations. import unittest from matrix import Matrix, zeros, unit class Matrix_Test ( unittest.testcase : def test_zeros ( self : xrange = 2 yrange = 4 matrix = zeros ( xrange, yrange for x in range ( xrange : for y in range ( yrange : self.assertequals ( 0, matrix[x][y] def test_unit ( self : xrange = 2 yrange = 4 matrix = unit ( xrange, yrange for x in range ( xrange : for y in range ( yrange : if x == y : self.assertequals ( 1, matrix[x][y] else : self.assertequals ( 0, matrix[x][y] def test_addintegertuplecorrect ( self : # data is a tuple of triplets, the first two are the matrices to be added, the third is the expected # answer. ( Matrix ( ( ( 1, 1, ( 1, 1, Matrix ( ( ( 2, 2, ( 2, 2, Matrix ( ( ( 3, 3, ( 3, 3, ( Matrix ( ( ( 1,, ( 1,, ( 1,, ( 1,, Matrix ( ( ( 2,, ( 2,, ( 2,, ( 2,, Matrix ( ( ( 3,, ( 3,, ( 3,, ( 3,, ( Matrix ( ( ( 1, 1, 1, 1,, Matrix ( ( ( 2, 2, 2, 2,, Matrix ( ( ( 3, 3, 3, 3, # Addition should be commutative so try both ways round. self.assertequal ( datum[2], datum[0] + datum[1] self.assertequal ( datum[2], datum[1] + datum[0] def test_addintegerlistcorrect ( self : # data is a tuple of triplets, the first two are the matrices to be added, the third is the expected # answer.
4 72 Testing, Testing ( Matrix ( [ [ 1, 1 ], [ 1, 1 ] ], Matrix ( [ [ 2, 2 ], [ 2, 2 ] ], Matrix ( [ [ 3, 3 ], [ 3, 3 ] ], ( Matrix ( [ [ 1 ], [ 1 ], [ 1 ], [ 1 ] ], Matrix ( [ [ 2 ], [ 2 ], [ 2 ], [ 2] ], Matrix ( [ [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], ( Matrix ( [ [ 1, 1, 1, 1 ] ], Matrix ( [ [ 2, 2, 2, 2 ] ], Matrix ( [ [ 3, 3, 3, 3 ] ] # Addition should be commutative so try both ways round. self.assertequal ( datum[2], datum[0] + datum[1] self.assertequal ( datum[2], datum[1] + datum[0] def test_adddoubletuplecorrect ( self : # data is a tuple of triplets, the first two are the matrices to be added, the third is the expec # answer. ( Matrix ( ( ( 1.0, 1.0, ( 1.0, 1.0, Matrix ( ( ( 2.0, 2.0, ( 2.0, 2.0, Matrix ( ( ( 3.0, 3.0, ( 3.0, 3.0, ( Matrix ( ( ( 1.0,, ( 1.0,, ( 1.0,, ( 1.0,, Matrix ( ( ( 2.0,, ( 2.0,, ( 2.0,, ( Matrix ( ( ( 3.0,, ( 3.0,, ( 3.0,, ( 3.0,, ( Matrix ( ( ( 1.0, 1.0, 1.0, 1.0,, Matrix ( ( ( 2.0, 2.0, 2.0, 2.0,, Matrix ( ( ( 3.0, 3.0, 3.0, 3.0, # Addition should be commutative so try both ways round. self.assertequal ( datum[2], datum[0] + datum[1] self.assertequal ( datum[2], datum[1] + datum[0] def test_adddoublelistcorrect ( self : # data is a tuple of triplets, the first two are the matrices to be added, the third is the expec # answer. ( Matrix ( [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ], Matrix ( [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ], Matrix ( [ [ 3.0, 3.0 ], [ 3.0, 3.0 ] ], ( Matrix ( [ [ 1.0 ], [ 1.0 ], [ 1.0 ], [ 1.0 ] ], Matrix ( [ [ 2.0 ], [ 2.0 ], [ 2.0 ], [ 2.0 ] ] Matrix ( [ [ 3.0 ], [ 3.0 ], [ 3.0 ], [ 3.0 ] ], ( Matrix ( [ [ 1.0, 1.0, 1.0, 1.0 ] ], Matrix ( [ [ 2.0, 2.0, 2.0, 2.0 ] ], Matrix ( [ [ 3.0, 3.0, 3.0, 3.0 ] ] # Addition should be commutative so try both ways round. self.assertequal ( datum[2], datum[0] + datum[1] self.assertequal ( datum[2], datum[1] + datum[0] def test_addintegertupleerror ( self : # data is tuple of pairs which should not be addable due to different shapes. ( Matrix ( ( ( 1, 1, ( 1, 1, Matrix ( ( ( 2,, ( 2,, ( 2,, ( 2,, ( Matrix ( ( ( 1,, ( 1,, ( 1,, ( 1,, Matrix ( ( ( 2, 2, 2, 2,, ( Matrix ( ( ( 1, 1, 1, 1,, Matrix ( ( ( 2, 2, ( 2, 2 self.assertraises ( ValueError, Matrix. add, datum[0], datum[1]
5 Programming Exercises 73 def test_addintegerlisterror ( self : # data is tuple of pairs which should not be addable due to different shapes. ( Matrix ( [ [ 1, 1 ], [ 1, 1 ] ], Matrix ( [ [ 2 ], [ 2 ], [ 2 ], [ 2 ] ], ( Matrix ( [ [ 1 ], [ 1 ], [ 1 ], [ 1 ] ], Matrix ( [ [ 2, 2, 2, 2 ] ], ( Matrix ( [ [ 1, 1, 1, 1 ] ], Matrix ( [ [ 2, 2 ], [ 2, 2 ] ] self.assertraises ( ValueError, Matrix. add, datum[0], datum[1] def test_adddoubletupleerror ( self : # data is tuple of pairs which should not be addable due to different shapes. ( Matrix ( ( ( 1.0, 1.0, ( 1.0, 1.0, Matrix ( ( ( 2.0,, ( 2.0,, ( 2.0,, ( 2.0,, ( Matrix ( ( ( 1.0,, ( 1.0,, ( 1.0,, ( 1.0,, Matrix ( ( ( 2.0, 2.0, 2.0, 2.0,, ( Matrix ( ( ( 1.0, 1.0, 1.0, 1.0,, Matrix ( ( ( 2.0, 2.0, ( 2.0, 2.0 self.assertraises ( ValueError, Matrix. add, datum[0], datum[1] def test_adddoublelisterror ( self : # data is tuple of pairs which should not be addable due to different shapes. ( Matrix ( [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ], Matrix ( [ [ 2.0 ], [ 2.0 ], [ 2.0 ], [ 2.0 ] ], ( Matrix ( [ [ 1.0 ], [ 1.0 ], [ 1.0 ], [ 1.0 ] ], Matrix ( [ [ 2.0, 2.0, 2.0, 2.0 ] ], ( Matrix ( [ [ 1.0, 1.0, 1.0, 1.0 ] ], Matrix ( [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] self.assertraises ( ValueError, Matrix. add, datum[0], datum[1] # Methods added to answer question are below here ============================ def test_subtractcorrect ( self : ( Matrix ( ( ( 1, 1, ( 1, 1, Matrix ( ( ( 2, 2, ( 2, 2, Matrix ( ( ( -1, -1, ( -1, -1, ( Matrix ( ( ( 1,, ( 1,, ( 1,, ( 1,, Matrix ( ( ( 2,, ( 2,, ( 2,, ( 2,, Matrix ( ( ( -1,, ( -1,, ( -1,, ( -1,, ( Matrix ( ( ( 1, 1, 1, 1,, Matrix ( ( ( 2, 2, 2, 2,, Matrix ( ( ( -1, -1, -1, -1, self.assertequal ( datum[2], datum[0] - datum[1] def test_subtracterror ( self : ( Matrix ( ( ( 1, 1, ( 1, 1, Matrix ( ( ( 2,, ( 2,, ( 2,, ( 2,, ( Matrix ( ( ( 1,, ( 1,, ( 1,, ( 1,, Matrix ( ( ( 2, 2, 2, 2,, ( Matrix ( ( ( 1, 1, 1, 1,, Matrix ( ( ( 2, 2, ( 2, 2 self.assertraises ( ValueError, Matrix. sub, datum[0], datum[1] def test_multiplycorrect ( self :
6 74 Testing, Testing ( Matrix ( ( ( 1, 1, ( 1, 1, Matrix ( ( ( 2, 2, ( 2, 2, Matrix ( ( ( 4, 4, ( 4, 4, ( Matrix ( ( ( 1,, ( 1,, ( 1,, ( 1,, Matrix ( ( ( 2, 2, 2, 2,, Matrix ( ( ( 2, 2, 2, 2, ( 2, 2, 2, 2, ( 2, 2, 2, 2, ( 2, 2, 2, 2, ( Matrix ( ( ( 1, 1, 1, 1,, Matrix ( ( ( 2,, ( 2,, ( 2,, ( 2,, Matrix ( ( ( 8,, self.assertequal ( datum[2], datum[0] * datum[1] def test_multiplyerror ( self : ( Matrix ( ( ( 1, 1, ( 1, 1, Matrix ( ( ( 2,, ( 2,, ( 2,, ( 2,, ( Matrix ( ( ( 1, 1, 1, 1,, Matrix ( ( ( 2, 2, ( 2, 2 self.assertraises ( ValueError, Matrix. mul, datum[0], datum[1] if name == main : unittest.main ( Exercise 9.3 Write a test program for the queue implementation from Section?? (page??. import sys sys.path.append (../../../SourceCode/classyObjects import unittest from queue_2 import Queue class Queue_Test ( unittest.testcase : def setup ( self : self.queue = Queue ( def test_create ( self : self.assertequals ( 0, len ( self.queue def test_one ( self : self.queue.add ( 10 self.assertequals ( 1, len ( self.queue self.assertequals ( 10, self.queue.remove ( self.assertequals ( 0, len ( self.queue def test_many ( self : 10, fred, 10.4, [ 10, 20 ] self.queue.add ( datum self.assertequals ( len ( data, len ( self.queue for i in range ( len ( data : self.assertequals ( data[i], self.queue.remove ( self.assertequals ( 0, len ( self.queue def test_removeempty ( self : self.assertraises ( IndexError, self.queue.remove
7 Programming Exercises 75 if name == main : unittest.main ( Exercise 9.4 Write a test program for the stack implementation from Section?? (page??. Exercise 9.5 Write a test program for the Account class from?? (page??, the CreditAccount class from?? (page??, and the StudentAccount class from?? (page??. Exercise 9.6 Below is the start of a test suite; the exercise is to write a module that passes it. Your code will provide functions to calculate various sorts of average on lists of data: mode the most frequent datum appearing in the list. median the middle value in the list of (sorted data. mean the total of the data divided by the number of values. import average, unittest class TestMe ( unittest.testcase : def setup ( self : self.zeros = [ 0.0 for i in range ( 1,10 ] self.ints = [ i for i in range ( -10, 10 ] self.foobar = [ i for i in range ( -10, 10 ] + [ 2, 2, 2, 2, 2, 2, 2, 2 ] def test_mode ( self : self.assertequals ( 0.0, average.mode ( self.zeros self.assertequals ( 0, average.mode ( self.ints self.assertequals ( 2, average.mode ( self.foobar def test_mean ( self : self.assertequals ( 0.0, average.mean ( self.zeros self.assertequals ( -1, average.mean ( self.ints self.assertequals ( 0, average.mean ( self.foobar def test_median ( self : self.assertequals ( 0.0, average.median ( self.zeros self.assertequals ( 0, average.median ( self.ints self.assertequals ( 2, average.median ( self.foobar if name == main : unittest.main ( Exercise 9.7 The test suite for the previous task is a good start, but not very complete. Add some more test cases. In particular, you should test for: Handling data that isn t in a sequence. Handling data that is in a sequence but isn t numeric.
8 76 Testing, Testing Exercise 9.8 Use PyUnit to test the following functions in the random module: randint random choice Exercise 9.9 If you have completed the exercise above, you will have noticed that the random module contains both functions and classes. The classes represent various sorts of random number generator, and many of the available functions are duplicated as methods in each of the classes. Write a test suite to test the randint, random and choice methods in the random.random class. Exercise 9.10 Some programs cannot be easily tested using unit test modules such as PyUnit. GUIs, in particular, need both unit testing (to exercise application logic and testing that exercises the graphical components of the program. For this exercise you need to thoroughly test the Turtle module. Although you are already familiar with this code, you should make sure that you plan your testing carefully and exercise as many of the available functions as possible. In particular, you should note that many functions in turtle are not graphical, and so can be tested with PyUnit. Exercise 9.11 Some data is more interesting to test than others. UK postcodes (unlike US zip codes are particularly interesting because they have lots of special cases. Most postcodes consist of two letters, one number, a space, a number and two letters. For example, James office postcode is CV1 5FB. However, many postcodes are slightly different, such as PO10 0AB, SW1A 0AA and SAN TA1. Read about British postcodes on Wikipedia wiki/uk_postcodes and write a table of test data that would thoroughly exercise a postcode parser. Challenges Challenge 9.1 We left these questions as questions for the reader in Section?? (page??: 1. Should we be stopping numbers such as IIIIIIIIIIII, for example, from being legal? 2. Should we be forbidding mixed case numbers? 3. Are MCMIC, MCMXCIX and MIM all valid representations of 1999? Why does MCMXCIX appear to be the preferred representation? 4. Is MCMCXCVIII a valid representation of 2098? 5. Is MXMVII a valid representation of 1998?
9 Challenges Should we be stopping numbers such as IIIIIIIIIIII, for example, from being legal? 2. Should we be forbidding mixed case numbers? (Probably yes. 3. Are MCMIC, MCMXCIX and MIM all valid representations of 1999? Why does MCMXCIX appear to be the preferred representation? 4. Is MCMCXCVIII a valid representation of 2098? 5. Is MXMVII a valid representation of 1998? Challenge 9.2 In this challenge you will be developing a program using Test-Driven Development (TDD, which we introduced in Section?? (page??. Make sure you follow the principles of TDD strictly. The purpose of this challenge is not just to give you more programming practice, but to give you experience of developing a whole program using TDD. In Chapters?? and?? we developed the Die class and its various subclasses. For this challenge you will write a game of Snap, which should be played on the console (i.e. you don t need to write a GUI unless you want to. You will probably want to include the following components, but the detailed design of the code is up to you: A pack of cards. You will probably want to use a subclass of Die for this. You don t have to model a standard pack of 52 cards, it s up to you. Some part of your program should control the game. This component should be responsible for knowing whose turn it is to play and when the game has been won (or drawn if you run out of cards. An interface. Some component of your program should be responsible for communicating with the user. Following good HCI principles, you should make sure that the user is always aware of the state of the game (including their score. Note that because users are playing with a pack of cards, when one card is (randomly played, it cannot be used again. So you need some way to ensure that cards are not played twice perhaps by keeping track of which cards have already been played. This code could be placed in various components of the program. Think about where would be most sensible to put it (but remember, you can always refactor your code later on. Challenge 9.3 In Section?? (page?? of this chapter, we wrote a test class for the matrix module from Section?? (page??. In this challenge we will give you code for another module that uses matrices to perform some simple graphics operations. The code comes with some simple tests, your job is to test the code thoroughly using PyUnit. In graphics applications such as the GIMP or Photoshop and in animations, shapes and objects are often moved, scaled and rotated
10 78 Testing, Testing automatically. This is often done using a technique called homogeneous coordinates, in which 3D matrices are used to manipulate 2D images. To convert a 2D point into a homogeneous 3D point we make the following transformation: (x,y (x,y,1 and to convert back to an ordinary 2D point the following transformation needs to be performed: ( x (x,y,h h h, y To perform a transformation (rotation, translation or scaling on a point, the point needs to be multiplied by a transformation matrix. In the code below we have created a class called HomogMatrix which is a subclass of the Matrix class you have seen before. This class has methods to convert vectors to and from their homogeneous counterparts. The module also has functions to perform transformations on vectors and code to draw shapes (made from lists of vectors with the Python turtle. Make sure you spend some time looking through this code in order to understand it, before you begin to write some test cases for the HomogMatrix class and the later functions. Provides functions to rotate, scale and translate points using homogeneous matrices. author = Sarah Mount <[email protected]> date = version = 1.0 copyright = Copyright (c 2007 Sarah Mount licence = GNU General Public Licence (GPL from matrix import Matrix import copy, math, turtle class HomogMatrix ( Matrix : def init ( self, data : Matrix. init ( self, data def ensure2d ( self : if len ( self.data!= 1 or len ( self.data[0]!= 2 : raise ValueError, Matrix not a 2D vector. def ensure3d ( self : if len ( self.data!= 1 or len ( self.data[0]!= 3 : raise ValueError, Matrix not a 3D vector. def de_homo ( self : Convert a homogeneous 3D point into a 2D point. self. ensure3d ( m1 = self.data[0][0] / self.data[0][2] m2 = self.data[0][1] / self.data[0][2] return HomogMatrix ( [ [ m1, m2 ] ] def en_homo ( self : Convert a 2D point into a homogeneous 3D point.
11 Challenges 79 self. ensure2d ( d = copy.copy ( self.data d[0] = list ( d[0] d[0] += [1.0] return HomogMatrix ( d def mul ( self, m : mm = HomogMatrix ( Matrix. mul ( self, m return HomogMatrix ( mm def add ( self, m : mm = HomogMatrix ( Matrix. add ( self, m return HomogMatrix ( mm def sub ( self, m : mm = HomogMatrix ( Matrix. sub ( self, m return HomogMatrix ( mm def translate ( v, ( tx, ty : Translate 2D vector v by (t1, t2 if not isinstance ( v, HomogMatrix : raise ValueError, Matrix not homogeneous t_data = [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ tx, ty, 1.0 ] ] t = Matrix ( t_data v_h = v.en_homo ( translated = v_h * t return translated.de_homo ( def scale ( v, ( sx, sy : Scale vector v by (sx, sy. if not isinstance ( v, HomogMatrix : raise ValueError, Matrix not homogeneous s_data = [ [ sx, 0.0, 0.0 ], [ 0.0, sy, 0.0 ], [ 0.0, 0.0, 1.0 ] ] s = HomogMatrix ( s_data v_h = v.en_homo ( scaled = v_h * s return scaled.de_homo ( def rotate ( v, theta : Scale vector v by (sx, sy. if not isinstance ( v, HomogMatrix : raise ValueError, Matrix not homogeneous r_data = [ [ math.cos ( theta, math.sin ( theta, 0.0 ], [ -math.sin ( theta, math.cos ( theta, 0.0 ], [ 0.0, 0.0, 1.0 ] ] r = Matrix ( r_data v_h = v.en_homo ( rotated = v_h * r return rotated.de_homo ( def draw ( points :
12 80 Testing, Testing Draw a shape made from a list of points. turtle.clear ( turtle.up ( turtle.goto ( points[0][0] turtle.down ( for point in points[1:]: turtle.goto ( point[0] if name == main : # Test data -- some simple shapes made from lists of points. # A point is a 2D vector [[x, y]] shapes = { square : [ HomogMatrix ( [ ( 0.0, 0.0 ], HomogMatrix ( [ ( 100.0, 0.0 ], HomogMatrix ( [ ( 100.0, ], HomogMatrix ( [ ( 0.0, ], HomogMatrix ( [ ( 0.0, 0.0 ] ], rectangle : [ HomogMatrix ( [ ( 0.0, 0.0 ], HomogMatrix ( [ ( 200.0, 0.0 ], HomogMatrix ( [ ( 200.0, ], HomogMatrix ( [ ( 0.0, ], HomogMatrix ( [ ( 0.0, 0.0 ] ], pentagon : [ HomogMatrix ( [ ( 0.0, 0.0 ], HomogMatrix ( [ ( 100.0, 0.0 ], HomogMatrix ( [ ( 131.0, 95.0 ], HomogMatrix ( [ ( 50.0, ], HomogMatrix ( [ ( -30.0, 95.0 ], HomogMatrix ( [ ( 0.0, 0.0 ] ] } for shape in shapes.keys ( : print shape, : for vector in shapes[shape] : print vector draw ( shapes[shape] print def draw_transform ( trans, data, s, t : Apply matrix transformation to a shape and draw the transformed shape with the turtle. trans should be a function. data is used by the trans function. s should be a key (for the shapes dict. t should be a string. ss = map ( lambda v : trans ( v, data, shapes[s] print t, s, : for v in ss : print \t, v print draw ( ss # Draw transformed shapes draw_transform ( translate, ( , , square, translated draw_transform ( translate, ( , , pentagon, translated draw_transform ( scale, ( 1.5, 0.2, rectangle, scaled draw_transform ( scale, ( 0.25, 0.25, pentagon, scaled
13 Challenges 81 draw_transform ( rotate, 45.0, square, rotated draw_transform ( rotate, 20.0, pentagon, rotated raw_input ( Press any key to exit.
CIS 192: Lecture 13 Scientific Computing and Unit Testing
CIS 192: Lecture 13 Scientific Computing and Unit Testing Lili Dworkin University of Pennsylvania Scientific Computing I Python is really popular in the scientific and statistical computing world I Why?
Intro to scientific programming (with Python) Pietro Berkes, Brandeis University
Intro to scientific programming (with Python) Pietro Berkes, Brandeis University Next 4 lessons: Outline Scientific programming: best practices Classical learning (Hoepfield network) Probabilistic learning
Python Testing with unittest, nose, pytest
Python Testing with unittest, nose, pytest Efficient and effective testing using the 3 top python testing frameworks Brian Okken This book is for sale at http://leanpub.com/pythontesting This version was
Python for Rookies. Example Examination Paper
Python for Rookies Example Examination Paper Instructions to Students: Time Allowed: 2 hours. This is Open Book Examination. All questions carry 25 marks. There are 5 questions in this exam. You should
Python as a Testing Tool. Chris Withers
Python as a Testing Tool Chris Withers Who am I? Chris Withers Independent Zope and Python Consultant Using Python since 1999 Fan of XP What do I use Python for? Content Management Systems Integration
Survey of Unit-Testing Frameworks. by John Szakmeister and Tim Woods
Survey of Unit-Testing Frameworks by John Szakmeister and Tim Woods Our Background Using Python for 7 years Unit-testing fanatics for 5 years Agenda Why unit test? Talk about 3 frameworks: unittest nose
Profiling, debugging and testing with Python. Jonathan Bollback, Georg Rieckh and Jose Guzman
Profiling, debugging and testing with Python Jonathan Bollback, Georg Rieckh and Jose Guzman Overview 1.- Profiling 4 Profiling: timeit 5 Profiling: exercise 6 2.- Debugging 7 Debugging: pdb 8 Debugging:
Test Driven Development in Python
Test Driven Development in Python Kevin Dahlhausen [email protected] My (pythonic) Background learned of python in 96 < Vim Editor Fast-Light Toolkit python wrappers PyGallery one of the early
Introduction to Python
WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language
Fail early, fail often, succeed sooner!
Fail early, fail often, succeed sooner! Contents Beyond testing Testing levels Testing techniques TDD = fail early Automate testing = fail often Tools for testing Acceptance tests Quality Erja Nikunen
Software Testing with Python
Software Testing with Python Magnus Lyckå Thinkware AB www.thinkware.se EuroPython Conference 2004 Chalmers, Göteborg, Sweden 2004, Magnus Lyckå In the next 30 minutes you should... Learn about different
Tasks to Move Students On
Maths for Learning Inclusion Tasks to Move Students On Part 1 Maths for Learning Inclusion (M4LI) Tasks to Move Students On Numbers 1 10 Structuring Number Maths for Learning Inclusion (M4LI) Tasks to
Chapter 3 Writing Simple Programs. What Is Programming? Internet. Witin the web server we set lots and lots of requests which we need to respond to
Chapter 3 Writing Simple Programs Charles Severance Unless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License. http://creativecommons.org/licenses/by/3.0/.
Unit Testing webmethods Integrations using JUnit Practicing TDD for EAI projects
TORRY HARRIS BUSINESS SOLUTIONS Unit Testing webmethods Integrations using JUnit Practicing TDD for EAI projects Ganapathi Nanjappa 4/28/2010 2010 Torry Harris Business Solutions. All rights reserved Page
Welcome to Introduction to programming in Python
Welcome to Introduction to programming in Python Suffolk One, Ipswich, 4:30 to 6:00 Tuesday Jan 14, Jan 21, Jan 28, Feb 11 Welcome Fire exits Toilets Refreshments 1 Learning objectives of the course An
Building and breaking a Python sandbox
Building and breaking a Python sandbox Director Organizer @jessicamckellar http://jesstess.com Why? Learning a language Providing a hosted scratch pad Distributed computation Inspecting running processes
by Teresa Evans Copyright 2005 Teresa Evans. All rights reserved.
by Teresa Evans Copyright 2005 Teresa Evans. All rights reserved. Permission is given for the making of copies for use in the home or classroom of the purchaser only. SAMPLE PAGES Please enjoy using these
[1] Diagonal factorization
8.03 LA.6: Diagonalization and Orthogonal Matrices [ Diagonal factorization [2 Solving systems of first order differential equations [3 Symmetric and Orthonormal Matrices [ Diagonal factorization Recall:
Teaching Pre-Algebra in PowerPoint
Key Vocabulary: Numerator, Denominator, Ratio Title Key Skills: Convert Fractions to Decimals Long Division Convert Decimals to Percents Rounding Percents Slide #1: Start the lesson in Presentation Mode
Convert between units of area and determine the scale factor of two similar figures.
CHAPTER 5 Units of Area c GOAL Convert between units of area and determine the scale factor of two. You will need a ruler centimetre grid paper a protractor a calculator Learn about the Math The area of
Goal: Practice writing pseudocode and understand how pseudocode translates to real code.
Lab 7: Pseudocode Pseudocode is code written for human understanding not a compiler. You can think of pseudocode as English code that can be understood by anyone (not just a computer scientist). Pseudocode
Python Loops and String Manipulation
WEEK TWO Python Loops and String Manipulation Last week, we showed you some basic Python programming and gave you some intriguing problems to solve. But it is hard to do anything really exciting until
Wrestling with Python Unit testing. Warren Viant
Wrestling with Python Unit testing Warren Viant Assessment criteria OCR - 2015 Programming Techniques (12 marks) There is an attempt to solve all of the tasks using most of the techniques listed. The techniques
CS 4204 Computer Graphics
CS 4204 Computer Graphics 2D and 3D Transformations Doug Bowman Adapted from notes by Yong Cao Virginia Tech 1 Transformations What are they? changing something to something else via rules mathematics:
Testing: Python, Java, Groovy, etc.
Testing: Python, Java, Groovy, etc. Prof Russel Winder http://www.russel.org.uk email: [email protected] xmpp: [email protected] twitter: @russel_winder Copyright 2012 Russel Winder 1 Aims, Goals
A Concrete Introduction. to the Abstract Concepts. of Integers and Algebra using Algebra Tiles
A Concrete Introduction to the Abstract Concepts of Integers and Algebra using Algebra Tiles Table of Contents Introduction... 1 page Integers 1: Introduction to Integers... 3 2: Working with Algebra Tiles...
VISUAL ALGEBRA FOR COLLEGE STUDENTS. Laurie J. Burton Western Oregon University
VISUAL ALGEBRA FOR COLLEGE STUDENTS Laurie J. Burton Western Oregon University VISUAL ALGEBRA FOR COLLEGE STUDENTS TABLE OF CONTENTS Welcome and Introduction 1 Chapter 1: INTEGERS AND INTEGER OPERATIONS
REFERENCE GUIDE 1. INTRODUCTION
1. INTRODUCTION Scratch is a new programming language that makes it easy to create interactive stories, games, and animations and share your creations with others on the web. This Reference Guide provides
Key Stage 3. Scheme of Work. Written by Heaton Moor Digital
Key Stage 3 Scheme of Work Written by Heaton Moor Digital 1 Table of Contents Terms and Conditions Page 3 UK National Computing Curriculum Pathways Page 4 Mapping the Year 7 Scheme to the Computing Curriculum
MAKING MATH MORE FUN BRINGS YOU FUN MATH GAME PRINTABLES FOR HOME OR SCHOOL
MAKING MATH MORE FUN BRINGS YOU FUN MATH GAME PRINTABLES FOR HOME OR SCHOOL THESE FUN MATH GAME PRINTABLES are brought to you with compliments from Making Math More Fun at and Math Board Games at Copyright
Affine Transformations
A P P E N D I X C Affine Transformations CONTENTS C The need for geometric transformations 335 C2 Affine transformations 336 C3 Matri representation of the linear transformations 338 C4 Homogeneous coordinates
Introduction to Python
Introduction to Python Sophia Bethany Coban Problem Solving By Computer March 26, 2014 Introduction to Python Python is a general-purpose, high-level programming language. It offers readable codes, and
If A is divided by B the result is 2/3. If B is divided by C the result is 4/7. What is the result if A is divided by C?
Problem 3 If A is divided by B the result is 2/3. If B is divided by C the result is 4/7. What is the result if A is divided by C? Suggested Questions to ask students about Problem 3 The key to this question
How To Factor By Gcf In Algebra 1.5
7-2 Factoring by GCF Warm Up Lesson Presentation Lesson Quiz Algebra 1 Warm Up Simplify. 1. 2(w + 1) 2. 3x(x 2 4) 2w + 2 3x 3 12x Find the GCF of each pair of monomials. 3. 4h 2 and 6h 2h 4. 13p and 26p
SpiraTest / SpiraTeam Automated Unit Testing Integration & User Guide Inflectra Corporation
SpiraTest / SpiraTeam Automated Unit Testing Integration & User Guide Inflectra Corporation Date: October 3rd, 2014 Contents 1. Introduction... 1 2. Integrating with NUnit... 2 3. Integrating with JUnit...
We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
Given a point cloud, polygon, or sampled parametric curve, we can use transformations for several purposes:
3 3.1 2D Given a point cloud, polygon, or sampled parametric curve, we can use transformations for several purposes: 1. Change coordinate frames (world, window, viewport, device, etc). 2. Compose objects
How To Understand The Details Of A Function In Python 2.5.2 (For Beginners)
Python Programming: An Introduction to Computer Science Chapter 6 Defining Functions Python Programming, 2/e 1 Objectives To understand why programmers divide programs up into sets of cooperating functions.
Advanced Topics: Biopython
Advanced Topics: Biopython Day Three Testing Peter J. A. Cock The James Hutton Institute, Invergowrie, Dundee, DD2 5DA, Scotland, UK 23rd 25th January 2012, Workshop on Genomics, Český Krumlov, Czech Republic
Computing Concepts with Java Essentials
2008 AGI-Information Management Consultants May be used for personal purporses only or by libraries associated to dandelon.com network. Computing Concepts with Java Essentials 3rd Edition Cay Horstmann
Java course - IAG0040. Unit testing & Agile Software Development
Java course - IAG0040 Unit testing & Agile Software Development 2011 Unit tests How to be confident that your code works? Why wait for somebody else to test your code? How to provide up-to-date examples
Year 9 mathematics test
Ma KEY STAGE 3 Year 9 mathematics test Tier 6 8 Paper 1 Calculator not allowed First name Last name Class Date Please read this page, but do not open your booklet until your teacher tells you to start.
Software Tool Seminar WS1516 - Taming the Snake
Software Tool Seminar WS1516 - Taming the Snake November 4, 2015 1 Taming the Snake 1.1 Understanding how Python works in N simple steps (with N still growing) 1.2 Step 0. What this talk is about (and
Exercise 1: Python Language Basics
Exercise 1: Python Language Basics In this exercise we will cover the basic principles of the Python language. All languages have a standard set of functionality including the ability to comment code,
Test Driven Development
Test Driven Development Introduction Test Driven development (TDD) is a fairly recent (post 2000) design approach that originated from the Extreme Programming / Agile Methodologies design communities.
Objects and classes. Objects and classes. Jarkko Toivonen (CS Department) Programming in Python 1
Objects and classes Jarkko Toivonen (CS Department) Programming in Python 1 Programming paradigms of Python Python is an object-oriented programming language like Java and C++ But unlike Java, Python doesn
NF5-12 Flexibility with Equivalent Fractions and Pages 110 112
NF5- Flexibility with Equivalent Fractions and Pages 0 Lowest Terms STANDARDS preparation for 5.NF.A., 5.NF.A. Goals Students will equivalent fractions using division and reduce fractions to lowest terms.
Name: Section Registered In:
Name: Section Registered In: Math 125 Exam 3 Version 1 April 24, 2006 60 total points possible 1. (5pts) Use Cramer s Rule to solve 3x + 4y = 30 x 2y = 8. Be sure to show enough detail that shows you are
XP and TDD. Extreme Programming and Test Driven Development. Bertrand Meyer, Manuel Oriol Andreas Leitner. Chair of Software Engineering ETH Zurich
XP and TDD Extreme Programming and Test Driven Development Bertrand Meyer, Manuel Oriol Andreas Leitner ETH Zurich October 27, 2006 Outline Development Processes Overview Extreme Programming Test Driven
Mathematics (Project Maths Phase 1)
2011. S133S Coimisiún na Scrúduithe Stáit State Examinations Commission Junior Certificate Examination Sample Paper Mathematics (Project Maths Phase 1) Paper 2 Ordinary Level Time: 2 hours 300 marks Running
Python Lists and Loops
WEEK THREE Python Lists and Loops You ve made it to Week 3, well done! Most programs need to keep track of a list (or collection) of things (e.g. names) at one time or another, and this week we ll show
Welcome to Harcourt Mega Math: The Number Games
Welcome to Harcourt Mega Math: The Number Games Harcourt Mega Math In The Number Games, students take on a math challenge in a lively insect stadium. Introduced by our host Penny and a number of sporting
Beginning to Program Python
COMP1021 Introduction to Computer Science Beginning to Program Python David Rossiter Outcomes After completing this presentation, you are expected to be able to: 1. Use Python code to do simple text input
ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)
ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology) Subject Description: This subject deals with discrete structures like set theory, mathematical
Test-Driven Development
Test-Driven Development An Introduction Mattias Ståhlberg [email protected] Debugging sucks. Testing rocks. Contents 1. What is unit testing? 2. What is test-driven development? 3. Example 4.
2010-2011 Assessment for Master s Degree Program Fall 2010 - Spring 2011 Computer Science Dept. Texas A&M University - Commerce
2010-2011 Assessment for Master s Degree Program Fall 2010 - Spring 2011 Computer Science Dept. Texas A&M University - Commerce Program Objective #1 (PO1):Students will be able to demonstrate a broad knowledge
13 MATH FACTS 101. 2 a = 1. 7. The elements of a vector have a graphical interpretation, which is particularly easy to see in two or three dimensions.
3 MATH FACTS 0 3 MATH FACTS 3. Vectors 3.. Definition We use the overhead arrow to denote a column vector, i.e., a linear segment with a direction. For example, in three-space, we write a vector in terms
Paper 1. Calculator not allowed. Mathematics test. First name. Last name. School. Remember KEY STAGE 3 TIER 5 7
Ma KEY STAGE 3 Mathematics test TIER 5 7 Paper 1 Calculator not allowed First name Last name School 2009 Remember The test is 1 hour long. You must not use a calculator for any question in this test. You
Kindergarten Math Content 1
Kindergarten Math Content 1 Number and Operations: Whole Numbers Counting and the Number System A main focus in Kindergarten is counting, which is the basis for understanding the number system and for
Assembly Language Programming
Assembly Language Programming Assemblers were the first programs to assist in programming. The idea of the assembler is simple: represent each computer instruction with an acronym (group of letters). Eg:
Card programming Programming Language design
Tell and Draw, Card Programming Developed by: Jun-PyO Park, Seung-Bum Kim, Dong-Hee Park and Seung-Joon Choi. Arranged by: Tim Bell. This is an engaging extension of the CSUnplugged Marching Orders activity.
Numeracy Targets. I can count at least 20 objects
Targets 1c I can read numbers up to 10 I can count up to 10 objects I can say the number names in order up to 20 I can write at least 4 numbers up to 10. When someone gives me a small number of objects
Year 9 mathematics test
Ma KEY STAGE 3 Year 9 mathematics test Tier 5 7 Paper 1 Calculator not allowed First name Last name Class Date Please read this page, but do not open your booklet until your teacher tells you to start.
Software Testing. Theory and Practicalities
Software Testing Theory and Practicalities Purpose To find bugs To enable and respond to change To understand and monitor performance To verify conformance with specifications To understand the functionality
Rotation Matrices and Homogeneous Transformations
Rotation Matrices and Homogeneous Transformations A coordinate frame in an n-dimensional space is defined by n mutually orthogonal unit vectors. In particular, for a two-dimensional (2D) space, i.e., n
Python and Google App Engine
Python and Google App Engine Dan Sanderson June 14, 2012 Google App Engine Platform for building scalable web applications Built on Google infrastructure Pay for what you use Apps, instance hours, storage,
Glossary of Object Oriented Terms
Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction
CS 4620 Practicum Programming Assignment 6 Animation
CS 4620 Practicum Programming Assignment 6 Animation out: Friday 14th November 2014 due: : Monday 24th November 2014 1 Introduction In this assignment, we will explore a common topic in animation: key
TEACHER S GUIDE TO RUSH HOUR
Using Puzzles to Teach Problem Solving TEACHER S GUIDE TO RUSH HOUR Includes Rush Hour 2, 3, 4, Rush Hour Jr., Railroad Rush Hour and Safari Rush Hour BENEFITS Rush Hour is a sliding piece puzzle that
SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI-89. by Joseph Collison
SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI-89 by Joseph Collison Copyright 2000 by Joseph Collison All rights reserved Reproduction or translation of any part of this work beyond that permitted by Sections
Mathematical goals. Starting points. Materials required. Time needed
Level N7 of challenge: A/B N7 Using percentages to increase quantities quantities Mathematical goals Starting points Materials required Time needed To enable learners to: make links between percentages,
Memory Management Simulation Interactive Lab
Memory Management Simulation Interactive Lab The purpose of this lab is to help you to understand deadlock. We will use a MOSS simulator for this. The instructions for this lab are for a computer running
CCSS Mathematics Implementation Guide Grade 5 2012 2013. First Nine Weeks
First Nine Weeks s The value of a digit is based on its place value. What changes the value of a digit? 5.NBT.1 RECOGNIZE that in a multi-digit number, a digit in one place represents 10 times as much
MATHS ACTIVITIES FOR REGISTRATION TIME
MATHS ACTIVITIES FOR REGISTRATION TIME At the beginning of the year, pair children as partners. You could match different ability children for support. Target Number Write a target number on the board.
-- Martensdale-St. Marys Community School Math Curriculum
-- Martensdale-St. Marys Community School Standard 1: Students can understand and apply a variety of math concepts. Benchmark; The student will: A. Understand and apply number properties and operations.
521493S Computer Graphics. Exercise 2 & course schedule change
521493S Computer Graphics Exercise 2 & course schedule change Course Schedule Change Lecture from Wednesday 31th of March is moved to Tuesday 30th of March at 16-18 in TS128 Question 2.1 Given two nonparallel,
December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS
December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B KITCHENS The equation 1 Lines in two-dimensional space (1) 2x y = 3 describes a line in two-dimensional space The coefficients of x and y in the equation
A Practical Guide to Test Case Types in Java
Software Tests with Faktor-IPS Gunnar Tacke, Jan Ortmann (Dokumentversion 203) Overview In each software development project, software testing entails considerable expenses. Running regression tests manually
2D Geometric Transformations
2D Geometric Transformations (Chapter 5 in FVD) 2D Geometric Transformations Question: How do we represent a geometric object in the plane? Answer: For now, assume that objects consist of points and lines.
SAT Math Facts & Formulas Review Quiz
Test your knowledge of SAT math facts, formulas, and vocabulary with the following quiz. Some questions are more challenging, just like a few of the questions that you ll encounter on the SAT; these questions
Paper 1. Calculator not allowed. Mathematics test. First name. Last name. School. Remember KEY STAGE 3 TIER 6 8
Ma KEY STAGE 3 Mathematics test TIER 6 8 Paper 1 Calculator not allowed First name Last name School 2009 Remember The test is 1 hour long. You must not use a calculator for any question in this test. You
THREE DIMENSIONAL GEOMETRY
Chapter 8 THREE DIMENSIONAL GEOMETRY 8.1 Introduction In this chapter we present a vector algebra approach to three dimensional geometry. The aim is to present standard properties of lines and planes,
Math Games For Skills and Concepts
Math Games p.1 Math Games For Skills and Concepts Original material 2001-2006, John Golden, GVSU permission granted for educational use Other material copyright: Investigations in Number, Data and Space,
Mathematics. What to expect Resources Study Strategies Helpful Preparation Tips Problem Solving Strategies and Hints Test taking strategies
Mathematics Before reading this section, make sure you have read the appropriate description of the mathematics section test (computerized or paper) to understand what is expected of you in the mathematics
MOVIES, GAMBLING, SECRET CODES, JUST MATRIX MAGIC
MOVIES, GAMBLING, SECRET CODES, JUST MATRIX MAGIC DR. LESZEK GAWARECKI 1. The Cartesian Coordinate System In the Cartesian system points are defined by giving their coordinates. Plot the following points:
Test Automation Integration with Test Management QAComplete
Test Automation Integration with Test Management QAComplete This User's Guide walks you through configuring and using your automated tests with QAComplete's Test Management module SmartBear Software Release
Igniting young minds through computer programming
Igniting young minds through computer programming igniting young minds W riting computer programs is a challenging, yet extremely satisfying personal experience that develops essential skills in logic,
A skip list container class in Python
A skip list container class in Python Abstract An alternative to balanced trees John W. Shipman 2012-11-29 13:23 Describes a module in the Python programming language that implements a skip list, a data
PAYCHEX, INC. BASIC BUSINESS MATH TRAINING MODULE
PAYCHEX, INC. BASIC BUSINESS MATH TRAINING MODULE 1 Property of Paychex, Inc. Basic Business Math Table of Contents Overview...3 Objectives...3 Calculator...4 Basic Calculations...6 Order of Operation...9
Introduction to Python
1 Daniel Lucio March 2016 Creator of Python https://en.wikipedia.org/wiki/guido_van_rossum 2 Python Timeline Implementation Started v1.0 v1.6 v2.1 v2.3 v2.5 v3.0 v3.1 v3.2 v3.4 1980 1991 1997 2004 2010
River Dell Regional School District. Computer Programming with Python Curriculum
River Dell Regional School District Computer Programming with Python Curriculum 2015 Mr. Patrick Fletcher Superintendent River Dell Regional Schools Ms. Lorraine Brooks Principal River Dell High School
TWO-DIMENSIONAL TRANSFORMATION
CHAPTER 2 TWO-DIMENSIONAL TRANSFORMATION 2.1 Introduction As stated earlier, Computer Aided Design consists of three components, namely, Design (Geometric Modeling), Analysis (FEA, etc), and Visualization
Python Programming: An Introduction To Computer Science
Python Programming: An Introduction To Computer Science Chapter 8 Booleans and Control Structures Python Programming, 2/e 1 Objectives æ To understand the concept of Boolean expressions and the bool data
Solving Simultaneous Equations and Matrices
Solving Simultaneous Equations and Matrices The following represents a systematic investigation for the steps used to solve two simultaneous linear equations in two unknowns. The motivation for considering
