随笔分类 -  python测试

摘要:限于作者水平有限,以下内容可能是管窥之见,希望大家高抬贵手,且让我斗胆抛砖引玉。公司产品迪备主要是通过网页操作来进行数据库的备份与恢复,监控与管理,因此在测试的过程中,可以用python测试脚本来模拟用户的操作,这样的测试对于回归测试效果尤佳,减少了人工操作,极大地提高了效率。据网上资料得知,python的web测试开源世界,存在splinter,它是自动化测试web的框架,这是最为基本的Web-driver。然后加上selenium,两者并用,才能支持主流的浏览器的firefox, chrome 和IE ,到目前为止,支持chrome浏览器的最为齐全,连鼠标的模拟的API都存在,同时对其余两 阅读全文
posted @ 2012-08-28 23:21 苍术厚朴 阅读(11647) 评论(2) 推荐(2)
摘要:"""Loading unittests."""import osimport reimport sysimport tracebackimport typesfrom functools import cmp_to_key as _CmpToKeyfrom fnmatch import fnmatchfrom . import case, suite__unittest = True# what about .pyc or .pyo (etc)# we would need to avoid loading the same tes 阅读全文
posted @ 2012-08-22 09:27 苍术厚朴 阅读(4256) 评论(0) 推荐(0)
摘要:#-*-coding:utf-8-*-from __future__ import with_statementimport osimport unittestimport timefrom splinter import Browserfrom random import randintclass DbackupTestCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.browser = Browser('firefox') @classmethod def setDownCla... 阅读全文
posted @ 2012-08-17 10:48 苍术厚朴 阅读(2846) 评论(0) 推荐(0)
摘要:jQuery API Documentation详细的API和例子说明,请参考文档:http://docs.jquery.com/Main_Page百度百科的解析:http://baike.baidu.com/view/1020297.htmCore$( expr , context )This function accepts a string containing a CSS or basic XPath selector which is then used to match a set of elements.The core functionality of jQuery cente 阅读全文
posted @ 2012-08-15 21:37 苍术厚朴 阅读(1622) 评论(0) 推荐(0)
摘要:#-*-coding:utf-8-*-from __future__ import with_statementimport ostry: import unittest2 as unittestexcept ImportError: import unittestimport time from splinter import Browserfrom random import randint class DbackupTestCase(unittest.TestCase): # support 2.7,but not support 2.6.all the testca... 阅读全文
posted @ 2012-08-15 18:26 苍术厚朴 阅读(1602) 评论(0) 推荐(1)
摘要:当我基本能从事Django框架来对网站进行开发的时候,发现对Python的知识了解得太少了,甚至到了知识匮乏的阶段。看来,我得温习一下Python知识了。据我个人的理解,Python中有三种内置的数据类型。dictionary(字典)、List(列表)和tuple(元组)。下面我将对这几个内置的数据类型进行总结。Dictionary(字典)首先,什么是字典呢?通俗地来讲,字典无非就是很多的数据,但是它有一个目录,可以通过目录中的一个简单值来找到与之相对于的详细信息。换句话来说,目录就是内容的一个特殊标示,即目录中的每一个字段,都会在内容中有与之相对应的详细信息。也就是说,目录中的每一个信息都是 阅读全文
posted @ 2012-08-13 23:19 苍术厚朴 阅读(36695) 评论(1) 推荐(5)
摘要:简介: 软件的测试是一件非常乏味的事情,在测试别人编写的软件时尤其如此,程序员通常都只对编写代码感兴趣,而不喜欢文档编写和软件测试这类"没有创新"的工作。既然如此,为什么不让程序员在编写软件时自己加入一些用于测试的代码,使测试过程自动化呢?在软件工程中,这一技术称为自动单元测试,本文介绍在用Python开发软件时如何实现这一目标。 一、软件测试大型软件系统的开发是一个很复杂的过程,其中因为人的因素而所产生的错误非常多,因此软件在开发过程必须要有相应的质量保证活动,而软件测试则是保证质量的关键措施。正像软件熵(software entropy)所描述的那样:一个程序从设计很好 阅读全文
posted @ 2012-08-13 21:44 苍术厚朴 阅读(3617) 评论(0) 推荐(1)
摘要:正则表达式由一些普通字符和一些元字符(metacharacters)组成。普通字符包括大小写的字母和数字,而元字符则具有特殊的含义,我们下面会给予解释。 在最简单的情况下,一个正则表达式看上去就是一个普通的查找串。例如,正则表达式"testing"中没有包含任何元字符,它可以匹配"testing"和"123testing"等字符串,但是不能匹配"Testing"。 要想真正的用好正则表达式,正确的理解元字符是最重要的事情。下表列出了所有的元字符和对它们的一个简短的描述。元字符描述\将下一个字符标记为一个特殊字符、或 阅读全文
posted @ 2012-08-13 21:28 苍术厚朴 阅读(1833) 评论(0) 推荐(0)
摘要:#!/usr/bin/env pythonfrom sys import argvfrom os import makedirs,unlink,sepfrom os.path import dirname,exists,isdir,splitextfrom string import replace,find,lowerfrom htmllib import HTMLParserfrom urllib import urlretrievefrom urlparse import urlparse,urljoinfrom formatter import DumbWriter,AbstractF 阅读全文
posted @ 2012-08-13 01:44 苍术厚朴 阅读(962) 评论(0) 推荐(0)
摘要:# -*-coding:utf-8-*-import sys, os'''将当前进程fork为一个守护进程 注意:如果你的守护进程是由inetd启动的,不要这样做!inetd完成了 所有需要做的事情,包括重定向标准文件描述符,需要做的事情只有 chdir() 和 umask()了'''def daemonize(stdin='/dev/null',stdout= '/dev/null', stderr= 'dev/null'): '''Fork当前进程为守护进程,重定向标准文 阅读全文
posted @ 2012-08-13 01:05 苍术厚朴 阅读(6275) 评论(0) 推荐(0)
摘要:#!/usr/bin/env pythonimport os, signal,sys, time, select, randomdef child_make(i, read_end, write_end): fork_result = os.fork() if fork_result == 0: os.close(read_end) child_main(i,write_end)def child_main(i,write_end): time.sleep(random.randint(3,6)) os.write(write_end, '=... 阅读全文
posted @ 2012-08-13 00:25 苍术厚朴 阅读(809) 评论(0) 推荐(0)
摘要:#需要检查一个“目录”,或者某个包含子目录的目录树,并根据某种模式迭代所有的文件(也可能包含子目录)使用的是os.walk生成器import os, fnmatchdef all_files(root, patterns = '*', single_level = False, yield_folders=False): patterns = patterns.split(';') for path, subdirs, files in os.walk(root): if yield_folders: files.extend(subdirs) ... 阅读全文
posted @ 2012-08-12 23:44 苍术厚朴 阅读(2995) 评论(0) 推荐(0)
摘要:"""A parser for HTML and XHTML.""" 2 3 # This file is based on sgmllib.py, but the API is slightly different. 4 5 # XXX There should be a way to distinguish between PCDATA (parsed 6 # character data -- the normal case), RCDATA (replaceable character 7 # data -- only cha 阅读全文
posted @ 2012-08-12 21:38 苍术厚朴 阅读(525) 评论(0) 推荐(0)
摘要:Source code: Lib/HTMLParser.pyThis module defines a class HTMLParser which serves as the basis for parsing text files formatted in HTML (HyperText Mark-up Language) and XHTML. Unlike the parser in htmllib, this parser is not based on the SGML parser in sgmllib.class HTMLParser.HTMLParserAn HTMLParse 阅读全文
posted @ 2012-08-12 21:36 苍术厚朴 阅读(603) 评论(0) 推荐(0)
摘要:文档:http://docs.python.org/library/pdb.htmlThe debugger recognizes the following commands. Most commands can be abbreviated to one or two letters; e.g. h(elp) means that either h or help can be used to enter the help command (but not he or hel, nor H or Help or HELP). Arguments to commands must be se 阅读全文
posted @ 2012-08-12 16:26 苍术厚朴 阅读(657) 评论(0) 推荐(0)
摘要:# -*- coding: utf-8 -*-# Copyright 2012 splinter authors. All rights reserved.# Use of this source code is governed by a BSD-style# license that can be found in the LICENSE file.from __future__ import with_statementfrom splinter.driver import ElementAPIfrom splinter.element_list import ElementListcl 阅读全文
posted @ 2012-08-12 16:01 苍术厚朴 阅读(1652) 评论(0) 推荐(0)
摘要:# -*- coding: utf-8 -*-# Copyright 2012 splinter authors. All rights reserved.# Use of this source code is governed by a BSD-style# license that can be found in the LICENSE file.from __future__ import with_statementimport loggingimport subprocessimport timeimport refrom contextlib import contextmana 阅读全文
posted @ 2012-08-12 15:52 苍术厚朴 阅读(3520) 评论(0) 推荐(0)
摘要:# -*- coding: utf-8 -*-:# Copyright 2012 splinter authors. All rights reserved.# Use of this source code is governed by a BSD-style# license that can be found in the LICENSE file."""This module contains the basic API for splinter drivers and elemnts."""from splinter.wit 阅读全文
posted @ 2012-08-12 15:45 苍术厚朴 阅读(1730) 评论(0) 推荐(0)
摘要:#!/usr/bin/env python# Copyright 2012 splinter authors. All rights reserved.# Use of this source code is governed by a BSD-style# license that can be found in the LICENSE file.import unittestfrom splinter import Browserclass TestGoogleSearch(unittest.TestCase): @classmethod def setUpClass(cls)... 阅读全文
posted @ 2012-08-12 15:41 苍术厚朴 阅读(494) 评论(0) 推荐(0)
摘要:# -*- coding: utf-8 -*-# Copyright 2012 splinter authors. All rights reserved.# Use of this source code is governed by a BSD-style# license that can be found in the LICENSE file."""This snippet show how to "test" a Facebook feature: the creation of an event.It creates an eve 阅读全文
posted @ 2012-08-12 15:39 苍术厚朴 阅读(644) 评论(0) 推荐(0)