def run(self): import os.path from test import unittest test_dir = os.path.join(os.path.dirname(__file__), 'test') package_suite = unittest.TestLoader().discover(test_dir) unittest.TextTestRunner(verbosity=2).run(package_suite)
results = self.Post.query.msearch('title:search').all() self.assertEqual(len(results), 2) results = self.Post.query.msearch('content:search').all() self.assertEqual(len(results), 1) results = self.Post.query.msearch( 'title:search OR content:title').all() self.assertEqual(len(results), 3) results = self.Post.query.msearch('*search').all() self.assertEqual(len(results), 3) results = self.Post.query.msearch('search*').all() self.assertEqual(len(results), 2) results = self.Post.query.msearch('search*', geohash='f37p0hxhg382', geofield='geo').all() self.assertEqual(len(results), 1) results = self.Post.query.msearch('', geohash='m8umpccxt26m', geofield='geo').all() self.assertEqual(len(results), 2) if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromNames( [ 'test_elasticsearch.TestSearch', ]) unittest.TextTestRunner(verbosity=1).run(suite)
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """ This is a convenience script for finding all the unit tests in the ./test/ directory and running them. Test modules are automatically detected, using TestLoader.discover(), which loads the test files that match the Unix-shell pattern 'test*.py' (such as ./test/test_passband.py). """ import sys from test import unittest # This import checks whether the FITS images used by some tests are where # expected and, if that is not the case, automatically downloads them from the # STScI Digitized Sky Survey. In this manner, any image retrieval will be done # before running the unit tests, never halfway through their execution. import test.dss_images TESTS_PACKAGE = 'test' if __name__ == "__main__": loader = unittest.TestLoader() tests = loader.discover(TESTS_PACKAGE) runner = unittest.runner.TextTestRunner(verbosity=2) runner.failfast = True result = runner.run(tests) sys.exit(not result.wasSuccessful())
self.Post = Post with self.app.test_request_context(): db.create_all() for i in range(10): name = 'post %d' % i post = self.Post(name=name, int1=i, int2=i * 2) post.save(self.db) def test_int_prop(self): with self.app.test_request_context(): results = self.Post.query.msearch('0', fields=['fts_int']).all() self.assertEqual(len(results), 1) results = self.Post.query.msearch('27', fields=['fts_int']).all() self.assertEqual(len(results), 1) def test_date_prop(self): with self.app.test_request_context(): results = self.Post.query.msearch('2017-05-04', fields=['fts_date']).all() self.assertEqual(len(results), 10) if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromNames([ 'test_whoosh.TestSearch', 'test_whoosh.TestRelationSearch', 'test_whoosh.TestSearchHybridProp', 'test_whoosh.TestHybridPropTypeHint', ]) unittest.TextTestRunner(verbosity=1).run(suite)
TESTING = True MSEARCH_INDEX_NAME = mkdtemp() MSEARCH_BACKEND = 'simple' self.app = Flask(__name__) self.app.config.from_object(TestConfig()) self.db = SQLAlchemy(self.app) self.search = Search(self.app, db=self.db) db = self.db class Post(db.Model, ModelSaveMixin): __tablename__ = 'basic_posts' __searchable__ = ['title', 'content'] id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(49)) content = db.Column(db.Text) def __repr__(self): return '<Post:{}>'.format(self.title) self.Post = Post self.init_data() if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromNames( ['test_simple.TestSearch', ]) unittest.TextTestRunner(verbosity=1).run(suite)
content = db.Column(db.Text) def __repr__(self): return '<Post:{}>'.format(self.title) self.Post = Post with self.app.test_request_context(): self.db.create_all() for (i, title) in enumerate(titles, 1): post = self.Post(title=title, content='content%d' % i) post.save(self.db) def test_basic_search(self): with self.app.test_request_context(): results = self.Post.query.msearch('水果').all() self.assertEqual(len(results), 2) results = self.Post.query.msearch('苹果').all() self.assertEqual(len(results), 1) results = self.Post.query.msearch('世博园').all() self.assertEqual(len(results), 1) if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromNames([ 'test_jieba.TestSearch', ]) unittest.TextTestRunner(verbosity=1).run(suite)