O'Reilly logo

Python Testing Cookbook. by Bhaskar N. Das, Greg L. Turnquist

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

With these steps, we will investigate what happens when we put too much into a single test method:

  1. Create a new file named recipe8.py to put out application code in for this recipe.
  1. Pick a class to test. In this case, we will use an alternative version of the Roman numeral converter, which converts both ways:
class RomanNumeralConverter(object):     def __init__(self): 
        self.digit_map = {"M":1000, "D":500, "C":100, "L":50, "X":10, "V":5, "I":1} 
 
    def convert_to_decimal(self, roman_numeral): 
        val = 0 
        for char in roman_numeral:         val += self.digit_map[char] 
    return val 
 
    def convert_to_roman(self, decimal):         val = "" 
    while decimal > 1000:         val += "M" 
        decimal -= 1000     while decimal > 500: 
        val += "D" decimal -= 500 while decimal > 100: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required