易截截图软件、单文件、免安装、纯绿色、仅160KB

Python sqlite3和单元测试

 
import os
import unittest # 包含单元测试模块
import sqlite3 as sqlite # 包含sqlite3模块
def get_db_path():
return "sqlite_testdb"
class TransactionTests(unittest.TestCase): # 单元测试第一步: 由TestCase派生类
def setUp(self): # 单元测试环境配置
try:
os.remove(get_db_path())
except:
pass
self.con1 = sqlite.connect(get_db_path(), timeout=0.1) # 连接数据库
self.cur1 = self.con1.cursor() # 获取游标
self.con2 = sqlite.connect(get_db_path(), timeout=0.1)
self.cur2 = self.con2.cursor()
def tearDown(self): # 单元测试环境清除
self.cur1.close() # 关闭游标
self.con1.close() # 关闭连接
self.cur2.close()
self.con2.close()
os.unlink(get_db_path())
def CheckDMLdoesAutoCommitBefore(self):
self.cur1.execute("create table test(i)") # 执行SQL查询
self.cur1.execute("insert into test(i) values (5)")
self.cur1.execute("create table test2(j)")
self.cur2.execute("select i from test")
res = self.cur2.fetchall()
self.failUnlessEqual(len(res), 1) # 测试
def CheckInsertStartsTransaction(self):
self.cur1.execute("create table test(i)")
self.cur1.execute("insert into test(i) values (5)")
self.cur2.execute("select i from test")
res = self.cur2.fetchall()
self.failUnlessEqual(len(res), 0)
def CheckUpdateStartsTransaction(self):
self.cur1.execute("create table test(i)")
self.cur1.execute("insert into test(i) values (5)")
self.con1.commit()
self.cur1.execute("update test set i=6")
self.cur2.execute("select i from test")
res = self.cur2.fetchone()[0]
self.failUnlessEqual(res, 5)
def CheckDeleteStartsTransaction(self):
self.cur1.exec


相关文档:

python 好东东

ipython 如果没有用装, 那就赶紧装上, 这个东西比起python自己带的那个交互界面要好用很多
shutil 类似于shell的一些接口, 比如 cp, mv等等
subprocess 调用子进程
optparse 解析命令行参数的, 用它来应付命令行参数, 简洁, 清晰
sqlite3 数据库, 进程级的数据库, 很酷, 甚至可以把这个数据库建在内存里. http://www.py ......

Python PAMIE示例

 转自:http://blog.chinaunix.net/u3/103146/showart_2058891.html
Python这种脚本语言的强大功能越来越被广大的程序员所重视,这种之前在国内流行度不高的语言近来气势高涨。各种第三方模块层出不穷。
 
本文介绍的便是一种能非常方便操作IE的第三方工具,PAMIE,他能让你如同写JS一样来操作IE浏览器。包括自 ......

[_数据挖掘_] python实践之1

 计划这个星期学习用python实现决策树算法。今晚就碰到了好多问题,好久没有用python了,并且3.0和书本上的有些东西不太一致,这里记录下几个地方。
1) import module 如果不是在标准目录下(系统的path,python的目录,当前目录),那么需要先import sys,然后sys.path.append('');
2) 改变源文件后,再次import ......

删除工程中svn文件的脚本(Ruby版和Python版)

两种不同的语言,不同的表达!
Python脚本实现.
""
"
    File Name : clean.py
    File Date : 2009/11/5 14:22:56
    Author     : DannyLai
    Purpose     : Cle ......

sqlite可视化IDE工具

 1. SQLite Database Browser 是一个SQLite数据库管理工具。是开源的、免费的。
Home Page
http://sqlitebrowser.sourceforge.net/
 
Download
http://sourceforge.net/project/showfiles.php?group_id=87946
 
Wiki
http://en.wikipedia.org/wiki/SQLite_Database_Browser
 
  2.  ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号