62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
#!/usr/bin/env python
|
||
# -*- coding: UTF-8 -*-
|
||
'''=================================================
|
||
@IDE :PyCharm
|
||
@Author :LuckyHuibo
|
||
@Date :2019/10/17 23:28
|
||
@Desc :
|
||
=================================================='''
|
||
|
||
import os
|
||
import tempfile
|
||
import pytest
|
||
|
||
from flask import Flask
|
||
|
||
import jieba
|
||
|
||
jieba.initialize()
|
||
|
||
os.chdir("..")
|
||
|
||
|
||
def create_app(test_config=None):
|
||
"""Create and configure an instance of the Flask application."""
|
||
app = Flask(__name__, instance_relative_config=True)
|
||
app.config.from_mapping(
|
||
# a default secret that should be overridden by instance config
|
||
SECRET_KEY="dev",
|
||
# store the database in the instance folder
|
||
DATABASE=os.path.join(app.instance_path, "flaskr.sqlite"),
|
||
)
|
||
|
||
|
||
@pytest.fixture
|
||
def app():
|
||
"""Create and configure a new app instance for each test."""
|
||
# create a temporary file to isolate the database for each test
|
||
db_fd, db_path = tempfile.mkstemp()
|
||
# create the app with common test config
|
||
app = create_app({"TESTING": True})
|
||
yield app
|
||
|
||
# close and remove the temporary database
|
||
os.close(db_fd)
|
||
os.unlink(db_path)
|
||
|
||
|
||
@pytest.fixture
|
||
def client(app):
|
||
"""A test client for the app."""
|
||
return app.test_client()
|
||
|
||
|
||
@pytest.fixture
|
||
def runner(app):
|
||
"""A test runner for the app's Click commands."""
|
||
return app.test_cli_runner()
|
||
|
||
# @pytest.fixture(scope="session", params=[(r"instance/say_words.txt", r"instance/init_say_words.txt")])
|
||
# def say_words(word2vec_model, request):
|
||
# return nlp_model.load_say_words(word2vec_model, *request.param)
|