コード例 #1
0
ファイル: testrete1.py プロジェクト: affinitydb/python
                lLeftCn = "http://testrete1/hier/cb%dto%d" % (pFrom, lMid)
                self.mDbConn.q("CREATE CLASS \"%s\" AS SELECT * FROM \"%s\" WHERE \"http://testrete1/hier/v\" >= %d AND \"http://testrete1/hier/v\" <= %d" % (lLeftCn, pBase, pFrom, lMid))
            else:
                lLeftCn = pBase                
            self.createClasses(pFrom, lMid, lLeftCn)
            # right
            if lMid + 1 < pTo:
                lRightCn = "http://testrete1/hier/cb%dto%d" % (lMid + 1, pTo)
                self.mDbConn.q("CREATE CLASS \"%s\" AS SELECT * FROM \"%s\" WHERE \"http://testrete1/hier/v\" >= %d AND \"http://testrete1/hier/v\" <= %d" % (lRightCn, pBase, lMid + 1, pTo))
            else:
                lRightCn = pBase
            self.createClasses(lMid + 1, pTo, lRightCn)
    def run(self):
        for iC in xrange(TESTRETE1_NUMCHECKS):
            self.mDbConn.q("INSERT \"http://testrete1/hier/v\"=%d" % (random.randrange(0, TESTRETE1_NUMCLASSES)))
    def check(self):
        lTot = 0
        for iC in xrange(TESTRETE1_NUMCLASSES):
            lTot += self.mDbConn.qCount("SELECT * FROM \"http://testrete1/hier/c%d\"" % iC)
        return lTot

class TestRete1(AffinityTest):
    "A basic test for flat vs hierarchical classification."
    def execute(self):
        _entryPoint()
AffinityTest.declare(TestRete1)

if __name__ == '__main__':
    lT = TestRete1()
    lT.execute()
コード例 #2
0
ファイル: testphotos1.py プロジェクト: affinitydb/python
        print ("user %s has tags %s" % (_pUser, _lTags))
        _lExpectedTags = lInMemoryChk.getUserTags(_pUser)
        if len(_lExpectedTags.difference(_lTags)) > 0:
            print ("WARNING: expected tags %s" % _lExpectedTags.difference(_lTags))
            assert False
        _lPhotos = _getpins("SELECT * FROM \"http://localhost/afy/class/testphotos1/photo\" AS p JOIN \"http://localhost/afy/class/testphotos1/tagging\" AS t ON (p.\"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#hasHash\" = t.\"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#hasHash\") WHERE t.\"http://code.google.com/p/tagont/hasTagLabel\" IN (%s);" % ','.join([("'%s'" % _iT) for _iT in _lTags]))
        _lUniquePhotos = set()
        for _iP in _lPhotos:
            _lUniquePhotos.add(_iP["http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#hasHash"])
        if len(_lPhotos) != len(_lUniquePhotos):
            print ("non-unique: %s unique: %s" % (len(_lPhotos), len(_lUniquePhotos)))
        return len(_lUniquePhotos)
    for iU in lUsersOfInterest:
        lCntPhotos = _countUserPhotos(iU["http://code.google.com/p/tagont/hasVisibility"])
        _chkCount("photos that can be viewed by %s" % iU["http://code.google.com/p/tagont/hasVisibility"], _pExpected=lInMemoryChk.countPhotos(iU["http://code.google.com/p/tagont/hasVisibility"]), _pActual=lCntPhotos)
    if False:
        # Output the final state.
        print (_getpins("SELECT *;"))
    # Close everything.
    lAffinity.close()

class TestPhotos1(AffinityTest):
    "A simple application talking to the store through pathSQL only, and using a relational model with joins."
    def execute(self):
        _entryPoint()
AffinityTest.declare(TestPhotos1)

if __name__ == '__main__':
    lT = TestPhotos1()
    lT.execute()
コード例 #3
0
            pHandlerData=time.time(),
            pGroupNotifs=True,
        )
        print(" sleeping 10 seconds")
        time.sleep(10)
        with CheckCounts(0, 1):
            print("15. change related pin %s" % lNewPins[1].mPID)
            lNewPins[1]["http://localhost/afy/property/testnotifications1/name"] = "Pablo"
            print(" sleeping 20 seconds")
            time.sleep(20)
        with CheckCounts(0, 1):
            print("16. change related pin %s" % lNewPins[1].mPID)
            lNewPins[1]["http://localhost/afy/property/testnotifications1/name"] = "Paolo"
            time.sleep(1)
        print("17. unregister")
        AFYNOTIFIER.unregisterClass("http://localhost/afy/class/testnotifications1/Named", onClassNotif)


class TestNotifications1(AffinityTest):
    "A basic test for notifications."

    def execute(self):
        _entryPoint()


AffinityTest.declare(TestNotifications1)

if __name__ == "__main__":
    lT = TestNotifications1()
    lT.execute()
コード例 #4
0
    # print "JSON result: %s" % lAffinity.check("SELECT * FROM cars AS c JOIN workers(@['d', 'n']) AS w ON (c.afy:pinID = w.cars) WHERE (c.year IN @[1980, 2000]);")
    print "Start step11"
    pins = PIN.loadPINs(lAffinity.qProto("SELECT * FROM cars AS c JOIN workers(@['d', 'n']) AS w ON (c.afy:pinID = w.cars) WHERE (c.year IN @[1980, 2000]);"))
    assert len(pins) > 0
    print "Step11 complete!" 

    # for repro bug#302
    lAffinity.q("DELETE FROM *;")
    assert lAffinity.qCount("select * where not exists(afy:predicate)") == 0
    lAffinity.close()	
    print "Test tutorial complete!"
    return True

def _entryPoint():
    start = time.time()
    test_executable_doc() # TODO: Review... doesn't seem happy...
    test_tutorial()
    end = time.time()
    print "TestOnlineMaterials costs : " + timeToString(end - start)
    
class TestOnlineMaterials(AffinityTest):
    def execute(self):
        _entryPoint()

AffinityTest.declare(TestOnlineMaterials)

if __name__ == '__main__':
    lT = TestOnlineMaterials()
    lT.execute()

コード例 #5
0
ファイル: testrules.py プロジェクト: affinitydb/python
            cnt=cnt+1
        sql = "INSERT OPTIONS(TRANSIENT) temperature="+ str(temperature) +",distance=" + str(distance)
        lAffinity.q(sql)

    lPins = PIN.loadPINs(lAffinity.qProto("SELECT * FROM #count_fire_warning"))

    print "==> Totally " + str(cnt) + " fire warnings are detected!"
    assert lPins[0]['fire_warning_cnt'] == cnt
    
    lAffinity.close()
    return True 

def _entryPoint():
    start = time.time()
    test_case_1()
    print "Test rules complete!"
    end = time.time()
    print "Testrules costs : " + timeToString(end - start)
    
class TestRules(AffinityTest):
    def execute(self):
        _entryPoint()

AffinityTest.declare(TestRules)

if __name__ == '__main__':
    lT = TestRules()
    lT.execute()
    

コード例 #6
0
ファイル: testtypes1.py プロジェクト: affinitydb/python
    lPin = PIN.loadPINs(lAffinity.qProto("INSERT (\"http://localhost/afy/property/testtypes1/value1\") VALUES (&%s.\"http://localhost/afy/property/testtypes1/value1\"[%d]);" % (lReferenced1.mPID, lValue.mEid)))[0]
    lPin['http://localhost/afy/property/testtypes1/value2'] = lValue
    lPin.refreshPIN()
    assert lValue == lPin['http://localhost/afy/property/testtypes1/value1']
    assert lValue == lPin['http://localhost/afy/property/testtypes1/value2']
    assert affinity_pb2.Value.VT_REFIDELT == lPin.getExtra('http://localhost/afy/property/testtypes1/value1').mType
    assert affinity_pb2.Value.VT_REFIDELT == lPin.getExtra('http://localhost/afy/property/testtypes1/value2').mType    

    # TODO: VT_EXPR
    # TODO: VT_QUERY
    # TODO: VT_CURRENT - available?
    # TODO: VT_ENUM - available?
    # TODO: VT_DECIMAL - available?
    # TODO: VT_URIID - purpose? vs VT_REFID?
    # TODO: VT_IDENTITY - purpose?
    # TODO: VT_REFCID - purpose?
    # TODO: VT_RANGE - purpose?
    # NOTE: VT_ARRAY is tested with collections.

    lAffinity.close()

class TestTypes1(AffinityTest):
    "A basic test for native data types (python and Affinity)."
    def execute(self):
        _entryPoint()
AffinityTest.declare(TestTypes1)

if __name__ == '__main__':
    lT = TestTypes1()
    lT.execute()
コード例 #7
0
ファイル: testbasics1.py プロジェクト: affinitydb/python
    if len(lPBStream.pins) > 1:
        print ("\nA basic PIN modification test (ISession::modify style).")
        lPid = lPBStream.pins[1].id
        print ("before modify: %s" % lAffinity.check("SELECT * FROM {@%x};" % lPid.id))
        lPin = PIN({PIN.SK_PID:PIN.PID.fromPB(lPid), "http://localhost/afy/property/testbasics1/myprop1":"bien"})
        #lPin = PIN(__PID__=PIN.PID.fromPB(lPid), testbasics1_myprop1="bien")
        lPin.savePIN()
        print ("after modify: %s" % lAffinity.check("SELECT * FROM {@%x};" % lPid.id))

    if len(lPBStream.pins) > 1:
        print ("\nA basic PIN deletion test.")
        lPid = lPBStream.pins[1].id
        print ("before delete: %s" % lAffinity.check("SELECT * FROM {@%x};" % lPid.id))
        PIN.deletePINs([PIN.PID.fromPB(lPid)])
        #print ("after delete: %s" % lAffinity.check("SELECT * FROM {@%x};" % lPid.id))

    #print ("\nFinal state check.")
    #print (lAffinity.check("SELECT *"))
    lAffinity.close()

class TestBasics1(AffinityTest):
    "First basic test (originally written for testgen/python)."
    def execute(self):
        _entryPoint()
AffinityTest.declare(TestBasics1)

if __name__ == '__main__':
    lT = TestBasics1()
    lT.execute()
コード例 #8
0
ファイル: testbasicpathsql.py プロジェクト: affinitydb/python
    assert 1 == lAffinity.qCount("SELECT color FROM houses(1).doors WHERE doorid=2;")
    assert 3 == lAffinity.qCount("SELECT color FROM houses(1).doors")
    assert 3 == lAffinity.qCount("SELECT color FROM houses.doors;") 

    lAffinity.close()
    return True  

def _entryPoint():
    # test cases are executed here
    start = time.time()
    TEST = 'test_case_'
    cnt = 0
    for i in range(1, 49):
        eval(TEST+str(i)+'()')
        cnt+=1
    
    end = time.time()
    print "Totally " + str(cnt) + " cases have been tested."
    print "TestBasicPathSQL costs : " + timeToString(end - start)
    
class TestBasicPathSQL(AffinityTest):
    def execute(self):
        _entryPoint()

AffinityTest.declare(TestBasicPathSQL)

if __name__ == '__main__':
    lT = TestBasicPathSQL()
    lT.execute()

コード例 #9
0
ファイル: testtransient.py プロジェクト: affinitydb/python
    # verify the results
    assert lAffinity.qCount("select * where exists(T6_P2);") == (TOTAL - cnt)
    assert lAffinity.qCount("SELECT * FROM T6_LEV_C1;") == cnt
    lAffinity.close()
    print "Test test_case_6 complete!"
    return True

def _entryPoint():
    start = time.time()
    test_case_1()
    test_case_2()
    test_case_3()
    #test_case_4()
    test_case_5()
    test_case_6()
    end = time.time()
    print "Test transient pins complete!"
    print "TestTransient costs : " + timeToString(end - start)
    
class TestTransient(AffinityTest):
    def execute(self):
        _entryPoint()

AffinityTest.declare(TestTransient)

if __name__ == '__main__':
    lT = TestTransient()
    lT.execute()

コード例 #10
0
ファイル: testcollections1.py プロジェクト: affinitydb/python
        lCollection3b = list(lCollection3)
        checkPersistedProp("comparing reloaded testcollections1/mycoll3 to lCollection3", lPin1, "http://localhost/afy/property/testcollection1/mycoll3", lCollection3b)
        while len(lCollection3b) > 1:
            del lPin1["http://localhost/afy/property/testcollection1/mycoll3"][0]
            del lCollection3b[0]
            if 0 != cmp(lPin1["http://localhost/afy/property/testcollection1/mycoll3"], lCollection3b):
                reportError("comparing in-memory testcollections1/mycoll3 to lCollection3b, after deletion of element")
            checkPersistedProp("comparing reloaded testcollections1/mycoll3 to lCollection3b, after deletion of element", lPin1, "http://localhost/afy/property/testcollection1/mycoll3", lCollection3b)
        del lPin1["http://localhost/afy/property/testcollection1/mycoll3"]
        try:
            if lPin1.has_key("http://localhost/afy/property/testcollection1/mycoll3") or lPin1.getExtra("http://localhost/afy/property/testcollection1/mycoll3"):
                reportError("retrieving testcollection1/mycoll3 after deletion of the property")
        except Exception as ex:
            #print repr(ex)
            pass
        lPinChk = PIN.createFromPID(lPin1.mPID)
        if lPinChk.has_key("http://localhost/afy/property/testcollection/mycoll3"):
            reportError("retrieving testcollection1/mycoll3 after deletion of the property, on reloaded pin")

    lAffinity.close()

class TestCollections1(AffinityTest):
    "A basic test for collections."
    def execute(self):
        _entryPoint()
AffinityTest.declare(TestCollections1)

if __name__ == '__main__':
    lT = TestCollections1()
    lT.execute()