Jump to content

Automated testing: Difference between revisions

(→‎Details specific to OpenHatch: update instructions for running a few tests and remove reference to MySQL)
$ python manage.py test
Whoosh的分词是基于正则表达式的,所以只需要写出合适的正则表达式就可以正确分词。下面是一些例子,可能有不完善的地方,需要继续完善完善。#测试分词#!/usr/bin/env python# -*- coidng: UTF-8 -*-from whoosh.analysis import RegexAnalyzerrex = RegexAnalyzer(ur”([\u4e00-\u9fa5])|(\w+(\.?\w+)*)”)print [token.text for token in rex(u"hi 中 000 中文测试中文 there 3.141 big-time under_score")]#一个完整的演示#!/usr/bin/env python# -*- coidng: UTF-8 -*-from whoosh.index import create_infrom whoosh.fields import *from whoosh.analysis import RegexAnalyzeranalyzer = RegexAnalyzer(ur”([\u4e00-\u9fa5])|(\w+(\.?\w+)*)”)schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT(stored=True, analyzer=analyzer))ix = create_in(“indexdir”, schema)writer = ix.writer()writer.add_document(title=u”First document”, path=u”/a”, content=u”This is the first document we've added!”)writer.add_document(title=u”Second document”, path=u”/b”, content=u”The second one 你 中文测试中文 is even more interesting!”)writer.commit()searcher = ix.searcher()results = searcher.find(“content”, u”first”)print results[0]results = searcher.find(“content”, u”你”)print results[0]results = searcher.find(“content”, u”测试”)print results[0]
== Read the official Django testing guide ==
The official guide on Django testing is quite good. It says, "The best part [about writing tests for Django code] is, it's really easy."
We use the Django "unit test" style of writing tests.
* Go '''[http://docs.djangoproject.com/en/dev/topics/testing/ read the official Django testing guide]'''.
== General testing tips ==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.