Skip to content

Instantly share code, notes, and snippets.

View gregturn's full-sized avatar

Greg L. Turnquist gregturn

View GitHub Profile
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
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
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
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)
import sys
err = sys.stderr
import nose
from nose.plugins import Plugin
class RegexPicker(Plugin):
name = "regexpicker"
def __init__(self):
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 "===================="
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)
$ 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.
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.
@gregturn
gregturn / recipe32.story
Created October 27, 2010 06:33
PyCukes BDD story
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