nosegae:用于google应用引擎测试的nose插件

NoseGAE的Python项目详细描述


NoseGAE: Nose for Google App Engine Testing
===========================================

`|PyPI| <https://pypi.python.org/pypi/NoseGAE>`_
`|Downloads| <https://pypi.python.org/pypi/NoseGAE>`_
`|License| <https://pypi.python.org/pypi/NoseGAE>`_ `|Build
Status| <https://travis-ci.org/Trii/NoseGAE>`_

安装
——


noseshop提供nosegae,可以通过"pip install nosegae"轻松安装。在积极维护库的同时,
此时没有添加任何新功能,因此开发工作已经停滞不前。如果您想使用这个库,或者只想克隆并安装,您可以选择"python setup.py install"或"python setup.py develop",甚至可以选择"pip"等价物。


`google app engine<;https://cloud.google.com/appengine/>;``应用程序的功能和单元测试。

>1。`它是做什么的?<;它做什么>;`

1.`功能测试`单元测试`配置测试床<;配置测试床>;`

1。`基于类的测试<;基于类的测试>;`
2。`函数测试<;函数测试>;`
3。` doctest<;doctest>;`

>3。` 0.5.2中的变化-052中的变化` 0.4.0中的变化<;040中的变化>;`


它的作用是什么?
-------


nosegae在测试运行之前设置gae开发环境。
这意味着您可以轻松地为
应用程序编写功能测试,而无需实际启动dev服务器并通过http测试
。该插件还配置并初始化一个testbed
实例,即基于"app.yaml"的应用程序ID,并使用"dev\u appserver.fix\u sys\u path()``设置
正确的路径。


bapp2
来自jinja2导入环境



