Commit 3c206d0a authored by Sidnei da Silva's avatar Sidnei da Silva

- Merge a fix from the five-integration branch, with a test.

parents 5573608a 583028d8
...@@ -141,9 +141,9 @@ class DatabaseResults: ...@@ -141,9 +141,9 @@ class DatabaseResults:
setattr(r,k,getattr(Record,k)) setattr(r,k,getattr(Record,k))
# Add SQL Aliases # Add SQL Aliases
d=r.__dict__
for k, v in aliases: for k, v in aliases:
if not hasattr(r,k): d[k]=v if not hasattr(r,k):
setattr(r, k, v)
if hasattr(brains, '__init__'): if hasattr(brains, '__init__'):
binit=brains.__init__ binit=brains.__init__
...@@ -152,8 +152,7 @@ class DatabaseResults: ...@@ -152,8 +152,7 @@ class DatabaseResults:
Record.__init__(self,data) Record.__init__(self,data)
binit(self.__of__(parent)) binit(self.__of__(parent))
r.__dict__['__init__']=__init__ setattr(r, '__init__', __init__)
self._class=r self._class=r
......
...@@ -71,9 +71,9 @@ class Results: ...@@ -71,9 +71,9 @@ class Results:
setattr(r,k,getattr(Record,k)) setattr(r,k,getattr(Record,k))
# Add SQL Aliases # Add SQL Aliases
d=r.__dict__
for k, v in aliases: for k, v in aliases:
if not hasattr(r,k): d[k]=v if not hasattr(r, k):
setattr(r, k, v)
if hasattr(brains, '__init__'): if hasattr(brains, '__init__'):
binit=brains.__init__ binit=brains.__init__
...@@ -83,7 +83,7 @@ class Results: ...@@ -83,7 +83,7 @@ class Results:
if parent is not None: self=self.__of__(parent) if parent is not None: self=self.__of__(parent)
binit(self) binit(self)
r.__dict__['__init__']=__init__ setattr(r, '__init__', __init__)
self._class=r self._class=r
......
from unittest import TestCase, TestSuite, makeSuite, main
from cStringIO import StringIO
from ExtensionClass import Base
from Shared.DC.ZRDB.Results import Results
from Shared.DC.ZRDB import RDB
class Brain:
def __init__(self, *args): pass
Parent = Base()
class TestResults(TestCase):
def test_results(self):
r = Results(([{'name':'foo', 'type':'integer'},
{'name':'bar', 'type':'integer'}],
((1, 2), (3, 4))),
brains=Brain,
parent=Parent)
self.assertEquals(len(r), 2)
row = r[0]
self.assertEquals(row[0], 1)
self.assertEquals(row[1], 2)
self.assertEquals(row.foo, 1)
self.assertEquals(row.bar, 2)
self.assertEquals(row.FOO, 1)
self.assertEquals(row.BAR, 2)
row = r[1]
self.assertEquals(row[0], 3)
self.assertEquals(row[1], 4)
self.assertEquals(row.foo, 3)
self.assertEquals(row.bar, 4)
self.assertEquals(row.FOO, 3)
self.assertEquals(row.BAR, 4)
self.failUnless(isinstance(row, Brain))
def test_rdb_file(self):
infile = StringIO("""\
foo\tbar
2i\t2i
1\t2
3\t4\
""")
r = RDB.File(infile,
brains=Brain,
parent=Parent)
self.assertEquals(len(r), 2)
row = r[0]
self.assertEquals(row[0], 1)
self.assertEquals(row[1], 2)
self.assertEquals(row.foo, 1)
self.assertEquals(row.bar, 2)
self.assertEquals(row.FOO, 1)
self.assertEquals(row.BAR, 2)
row = r[1]
self.assertEquals(row[0], 3)
self.assertEquals(row[1], 4)
self.assertEquals(row.foo, 3)
self.assertEquals(row.bar, 4)
self.assertEquals(row.FOO, 3)
self.assertEquals(row.BAR, 4)
self.failUnless(isinstance(row, Brain))
def test_suite():
return TestSuite((makeSuite(TestResults),))
if __name__ == '__main__':
main(defaultTest='test_suite')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment