List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:May 8 2007 2:03am
Subject:Rev 116: Added initial python unittests. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmerge
View as plain text  
------------------------------------------------------------
revno: 116
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: ndbjmerge
timestamp: Mon 2007-05-07 19:02:57 -0700
message:
  Added initial python unittests. 
  Cleaned up some stray code.
  Turned verbose into a bool in NdbClusterConnection.connect(), since it is.
added:
  python/mysql/cluster/tests/    tests-20070506071012-vi3f0brgl104dpdk-1
  python/mysql/cluster/tests/NdbTest.py ndbtest.py-20070508020252-wxtaxhe2iwj8es5c-1
  python/mysql/cluster/tests/__init__.py __init__.py-20070506071012-vi3f0brgl104dpdk-2
modified:
  python/ndbapi.i               
svn-v2:1@5fca6d9a-db22-0410-b55c-899b0a28da89-trunk-python%2fndb.i
  python/setup.py.in            
svn-v2:1@5fca6d9a-db22-0410-b55c-899b0a28da89-trunk-python%2fsetup.py
  swig/NdbClusterConnection.i    ndb_cluster_connecti-20070228021421-qkr4cbpxymyqdrf3-6
  swig/NdbFactory.i              ndbfactory.i-20070427052328-bwn5ewzrbigsg9v5-1
=== added directory 'python/mysql/cluster/tests'
=== added file 'python/mysql/cluster/tests/NdbTest.py'
--- a/python/mysql/cluster/tests/NdbTest.py	1970-01-01 00:00:00 +0000
+++ b/python/mysql/cluster/tests/NdbTest.py	2007-05-08 02:02:57 +0000
@@ -0,0 +1,90 @@
+import ClusterTestCase
+from mysql.cluster import ndbapi
+import unittest
+
+class NdbTest(ClusterTestCase.ClusterTestCase):
+
+
+    PRIMARYKEYINDEXNAME = "PRIMARY"
+    
+    TABLE1 = "table1"
+    TABLE2 = "table2"
+    TABLE3 = "table3"
+    key1   = "k1"
+    key2   = "k2"
+    data1  = "d1"
+    data2  = "d2"
+    data3  = "d3"
+    data4  = "d4"
+    data5  = "d5"
+    data6  = "d6"
+    data7  = "d7"
+    
+    rowTable1 = "rob"
+    rowTable2 = "james"
+    rowTable3 = "maeve"
+
+
+    def setUp(self):
+        super(NdbTest, self).setUp()
+        
+        self.createTable(self.TABLE1,"""
+        ( k1 VARCHAR(30) NOT NULL, d1 VARCHAR(20),
+        d2 INTEGER, primary key (k1) ) engine=ndbcluster;""")
+
+        self.createTable(self.TABLE2,"""
+        ( k1 VARCHAR(256) NOT NULL, k2 INTEGER NOT NULL, d1 VARCHAR(256),
+        d2 INTEGER, primary key (k1, k2) ) engine=ndbcluster;""")
+
+        self.createTable(self.TABLE3,"""
+        ( k1 VARCHAR(256) NOT NULL, d1 TIMESTAMP, d2 CHAR(1),
+        d3 VARBINARY(100), d4 BLOB, d5 TEXT, d6 BIGINT,
+        d7 BLOB, PRIMARY KEY (k1)) engine=ndbcluster;""")
+
+    def testInsertTable1(self):
+
+        trans = self.ndb.startTransaction();
+        
+        op = trans.getNdbOperation(self.TABLE1);
+        
+        op.insertTuple();
+        
+        op.setString( self.key1, self.rowTable1)
+        op.setNull( self.data1  )
+        op.setInt(self.data2, 42)
+        
+        trans.execute(ndbapi.NoCommit)
+        
+        trans.execute(ndbapi.Commit)
+        
+        trans.close()
+
+    def runInsertTable1(self):
+        trans = self.ndb.startTransaction();
+        
+        op = trans.getNdbOperation(self.TABLE1);
+        
+        op.insertTuple();
+        
+        op.setString( self.key1, self.rowTable1)
+        op.setString( self.data1 , "mynewvalue" )
+        op.setInt(self.data2, 42)
+        
+        trans.execute(ndbapi.NoCommit)
+            
+        trans.execute(ndbapi.Commit)
+        trans.close()
+        
+    def testInsertTable1ExcpetingError(self):
+
+        self.assertRaises(ndbapi.NdbApiException,self.runInsertTable1,self)
+
+                    
+
+
+test_all = unittest.TestLoader().loadTestsFromTestCase(NdbTest)
+        
+if __name__=="__main__":
+    #unittest.main()
+    
+    unittest.TextTestRunner(verbosity=2).run(suite)

