My main programming exerience is in Borland's Delphi 5, which suceeded a number of years using Turbo Pascal 7.0 under DOS. So, these new languages like Python, etc al. are a bit odd to me, but I really like the power of the built in dictionaries, tuples, etc.
I'm using an old build of Active State python (2.5.1) which I'll be updating. I managed to write a few modules with very trivial amounts of code, cribbing heavily from "Dive into Python" by Mark Pilgrim.
Here it is... ALL of it...
Translate01.py:
"""Translates internal representation to and from xhtml"""
#define Exceptions
class HtmlError(Exception): pass
class invalidHtmlError(HtmlError): pass
def toHtml(x):
"""convert x to html string"""
return x
def fromHtml(x):
"""convert html string to internal representation"""
return x
Translate01_test.py:
"""Unit test for translate01.py"""
import translate01
import unittest
class KnownValues(unittest.TestCase):
knownValues = ( ( '', ''),
( 'x','x'))
def testToHtmlKnownValues(self):
"""ToHtml should give known results with known input"""
for s1,s2 in self.knownValues:
result = translate01.toHtml(s1)
self.assertEqual(s2,result)
def testFromHtmlKnownValues(self):
"""FromHtml should give known results with known input"""
for s1,s2 in self.knownValues:
result = translate01.fromHtml(s2)
self.assertEqual(s1,result)
if __name__ == "__main__":
unittest.main()
It actually runs.... and tests ok... (because it's trivial right now)
PythonWin 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 32 bit (Intel)] on win32.
Portions Copyright 1994-2006 Mark Hammond - see 'Help/About PythonWin' for further copyright information.
>>> ..
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
So.... I'm on a journey... and I just took the very first step... a thousand miles to go. ;-)
No comments:
Post a Comment