示例#1
0
 def get_from(self, storage, obj_id):
     conn=storage.conn
     cur=conn.cursor()
     cur.execute("""
                 SELECT * FROM Students
                 WHERE
                 rowid=?""", (obj_id,))
     data=cur.fetchone()
     name, doc, _=data
     s=Student(name=name, doc=int(doc))
     s.sql_id=obj_id
示例#2
0
 def get_from(self, storage, obj_id):
     conn=storage.conn
     cur=conn.cursor()
     cur.execute("""SELECT * FROM Groups
                 WHERE
                 rowid=?""", (obj_id,))
     rc=cur.fetchone()
     if rc:
         self.group.name=rc[0]
         cur.execute("""SELECT rowid,* FROM Students
                     WHERE
                     group_id=?
                     """, (obj_id,))
         rows=cur.fetchall()
         for srowid, name, doc, _ in rows:
             s=Student(name=name, doc=int(doc),
                 group=self.group)
             s.sql_id=srowid
         self.group.sql_id=obj_id
示例#3
0
def test1():
    assert IStudent.implementedBy(Student)
    ivanov = Student(name="Ivanov Ivan")
    assert IStudent.providedBy(ivanov)

    ivanov.add("programming", 5)
    ivanov.add("programming", 4)
    ivanov.add("programming", 3)
    assert ivanov.grades("programming") == [5, 4, 3]
    assert ivanov.average("programming") == 4
    ivanov.add("programming", 5)
    assert abs(ivanov.average("programming") - (5 * 2 + 4 + 3) / 4) < 0.01
    #ivanov.average("funcan")
    return ivanov