Advertisement
Guest User

Untitled

a guest
Jan 11th, 2018
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.40 KB | None | 0 0
  1.  
  2. import sys
  3. import os
  4. from rasdapy import core
  5.  
  6. db = None
  7.  
  8. collName = "RasdaPyGrey"
  9.  
  10. def setUp():
  11.     hostname = "localhost"
  12.     username = "rasadmin"
  13.     password = "rasadmin"
  14.     collName = "RasdaPyGrey"
  15.     con = core.Connection(hostname=hostname,
  16.                             username=username, password=password)
  17.     global db
  18.     db = con.database("RASBASE")
  19.     print db
  20.  
  21. def test_a():
  22.     global db, collName
  23.     txn = db.transaction(rw=True)
  24.     print "Testing create collection..."
  25.     print collName
  26.     q = txn.query("create collection " + collName + " GreySet")
  27.     res = q.eval()
  28.     txn.commit()
  29.     #assertEqual(res, None)
  30.     print "Done"
  31.  
  32. def test_b():
  33.     global db, collName
  34.     txn = db.transaction(rw=True)
  35.     print "Testing insert some values to newly created collection..."
  36.     q = txn.query("insert into " + collName + " values marray x in [0:2, 0:2] values 1c")
  37.     res = q.eval()
  38.     txn.commit()
  39.     #assertEqual(res, None)
  40.     print "Done"
  41.  
  42. def test_c():
  43.     global db, collName
  44.     txn = db.transaction(rw=False)
  45.     print "Testing select some values from newly created collection..."
  46.     q = txn.query("select " + collName + "[0:2,0:2] from " + collName)
  47.     data = q.eval()
  48.     txn.abort()
  49.     #assertIsInstance(data, core.Array)
  50.     # convert rasdaman's output array to numpy array
  51.     # print data.to_array()
  52.     print "Done"
  53.  
  54. def test_d():
  55.     global db, collName
  56.     txn = db.transaction(rw=False)
  57.     print "Testing get the average cells from newly created collection..."
  58.     q = txn.query("select avg_cells(" + collName + ") from " + collName)
  59.     data = q.eval()
  60.     txn.abort()
  61.     #assertIsInstance(data, list)
  62.     #assertEqual(data, [1.0])
  63.     print "Done"
  64.  
  65. def test_e():
  66.     global db, collName
  67.     txn = db.transaction(rw=False)
  68.     print "Testing select some values from newly created collection..."
  69.     q = txn.query("select " + collName + "[0:2,0:2] from " + collName)
  70.     data = q.eval()
  71.     txn.abort()
  72.     #assertIsInstance(data, core.Array)
  73.     # convert rasdaman's output array to numpy array
  74.     # print data.to_array()
  75.     print "Done"
  76.  
  77. def test_f():
  78.     global db, collName
  79.     txn = db.transaction(rw=False)
  80.     print "Testing get the average cells from newly created collection..."
  81.     q = txn.query("select avg_cells(" + collName + ") from " + collName)
  82.     data = q.eval()
  83.     txn.abort()
  84.     #assertIsInstance(data, list)
  85.     #assertEqual(data, [1.0])
  86.     print "Done"
  87.  
  88. def test_g():
  89.     global db, collName
  90.     txn = db.transaction(rw=False)
  91.     print "Testing select some values from newly created collection..."
  92.     q = txn.query("select " + collName + "[0:2,0:2] from " + collName)
  93.     data = q.eval()
  94.     txn.abort()
  95.     #assertIsInstance(data, core.Array)
  96.     # convert rasdaman's output array to numpy array
  97.     # print data.to_array()
  98.     print "Done"
  99.  
  100. def test_h():
  101.     global db, collName
  102.     txn = db.transaction(rw=False)
  103.     print "Testing get the average cells from newly created collection..."
  104.     q = txn.query("select avg_cells(" + collName + ") from " + collName)
  105.     data = q.eval()
  106.     txn.abort()
  107.     #assertIsInstance(data, list)
  108.     #assertEqual(data, [1.0])
  109.     print "Done"
  110.  
  111. def test_i():
  112.     global db, collName
  113.     txn = db.transaction(rw=False)
  114.     print "Testing select some values from newly created collection..."
  115.     q = txn.query("select " + collName + "[0:2,0:2] from " + collName)
  116.     data = q.eval()
  117.     txn.abort()
  118.     #assertIsInstance(data, core.Array)
  119.     # convert rasdaman's output array to numpy array
  120.     # print data.to_array()
  121.     print "Done"
  122.  
  123. def test_j():
  124.     global db, collName
  125.     txn = db.transaction(rw=False)
  126.     print "Testing get the average cells from newly created collection..."
  127.     q = txn.query("select avg_cells(" + collName + ") from " + collName)
  128.     data = q.eval()
  129.     txn.abort()
  130.     #assertIsInstance(data, list)
  131.     #assertEqual(data, [1.0])
  132.     print "Done"
  133.  
  134. def test_k():
  135.     global db, collName
  136.     txn = db.transaction(rw=True)
  137.     print "Testing drop collection..."
  138.     q = txn.query("drop collection " + collName)
  139.     res = q.eval()
  140.     txn.commit()
  141.     #assertEqual(res, None)
  142.     print "Done"
  143.    
  144.  
  145.  
  146.  
  147. setUp()
  148.  
  149. test_a()
  150. test_b()
  151. test_c()
  152. test_d()
  153. test_e()
  154. test_f()
  155. test_g()
  156. test_h()
  157. test_i()
  158. test_j()
  159. test_k()
  160.  
  161. # os._exit(1)
  162.  
  163. print "Trying to close database connection..."
  164. db.close()
  165. print "Done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement