Skip to content

Instantly share code, notes, and snippets.

View gregturn's full-sized avatar

Greg L. Turnquist gregturn

View GitHub Profile
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 "===================="
import sys
err = sys.stderr
import nose
from nose.plugins import Plugin
class RegexPicker(Plugin):
name = "regexpicker"
def __init__(self):
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)
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
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