File: testdb

package info (click to toggle)
sqlobject 3.10.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,660 kB
  • sloc: python: 17,348; makefile: 162; sh: 95
file content (54 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh

# Simple test that we can use a memory database

set -e

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR

cat << EOF > testdb.py
import sys

from sqlobject import SQLObject, connectionForURI, IntCol, sqlhub, SQLObjectNotFound


class TestCol(SQLObject):

    number = IntCol()


def run():
    sqlhub.processConnection = connectionForURI('sqlite:///:memory:')

    TestCol.createTable()

    entry1 = TestCol(number=1)
    entry2 = TestCol(number=2)
    entry3 = TestCol(number=3)

    # Check we have the right number of entries
    if TestCol.select().count() != 3:
        sys.exit(1)

    # check we can select by number
    entry = TestCol.selectBy(number=1).getOne()
    if entry != entry1:
        return False

    # Check select fails correctly
    try:
        TestCol.selectBy(number=4).getOne()
    except SQLObjectNotFound:
       return True
    return False

if __name__ == "__main__":
   if not run():
       sys.exit(1)
EOF

for py in $(py3versions -s) python3; do
   $py testdb.py
done