类hello(webapp2.requesthandler):
def get(self):
self.response.headers['content-type']='text/plain'
env=environment()
template=env.from_string("hello{{greeting}!")
self.response.out.write(template.render(greeting='world')

app=webapp2.wsgiapplication([('/',hello],debug=true)


和一个简单的功能测试套件`` examples/helloworld/test.py``用于
应用程序:





d

app=testapp(helloworld.app)




class helloworld test(unittest.testcase):
def test_index(self):
"测试应用程序的索引页是否应用作:内容类型:文本/纯文本
正文内容应包含字符串:hello worlD!
"
响应=app.get('/')
self.assertequal(response.content_type,'text/plain')
self.assertin('hello world!',response.body)



>没有nosegae,测试失败。





br/>-----------------------------------————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————s/josh/developer/github/jj/lib/python2.7/site packages/nose-1.3.4-py2.7.egg/nose/importer.py",第47行,在importfrompath中
返回self.importfromdir(dir路径,fqname)
文件"/users/josh/developer/github/jj/lib/python2.7/site packages/nose-1.3.4-py2.7.egg/nose/importer.py",行94,in importFromDir
mod=load_模块(部分fqname,fh,filename,desc)
file"/users/josh/developer/github/nosegae/examples/helloworld/test.py",第2行,in<;module>;
import helloworld
file"/users/josh/developer/github/nosegae/examples/helloworld/hel"loworld.py",第1行,在<;module>;
导入webapp2
importorror:没有名为webapp2的模块

/>——:

HelloWorld$noests--日志记录级别=错误--GAE

——东南方。如果您想
为您的数据模型编写单元测试呢?通常,您不能在开发环境之外使用
模型,因为google应用程序
引擎数据存储不可用。但是,由于nosegae插件设置了围绕测试运行的开发环境,因此您可以直接在测试中使用模型。


请考虑"examples/pets/models.py"文件,该文件包含一些来自google.appengine.ext import ndb的


类pet(ndb.model):
"pet类为宠物提供存储空间。

>;
>;>;>testbed.init memcache>;>testbed.init数据存储库v3
您可以创建宠物:
>>gt;muffy=pet(name=u'muffy,type=u'dog,breed=u"shi'tsi")
>>muffy'docest:+省略号
pet(name=u'muffy,type=u'dog,breed=u"shi'tsi",…)
>;muffy'u key=muffy.put()

TS键:

>;>muffy_key.get();doctest:+ellipsis
pet(name=u'muffy',type=u'dog',breed=u"shi'tz",…)


或通过选择宠物的查询:

>;>;list(pet.query(pet.type=="dog"),doctest:+ellipsis
[pet(nAME=U'muffy',…)]

它将被更新。

>;>bool(muffy_key==muffy_key_2)
true
"
name=ndb.stringproperty(必需=true)
type=ndb.stringproperty(必需=true,选项=("cat","dog","bird","fish","monkey"))
breed=ndb.stringproperty()
age=ndb.integerproperty()
comments=ndb.textproperty()
created=ndb.datetimeproperty(auto_now_add=true,required=true)

def_u repr_u(self):
return("pet(name=%r,type=%r,breed=%r,age=%r,
"comments=%r,created=%r)"%
(self.name,self.type,self.breed,self.age,
self.comments,self.created))


如果没有nosegae,doctests将失败。



pets$nosetests--with doctest--logging level=error
f
==========一次回溯(最近的回溯)最后一次调用:
文件"/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/doctest.py",runtest中的第2201行
引发self.failureexception(self.format_failure(new.getvalue())
断言错误:对models.pet的doctest测试失败
文件"/users/josh/developer/github/nosegae/examples/pets/models.py",第4行,在pet中

ffy.put()
引发异常:
回溯(最近一次调用):
文件"/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/doctest.py",第1289行,在运行时
compileflags,1)在test.globs
文件"<;doctest models.pet[2]>;",第1行,in<;module>;
muffy_key=muffy.put()
文件"/applications/googleappenginelauncher.app/contents/resources/google appengine default.bundle/contents/resources/google廑appengine/google/appengine/ext/ndb/model.py",第3379行,in廑put
返回self._put_async(**ctx_options).get_result()
file"/applications/googleappenginelauncher.app/contents/resources/google appengine default.bundle/contents/resources/google_appengine/google/appengine/ext/ndb/tasklets.py"行325,在get_result中
self.check_success()
file"/applications/googleappenginelauncher.app/contents/resources/google appengine default.bundle/contents/resources/google撸appengine/google/appengine/ext/ndb/tasklets.py",第368行,在"帮助"中,tasklet撸along
value=gen.throw(exc.撸class撸,exc,tb)
file"/application"选项/googleappenginelauncher.app/contents/resources/google appengine default.bundle/contents/resources/google廑appengine/google/appengine/ext/ndb/context.py",第810行,in-put
key=yield self.廑put廑batcher.add(实体,选项)
file"/applications/googleappenginelauncher.app/contents/resources/google appengine default.bundle/contents/resources/google廑appengine/google/appengine/ext/ndb/tasklets.py",第371行,在廑帮助廑tasklet廑中
value=gen.send(val)
文件"/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google廑appengine/google/appengine/ext/ndb/context.py",第343行,in廑put廑tasklet
keys=yield self.廑conn.async廑put(options,datastore廑entities)
file"/applications/googleappenginelauncher.app/contents/resources/googundle/contents/resources/google_appengine/google/appengine/datastore/datastore_rpc.py",第1801行,在async_put中
返回make_put_call(base_req,pbs,extra_hook)
文件"/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google廑appengine/google/appengine/datastore/datastore廑rpc.py",第1784行,make廑put廑call
service廑name=self.廑api廑version)
file"/applications/googleappenginelauncher.app/contents/resources/google廑appengine-default.bundle/contents/resources/le/appengine/datastore/datastore_rpc.py",第1310行,在"make_rpc_call
rpc=self.\u create_rpc(config,service_name)
file"/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/datastore/datastore_rpc.py",第1205行,在_create_rpc
rpc=apiproxy_stub_map.userrpc(service_name,deadline,callback)
file"/applications/googleappenginelauncher.app/contents/resources/google appengine-default.bundle/contents/resources/google_appengine/google/appengine/api/apiproxy_stub_map.py",第414行,在uuu init_uu
self.u rpc=createrpc(服务,stubmap)
文件"/applications/googleappenginelauncher.app/contents/resources/google appengine default.bundle/contents/resources/google_appengine/google/appengine/api/api proxy_stub_map.py",第68行,在createrpc
assert stub中,找不到服务"%s"的api代理,%service
assertione错误:没有找到服务"datastore_v3"


使用nosegae的api代理,它们通过了。

::


pets$nosetests--with doctest--with gae

在0.228s内运行了1个测试

ok

con配置测试台时,nosegae会自动为您配置"testbed"实例,然后启用测试通过所需的任何存根。有两种方法可以启用和配置存根。第一个也是最灵活的方法是直接初始化注入测试用例的"testbed"实例上的存根。第二种也是更简单的方法是

测试用例上设置"nosegae"和可选的"nosegae"和"nosegae"kwargs"属性,并让nosegae为您配置它们。下面的
三节描述了如何在您自己的测试中使用"testbed"。


nosegae插件向测试类的实例注入名为"testbed"的属性,并根据与约定"nosegae"stubname>;``和"nosegae"stubname>;``匹配的任何属性对其进行配置。

手动配置每个测试。





class mytest(unit test.testcase):
def test_using_memcache(self):
"unit test using memcache"(使用memcache的单元测试)
来自google.appengine.api import memcache
self.testbed.init_memcache_stub()
memcache.set('test',true,30)
self.asserttrue(memcache.get('test')


def test_using_taskqueue(self):
"unit test using the taskqueue"""
self.testbed.init_taskqueue_stub(root_path='/path/to/app')
from google.appengine.api导入taskqueue
task_url='/some/task'
taskqueue.add(url=task_url)
taskqueue_stub=self.testbed.get_stub('taskqueue')
tasks=taskqueue_stub.get_filtered_tasks(url=task_url)
self.assertequal(1,len(tasks))
self.assertequal(task戋url,tasks[0.url)


下面的测试用例显示如何使用简单的配置方法编写使用
数据存储存根的测试,该方法使用
``nosegae戋lt;stubname>;``和``nosegae戋lt;stubname>;`u kwargs`.




类数据测试(unittest.testcase):启用数据存储存根self.assertsnotnone(entity)

请参见
``示例/函数手动配置`。





def test_index():
test_index.testbed由nosegae插件分配
test_index.testbed.init_taskqueue_stub(task_retry_seconds=42,root_path=os.path.dirname(u file_u))
e触发一个任务队列,应该毫无例外地传递
app=testapp(hello world.app)
response=app.get('/')
assert'hello world!'在str(response)

序列化方法。有关完整的示例代码,请参见
``examples/issue42-task-queue`。




在str(response)

路径和具有kwargs属性的任何其他参数
test_index.nosegae_taskqueue_kwargs=dict(task_retry_seconds=42,root_path=os.path.dirname(u file_uu))

~~~~~~

doctests是一个完整的其他野兽。它们仍然可以工作,但所有的"testbed"配置都必须手动完成。nosegae使用"nose doctest
plugin<;http://nose.readthedocs.org/en/latest/plugins/doctests.html>;`
将名为"testbed"的全局变量注入到包含当前活动"testbed"实例的doctest作用域中。有关完整示例,请参见
``examples/pets/models.py```t>>>testbed.init_datastore_v3_stub()

equired=true,choices=("cat","dog","bird","fish","monkey"))
breed=ndb.stringproperty()

``````````````` 0.5.2中的更改


0.5.2版本引入了初步的模块支持,允许
发送到``--gae应用程序``命令行的多个yaml或路径
.

::


notests——使用gae\
--gae application='app.yaml,mobile''u frontend.yaml,static''u backend.yaml,dispatch.yaml'

<0.4.0中的更改
----

0.4.0版本是支持"dev''u appserver2``的主要重写版本。此版本引入了以下两个重要更改。


由于不再有任何
在"nose"自己的内部工作之间切换的方法,因此被删除。


这意味着某些测试可能在本地通过,但有问题的代码将由于模块和功能的限制而在生产中失败。从
开始,现在没有解决方法,但欢迎提出请求!

testbed是为您设置的
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

新插件会自动设置初始的
``google.appengine.ext.testbed.testbed``实例并将其注入到您的测试用例中。


| pypi图像::https://img.shields.io/pypi/v/nosegae.svg
…|下载图像::https://img.shields.io/pypi/dm/nosegae.svg
…|许可证图像::https://img.shields.io/pypi/l/nosegae.svg
…|构建
状态图像::https://travis-ci.org/trii/nosegae.svg?分支=主

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在JScrollPane标题中禁用鼠标滚轮滚动?   java如何为篮球计分器应用程序存储包括球队名称在内的比赛分数?   java如何使用ADT接口实例化列表   JavaCV抓取帧方法延迟并返回旧帧   java在上传文件时处理网络问题   java如何创建2d阵列的克隆?   关于XMLGregorianCalendar的java信息   java XmlUnit在比较XML文件时忽略元素的顺序   java如何最好地检测无意义的文本?   克隆如何制作java扫描仪的副本?   验证Java中空值的BigDecimal数据类型   java字符串数组中的字数   java JavaFX:如何选择平铺并添加数字和边框线?   java更改jtable中从jar文件获取的特定行的颜色   正则表达式Java字符串。拆分:将\\W用作非单词分隔符时出现问题   当内存损坏时,Java中的同一引用/实例变量会发生什么变化?   java无法在Javadoc注释中链接到JDK10