Update of /cvsroot/webware/Webware/MiscUtils/Testing
In directory usw-pr-cvs1:/tmp/cvs-serv7569
Modified Files:
TestDataTable.py
Log Message:
test for comments; minor code clean
Index: TestDataTable.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiscUtils/Testing/TestDataTable.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** TestDataTable.py 2000/12/04 22:04:55 1.5
--- TestDataTable.py 2001/12/20 20:01:11 1.6
***************
*** 1,12 ****
! import sys
! sys.path.insert(0, '..')
from DataTable import *
import string
# @@ 2000-12-04 ce: We don't test the feature where record like objects, that respond to hasValueForKey() and valueForKey(), can be added to a table (as opposed to a sequence, dictionary or TableRecord instance).
def heading(title):
! print
! print title
--- 1,30 ----
! import FixPath
from DataTable import *
import string
+ from StringIO import StringIO
+
# @@ 2000-12-04 ce: We don't test the feature where record like objects, that respond to hasValueForKey() and valueForKey(), can be added to a table (as opposed to a sequence, dictionary or TableRecord instance).
def heading(title):
! print 'Testing %s...' % title
!
!
! def testSource(name, src, headings, data):
! heading(name+':')
! dt = DataTable()
! lines = split(src, '\n')
! dt.readLines(lines)
! assert [col.name() for col in dt.headings()]==headings
! i = 0
! while i<len(dt):
! match = data[i]
! if dt[i].asList()!=match:
! print 'mismatch'
! print 'i :', i
! print 'match :', match
! print 'dt[i] :', dt[i]
! raise AssertionError
! i = i + 1
***************
*** 39,43 ****
heading('Writing file (CSV):')
! t.writeFile(sys.stdout)
heading('Accessing rows:')
--- 57,69 ----
heading('Writing file (CSV):')
! answer = '''\
! name,age,rating
! John,26,7.2
! Mary,32,8.3
! '''
! out = StringIO()
! t.writeFile(out)
! results = out.getvalue()
! assert results==answer, '\n%r\n%r\n' % (results, answer)
heading('Accessing rows:')
***************
*** 55,78 ****
t.append([4, 5, 6])
assert t[0]['x'] - t[1]['z'] == -5
-
- heading('Quoted values:')
- t = DataTable()
- lines = split('''"x","y,y",z
- a,b,c
- a,b,"c,d"
- "a,b",c,d
- "a","b","c"
- "a",b,"c"
- "a,b,c"
- "","",""
- "a","",
- ''', '\n')
-
- t.readLines(lines)
- assert t.headings()[0].name()=='x'
- assert t.headings()[1].name()=='y,y'
- assert t.headings()[2].name()=='z'
! matches = [
['a', 'b', 'c'],
['a', 'b', 'c,d'],
--- 81,99 ----
t.append([4, 5, 6])
assert t[0]['x'] - t[1]['z'] == -5
! # Basics
! src = '''\
! "x","y,y",z
! a,b,c
! a,b,"c,d"
! "a,b",c,d
! "a","b","c"
! "a",b,"c"
! "a,b,c"
! "","",""
! "a","",
! '''
! headings = ['x', 'y,y', 'z']
! data = [
['a', 'b', 'c'],
['a', 'b', 'c,d'],
***************
*** 84,97 ****
['a', '', '']
]
! i = 0
! while i<len(t):
! match = matches[i]
! if t[i].asList()!=match:
! print 'mismatch'
! print 'i :', i
! print 'match :', match
! print 't[i] :', t[i]
! raise AssertionError
! i = i + 1
print
--- 105,133 ----
['a', '', '']
]
! testSource('Basics', src, headings, data)
!
!
! # Comments
! src = '''\
! a:int,b:int
! 1,2
! #3,4
! 5,6
! '''
! headings = ['a', 'b']
! data = [
! [1, 2],
! [5, 6],
! ]
! testSource('Comments', src, headings, data)
!
! # Multiline records
! src = '''\
! a
! """Hi""",
! '''
! headings = ['a']
! data = ['"Hi"']
! #testSource('Multiline records', src, headings, data)
print
|