def test01AttributeListModule(self): # Ported to unittest CORALCOOL-2940 print coral.AttributeList.__doc__ list1 = coral.AttributeList() date1 = coral.Date() x = 'a' xType1 = 'in' xType2 = 't' list1.extend(x, xType1 + xType2) list1.extend("bx", "date") list1.extend("c", "int") # AL1 has size 3 list2 = coral.AttributeList() list2.extend("c", "int") list2.extend("d", "long") list2.extend("e", "long double") # AL2 has size 3 list1.merge(list2) # AL1 has now size 5 (c,d,e shared with AL2) list3 = coral.AttributeList() list3.extend("a", "int") list3.extend("b", "date") # NB: AL1 has bx, AL3 has b list3.extend("c", "int") list3.extend("d", "long") list3.extend("e", "long double") # AL3 has size 5 list4 = coral.AttributeList() list4.extend("c", "int") list4.extend("d", "long") list4.extend("e", "long double") # AL4 has size 3 list1[0].setData(100) list1['bx'].setData(date1) list1[2].setData(1000) # also sets it for AL2 list1[3].setData(10000) # also sets it for AL2 list1[4].setData(100000L) # also sets it for AL2 list3.copyData(list1) # NB: weird, copies AL1[bx] into AL3[b] list4.fastCopyData( list2) # NB: no type checking, but c,d,e match types print "---LIST1----" for attr in iter(list1): print attr.data() print "---LIST1----\n", list1 print "---LIST2----\n", list2 print "---LIST3----\n", list3 print "---LIST4----\n", list4 self.assertEqual(list1.size(), len(list1)) self.assertEqual(list1.size(), 5) self.assertEqual(list2.size(), 3) self.assertEqual(list3.size(), 5) self.assertEqual(list4.size(), 3) self.assertTrue(list1 != list2) self.assertTrue( list1 == list3) # WEIRD! Element names [2] differ, bx!=b self.assertEqual(list1, list3) # WEIRD as above... self.assertTrue(list3 != list4) self.assertTrue(list2 == list4)
import coral import unittest theDay, anotherDay, otherDay, someDifferentDay = coral.Date(), coral.Date( 2006, 9, 10), coral.Date(day=10, month=9, year=2006), coral.Date(2007) class PyCoralDateTest(unittest.TestCase): def setUp(self): print('[OVAL] setUp') def testDateModule(self): print('[OVAL] Test PyCoral Date Module') print(coral.Date.__doc__) print("theDay :: ", theDay.day(), "/", theDay.month(), "/", theDay.year()) print("anotherDay:: ", anotherDay.day(), "/", anotherDay.month(), "/", anotherDay.year()) print("otherDay:: ", otherDay.day(), "/", otherDay.month(), "/", otherDay.year()) print("someDifferentDay:: ", someDifferentDay.day(), "/", someDifferentDay.month(), "/", someDifferentDay.year()) print("-----------------------------") print("Note: Comparison result 0 = True, -1 = False OR Error") print("-----------------------------") print("Camparison Results of anotherDay & otherDay =", cmp(anotherDay, otherDay)) print("Camparison Results of anotherDay & someDifferentDay =", cmp(anotherDay, someDifferentDay))
description.setName("T") description.insertColumn("ID", "int") description.setPrimaryKey("ID") description.insertColumn("TheDate", "date") description.insertColumn("TheTime", "time stamp", 6) print("About to create the table") table = schema.createTable(description) rowBuffer = coral.AttributeList() table.dataEditor().rowBuffer(rowBuffer) for i in range(0, 5): rowBuffer["ID"].setData(i) rowBuffer["TheDate"].setData(coral.Date(2005, 11, i + 1)) rowBuffer["TheTime"].setData(coral.TimeStamp()) table.dataEditor().insertRow(rowBuffer) bulkInserter = table.dataEditor().bulkInsert(rowBuffer, 3) fraction = 111111111 for i in range(5, 10): fraction = fraction / 10 rowBuffer["ID"].setData(i) rowBuffer["TheDate"].setData(coral.Date(2005, 11, i + 1)) thisMoment = coral.TimeStamp() rowBuffer["TheTime"].setData( coral.TimeStamp(thisMoment.year(), thisMoment.month(), thisMoment.day(), thisMoment.hour(), thisMoment.minute(), thisMoment.second(),
def checkData(i): try: global m_rowBuffer row = m_rowBuffer if (row[0].data() != i): raise Exception("Unexpected value for variable ", row[0].specification().name()) if (i % 3 == 0): if (not row[1].isNull()): raise Exception("Unexpected NOTNULL data for variable ", row[1].specification().name()) else: if (row[1].isNull()): raise Exception("Unexpected NULL data for variable ", row[1].specification().name()) if (i % 2 == 0): temp = True else: temp = False if (row[1].data() != temp): raise Exception("Unexpected value for variable ", row[1].specification().name()) if (row[2].data() != (i * 2) % 256): raise Exception("Unexpected value for variable ", row[2].specification().name()) if (ord(row[3].data()) != (i * 2) % 128): raise Exception("Unexpected value for variable ", row[3].specification().name()) if (row[4].data() != (i * 3) % 2048): raise Exception("Unexpected value for variable ", row[4].specification().name()) if (row[5].data() != (i * 3) % 2048 - 1024): raise Exception("Unexpected value for variable ", row[5].specification().name()) if (row[6].data() != (i * 4) % 1000): raise Exception("Unexpected value for variable ", row[6].specification().name()) if (row[7].data() != (i * 4) % 1000 - 500): raise Exception("Unexpected value for variable ", row[7].specification().name()) if (row[8].data() != (i * 4) % 1001): raise Exception("Unexpected value for variable ", row[8].specification().name()) if (row[9].data() != (i * 4) % 1001 - 500): raise Exception("Unexpected value for variable ", row[9].specification().name()) if (row[10].data() != i % 123456789): raise Exception("Unexpected value for variable ", row[10].specification().name()) if (row[11].data() != i % 123456789 - 500): raise Exception("Unexpected value for variable ", row[11].specification().name()) if (i % 4 == 0): if (not row[12].isNull()): raise Exception("Unexpected NOTNULL data for variable ", row[12].specification().name()) else: if (row[12].isNull()): raise Exception("Unexpected NULL data for variable ", row[12].specification().name()) if (abs(row[12].data() / (i + 0.123) - 1) > 1e-324): raise Exception("Unexpected value for variable ", row[12].specification().name()) if (abs(row[13].data() / (0.123456789 - 2.3 * i) - 1) > 1e-324): raise Exception("Unexpected value for variable ", row[13].specification().name()) if (abs(row[14].data() / (0.123456789 + 2.3 * i) - 1) > 1e-324): raise Exception("Unexpected value for variable ", row[14].specification().name()) blob = row[15].data() p1 = pickle.load(blob) blobSize = 1000 * (i % 100 + 1) if (len(p1) != blobSize): raise Exception("Unexpected blob size for variable ", row[15].specification().name()) for j in range(0, blobSize): if (p1[j] != (i + j) % 256): raise Exception("Unexpected value for variable ", row[15].specification().name()) if (row[16].data() != coral.Date(2006, 1, i % 31 + 1)): raise Exception("Unexpected value for variable ", row[16].specification().name()) if (row[17].data() != coral.TimeStamp(2006, 1, 12, 15, 47, i % 60, 0)): raise Exception("Unexpected value for variable ", row[17].specification().name()) os1 = "A general String : " + str(i % 5) s1 = str(os1) if (row[18].data() != s1): raise Exception("Unexpected value for variable " + row[18].specification().name()) os2 = "...." + str(i % 10) s2 = str(os2) if (row[19].data() != s2): raise Exception("Unexpected value for variable ", row[19].specification().name()) os3 = "Value : " + str(i) s3 = str(os3) if (row[20].data() != s3): raise Exception("Unexpected value for variable ", row[20].specification().name()) print "CheckData SUCCESS " except Exception, e: raise Exception("CheckData FAILURE " + str(e))
def fillData(i): try: global m_rowBuffer row = m_rowBuffer row[0].setData(i) if (i % 3 == 0): row[1].setData(None) else: if (i % 2 == 0): temp = True else: temp = False row[1].setData(temp) row[2].setData((i * 2) % 256) row[3].setData((i * 2) % 128) row[4].setData((i * 3) % 2048) row[5].setData((i * 3) % 2048 - 1024) row[6].setData((i * 4) % 1000) row[7].setData((i * 4) % 1000 - 500) row[8].setData((i * 4) % 1001) row[9].setData((i * 4) % 1001 - 500) row[10].setData(i % 123456789) row[11].setData(i % 123456789 - 500) if (i % 4 == 0): row[12].setData(None) else: row[12].setData(i + 0.123) row[13].setData(0.123456789 - 2.3 * i) row[14].setData(0.123456789 + 2.3 * i) blob = coral.Blob() row[15].setData(blob) blobSize = 1000 * (i % 100 + 1) #blob.resize( blobSize ); p = [] for j in range(0, blobSize): p.append((i + j) % 256) pickle.dump(p, blob, True) row[15].setData(blob) row[16].setData(coral.Date(2006, 1, i % 31 + 1)) row[17].setData(coral.TimeStamp(2006, 1, 12, 15, 47, i % 60, 0)) os1 = "A general String : " + str(i % 5) s1 = str(os1) row[18].setData(s1) os2 = "...." + str(i % 10) s2 = str(os2) row[19].setData(s2) os3 = "Value : " + str(i) s3 = str(os3) row[20].setData(s3) print "FillData SUCCESS " except Exception, e: raise Exception("FillData FAILURE " + str(e))
import os import coral import unittest import sys #startRef = sys.gettotalrefcount() #endRef = sys.gettotalrefcount() dateData = coral.Date(year=2006, month=10, day=10) timeStampData = coral.TimeStamp() blobData = coral.Blob() aList1 = coral.AttributeList() aList2 = coral.AttributeList() class PyCoralAttributeListTest(unittest.TestCase): def setUp(self): print '[OVAL] setUp' print coral.AttributeList.__doc__ def testAttributeListSimpleData(self): print '[OVAL] testAttributeListSimpleData' # Extend AttributeList aList1.extend("c", "char") aList1.extend("i", "int") aList1.extend("dd", "date") aList1.extend("tm", "time stamp") aList1.extend("blob1", "blob") aList1.extend("floatVar", "float") aList1.extend("uSlongVar", "unsigned long")
import coral import unittest date1 = coral.Date() date2 = coral.Date(2007,9,10) timestamp1 = coral.TimeStamp() timestamp2 = coral.TimeStamp(2007, 12, 21, 12, 10, 30, 10000000) blob1 = coral.Blob(100) blob2 = coral.Blob(200) list1 = coral.AttributeList() list1.extend("a","date") list1.extend("b","time stamp") list1.extend("c","blob") list1BeforeMerging = len(list1) list1[0].setData(date1) list1[1].setData(timestamp1) list1[2].setData(blob1) print("------------------------------------------------------") print("Length of list1 before merging = " , list1BeforeMerging) print("Contents of list1 before merging") for attr in list1: print("Atribute Name =" , attr.specification().name() , ":TypeName =" , attr.specification().typeName() , ":Value = " , attr.data()) print("------------------------------------------------------") list2 = coral.AttributeList() list2.extend("c","blob") list2.extend("d","time stamp") list2.extend("e","date") list2BeforeMerging = len(list2) list2[0].setData(blob1)
w[0].setData(None) print("Element w[0] isNull OR not after setData(None): ", w[0].isNull()) print(str(w[0])) w[0].shareData(w[1]) print("Elements w[0] and w[1] after shareData = ", str(w[0]), str(w[1])) spec = w[0].specification() print("Attribute Specification details of w[0] = ", spec.name(), spec.typeName()) print(str(spec)) print("Comparison Results of specifications of w[0] and w[1] = ", cmp(w[0].specification(), w[1].specification())) print("Comparison Results of specifications of z[2] and w[2] = ", cmp(z[2].specification(), w[2].specification())) f = coral.Date() g = coral.TimeStamp() h = coral.Blob() w.extend("f", "date") w.extend("g", "time stamp") w.extend("h", "blob") li1 = [] li2 = [] for j in range(1, 500): li1.append(j) del j pickle.dump(li1, h, 1)
import coral import sys import unittest date1 = coral.Date() list1 = coral.AttributeList() x = 'a' xType1 = 'in' xType2 = 't' list1.extend(x, xType1 + xType2) list1.extend("bx", "date") list1.extend("c", "int") list2 = coral.AttributeList() list2.extend("c", "int") list2.extend("d", "long") list2.extend("e", "long double") list1.merge(list2) list3 = coral.AttributeList() list3.extend("a", "int") list3.extend("b", "date") list3.extend("c", "int") list3.extend("d", "long") list3.extend("e", "long double") list4 = coral.AttributeList() list4.extend("c", "int") list4.extend("d", "long") list4.extend("e", "long double")