This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from recipe7 import * | |
class RomanNumeralTester(object): | |
def __init__(self): | |
self.cvt = RomanNumeralConverter() | |
def simple_test(self): | |
print "+++ Converting M to 1000" | |
assert self.cvt.convert_to_decimal("M") == 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from recipe7 import * | |
from recipe7_legacy import * | |
import unittest | |
if __name__ == "__main__": | |
tester = RomanNumeralTester() | |
suite = unittest.TestSuite() | |
for test in [tester.simple_test, tester.combo_test1, \ | |
tester.combo_test2, tester.other_test]: | |
testcase = unittest.FunctionTestCase(test) | |
suite.addTest(testcase) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
err = sys.stderr | |
import nose | |
from nose.plugins import Plugin | |
class RegexPicker(Plugin): | |
name = "regexpicker" | |
def __init__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == "__main__": | |
args = ["", "recipe13", "--with-regexpicker", \ | |
"--re-pattern=test.*|length", "--verbosity=2"] | |
print "With verbosity..." | |
print "====================" | |
nose.run(argv=args, plugins=[RegexPicker()]) | |
print "Without verbosity..." | |
print "====================" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from springpython.context import * | |
from springpython.config import * | |
from pika_client import * | |
from ticker_system import * | |
from buy_low_sell_high import * | |
class AppContext(PythonConfig): | |
def __init__(self): | |
PythonConfig.__init__(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python recipe21_report.py recipe21 | |
=============================== | |
== Processing module recipe21 | |
=============================== | |
Documentation for module recipe21 | |
------------------------------- | |
This is documentation for the this entire recipe. | |
With it, we can demonstrate usage of the code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import doctest | |
class BddDocTestRunner(doctest.DocTestRunner): | |
""" | |
This is a customized test runner. It is meant | |
to run code examples like DocTestRunner, | |
but if a line preceeds the code example | |
starting with '#', then it prints that | |
comment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Story: Shopping cart | |
As a shopper | |
I want to load up items in my cart | |
So that I can check out and pay for them | |
Scenario 1: Empty cart | |
Given an empty cart | |
Then looking up the fifth item causes an error | |
And looking up a negative price causes an error | |
And the price with no taxes is $0.00 |
OlderNewer