Ejemplo n.º 1
0
class SQLiteTest(unittest.TestCase):

    def setUp(self):
        self.sb = SQLBackend("sqlite", ":memory:")

    def test_connect(self):
        self.assertTrue(self.sb.connected)

    def test_reuse(self):
        self.assertTrue(self.sb.connected)
        self.sb.disconnect()
        self.assertFalse(self.sb.connected)
        self.sb.connect()
        self.assertTrue(self.sb.connected)
Ejemplo n.º 2
0
class CursorSlicerRealTest(IterSlicerTest):

    def setUp(self):

        from pydra.cluster.tasks.datasource.backend import SQLBackend

        self.l = [('leicester',), ('quark',), (1,), (0,), (None,)]

        self.backend = SQLBackend("sqlite3", ":memory:")
        self.backend.connect()

        db = self.backend.handle
        db.execute("CREATE TABLE CHEESES (NAME)")
        db.executemany("INSERT INTO CHEESES VALUES (?)", self.l)
        db.commit()

        self.cursor = db.execute("SELECT * FROM CHEESES")
        self.slicer = CursorSlicer(self.cursor)
Ejemplo n.º 3
0
class SQLSelectorTest(unittest.TestCase):

    def setUp(self):
        #TODO: test the selector without using a real backend(?)
        from pydra.cluster.tasks.datasource.backend import SQLBackend

        self.l = [('leicester',), ('quark',), (1,), (0,), (None,)]

        self.backend = SQLBackend("sqlite3", ":memory:")
        self.backend.connect()

        db = self.backend.handle
        db.execute("CREATE TABLE CHEESES (NAME)")
        db.executemany("INSERT INTO CHEESES VALUES (?)", self.l)
        db.commit()

        self.selector = SQLSelector(self.backend, "SELECT * FROM CHEESES")

    def test_trivial(self):

        pass

    def test_select(self):

        query = "SELECT * FROM CHEESES"
        selector = SQLSelector(self.backend, query)
        self.assertEqual(self.l, [k for k in selector])

    def test_args(self):

        query = "SELECT * FROM CHEESES WHERE NAME IN (?, ?)"
        selector = SQLSelector(self.backend, query, "quark", "leicester")
        self.assertEqual(self.l[:2], [k for k in selector])

    def test_kwargs(self):

        query = "SELECT * FROM CHEESES WHERE NAME IN (:cheeseA, :cheeseB)"
        selector = SQLSelector(self.backend, query, cheeseA="quark", cheeseB="leicester")
        self.assertEqual(self.l[:2], [k for k in selector])

    def test_syntax(self):

        query = "SELECT * FROM CHEESES WHERE NAME IN (?, ?)"
        self.assertRaises(ValueError, SQLSelector, self.backend, query, "quark", "leicester", it="ni")
Ejemplo n.º 4
0
    def setUp(self):
        #TODO: test the selector without using a real backend(?)
        from pydra.cluster.tasks.datasource.backend import SQLBackend

        self.l = [('leicester',), ('quark',), (1,), (0,), (None,)]

        self.backend = SQLBackend("sqlite3", ":memory:")
        self.backend.connect()

        db = self.backend.handle
        db.execute("CREATE TABLE CHEESES (NAME)")
        db.executemany("INSERT INTO CHEESES VALUES (?)", self.l)
        db.commit()

        self.selector = SQLSelector(self.backend, "SELECT * FROM CHEESES")
Ejemplo n.º 5
0
 def setUp(self):
     self.sb = SQLBackend("sqlite", ":memory:")
Ejemplo n.º 6
0
 def test_sqlite_reuse(self):
     sb = SQLBackend("sqlite", ":memory:")
     self.assertTrue(sb.connected)
     sb.disconnect()
     self.assertFalse(sb.connected)
     sb.connect(":memory:")