=== added file 'python/mysql/cluster/tests/__init__.py'
=== modified file 'python/ndbapi.i'
--- a/python/ndbapi.i	2007-05-06 02:34:17 +0000
+++ b/python/ndbapi.i	2007-05-08 02:02:57 +0000
@@ -67,12 +67,10 @@
 
 %runtime %{
 
-// Include python/datetime.h - in case we need to make this more robust
-
+// Include python/datetime.h
 
   #include <datetime.h>
   
-  
   %}
 
 
@@ -192,17 +190,10 @@
 
 %init %{
 
-  // PyObject *m, *d; - m==module d==module.__dict__
   ndb_init();
   
-
   PyDateTime_IMPORT;
 
-/*
-  PyExc_NdbApiException =
PyErr_NewException("mysql.cluster.ndbapi.NdbApiException",NULL,NULL);
-  PyDict_SetItemString(d,"NdbApiException",PyExc_NdbApiException);
-  Py_INCREF(PyExc_NdbApiException);
-*/
   NEW_pyexcept(NdbApiException,NULL);
   NEW_pyexcept(NdbApiRuntimeException,PyExc_NdbApiException);
   NEW_pyexcept(NdbApiPermanentException,PyExc_NdbApiException);
@@ -216,22 +207,10 @@
   NEW_pyexcept(NoSuchIndexException,PyExc_NdbApiException);
   NEW_pyexcept(NoSuchTableException,PyExc_NdbApiException);
 
-
 %}
 
-%feature("shadow") NdbOperation::setValue %{
-#  %pythoncode %{
-def setValue(self,name,value,length=None):
-  if isinstance(value,"".__class__):
-    value="%c%s" % (len(value),value)
-  if length is None:
-    return _ndbapi.NdbOperation_setVal(self,name,value)
-  return _ndbapi.NdbOperation_setVal(self,name,value,length)
-     %}
-
 %include "NdbOperation.i"
 
-
 %include "NdbScanOperation.i"
 
 %include "NdbRecAttr.i"
@@ -259,7 +238,7 @@
     day = ret % 100
     ret = "%s-%s-%s" % (year,month,day)
   else:
-    raise Exception, "unknown type"
+    raise NdbApiException, "unknown type"
   return ret
   
     %}

=== modified file 'python/setup.py.in'
--- a/python/setup.py.in	2007-04-23 23:09:49 +0000
+++ b/python/setup.py.in	2007-05-08 02:02:57 +0000
@@ -123,6 +123,7 @@
                               )
 
                     ],
+      test_suite = "mysql.cluster.tests.NdbTest.test_all",
       entry_points = {
         'sqlalchemy.databases': [ 'ndbapi = mysql.cluster.alchemy:dialect' ]
       },

=== modified file 'swig/NdbClusterConnection.i'
--- a/swig/NdbClusterConnection.i	2007-05-07 08:12:56 +0000
+++ b/swig/NdbClusterConnection.i	2007-05-08 02:02:57 +0000
@@ -42,22 +42,12 @@
 	NDB_exception(NdbApiException,msg);
       }
   }
-  %typemap(check) int no_retries {
-    if ($1 < 0) { 
-      NDB_exception(NdbClusterConnectionPermanentException,"Retries must be greater than
or equal to zero.");
-    }
-  }
   %typemap(check) int retry_delay_in_seconds {
     if ($1 < 0) { 
       NDB_exception(NdbClusterConnectionPermanentException,"Delay must be greater than or
equal to zero.");
     }
   }
-  %typemap(check) int verbose {
-    if ($1 < 0 || $1 > 1) { 
-      NDB_exception(NdbClusterConnectionPermanentException,"Verbose must be either zero
or one.");
-    }
-  }
-  int connect(int no_retries=0, int retry_delay_in_seconds=1, int verbose=0);
+  int connect(int no_retries=0, int retry_delay_in_seconds=1, bool verbose=0);
 
 #if defined(SWIGJAVA)
   %javaexception("NdbApiException") {

=== modified file 'swig/NdbFactory.i'
--- a/swig/NdbFactory.i	2007-05-07 08:12:56 +0000
+++ b/swig/NdbFactory.i	2007-05-08 02:02:57 +0000
@@ -19,6 +19,7 @@
 
 %newobject NdbFactory::createNdbClusterConnection();
 
+
 %{
 
   class NdbFactory

Thread
Rev 116: Added initial python unittests. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmergeMonty Taylor8 May