Exemplo n.º 1
0
    def reset_report(self, filename):
        """
        这个方法主要是通过写入文件的方法,先打开cs.YML_REPORT也就是
        mkdocs.yml文件,判断文件中是否存在当前写入的内容。
        :param filename: 测试用例文件
        :return: 测试报告内容
        """
        try:
            result = os.path.exists(cs.REPORT_PATH)
            if result == True:
                conf.get_config(filename)
                reportName = eval(conf.get_data(title=cs.REPORT_NAME, key=cs.REPORT))
                report_name = eval(conf.get_data(title=cs.REPORT_NAME, key=cs.R_NAME))
                file = open(cs.YML_REPORT, 'r')
                list_con = file.readlines()
                content = str(list_con).decode("string_escape")
                fileContent = "- [%s, %s]"
                row = "\n"
                _content = fileContent % (reportName + cs.NOW, report_name)
                con = row + _content

                if fileContent % (reportName + cs.NOW, report_name) not in content:
                    f = open(cs.YML_REPORT, 'a+')
                    f.write(con)
                else:
                    logging.info("内容已经存在 %s" % _content)
        except Exception, e:
            logging.error("文件路径不存在 %s", e)
Exemplo n.º 2
0
    def execute_case(self, filename):
        """
        执行接口测试用例的方法
        :param filename: 用例文件名称
        :return: 测试结果
        """
        conf.get_config(filename)
        list = eval(conf.get_title_list())

        for i in range(2, len(list)):
            title = list[i]
            number = conf.get_data(title, key=cs.NUMBER)
            name = conf.get_data(title, key=cs.NAME)
            method = conf.get_data(title, key=cs.METHOD)
            url = conf.get_data(title, key=cs.URL)
            data = eval(conf.get_data(title, key=cs.DATA))
            _data = request.json.dumps(data,ensure_ascii=False,indent=4)
            headers = eval(conf.get_data(title, key=cs.HEADERS))
            _headers = request.json.dumps(headers,ensure_ascii=False,indent=4)
            testUrl = cs.TEST_URL + url
            actualCode = request.api(method, testUrl, _data, headers)
            expectCode = conf.get_data(title, key=cs.CODE)


            if actualCode != expectCode:
                logging.info("新增一条接口失败报告")
                self.write_report(
                    cs.API_TEST_FAIL % (name, number, method, testUrl, _headers,_data, expectCode, actualCode))
            else:
                logging.info("新增一条接口成功报告")
                self.write_report(cs.API_TEST_SUCCESS % (name, number, method, testUrl, _headers,_data, expectCode, actualCode))
Exemplo n.º 3
0
def get_application() -> FastAPI:
    project_name = get_config().project_name
    debug = get_config().debug
    version = get_config().version
    prefix = get_config().api_prefix

    application = FastAPI(title=project_name, debug=debug, version=version)
    application.include_router(api_router, prefix=prefix)
    return application
Exemplo n.º 4
0
def create_app() -> FastAPI:
    app = FastAPI(
        title='Hide',
        description='Hide API',
        version='1.0.0',
        docs_url=None if get_config().ENV == 'production' else '/docs',
        redoc_url=None if get_config().ENV == 'production' else '/redoc',
    )
    init_routers(app=app)
    init_cors(app=app)
    init_listeners(app=app)
    return app
Exemplo n.º 5
0
def get_application() -> FastAPI:
    project_name = get_config().project_name
    debug = get_config().debug
    version = get_config().version
    prefix = get_config().api_prefix

    application = FastAPI(title=project_name, debug=debug, version=version)
    application.include_router(api_router, prefix=prefix)
    #TODO: logging
    print(f"init application with\n\tprefix: {prefix}\n\tversion: {version}",
          flush=True)
    return application
Exemplo n.º 6
0
def create_app() -> FastAPI:
    app = FastAPI(
        title="Hide",
        description="Hide API",
        version="1.0.0",
        docs_url=None if get_config().ENV == "production" else "/docs",
        redoc_url=None if get_config().ENV == "production" else "/redoc",
        dependencies=[Depends(logging)])
    init_routers(app=app)
    init_cors(app=app)
    init_listeners(app=app)
    init_middleware(app=app)
    return app
Exemplo n.º 7
0
 def get_prepare_sql(self, filename, key):
     """
     获取预备执行的SQL
     :param title: 配置文件头信息
     :param key: 配置文件值
     :return: Value
     """
     try:
         conf.get_config(filename)
         value = conf.get_data(title=cs.TITLE, key=key)
         return value
     except Exception, e:
         logging.error("获取用例参数值失败 %s" % e)
Exemplo n.º 8
0
def GetYear(fuseau = config.get_config('timezone')):
    """fonction de récupération de l'année
    :param fuseau:      fuseau horaire ciblé  initialisé avec le fuseau horaire défini dans le fichier de config
    :returns:           retourne l'heure les minutes et les secondes courantes
    :rtype:             number
    """
    return GetTimestamp(fuseau, 1).strftime('%Y')
Exemplo n.º 9
0
def GetDate(fuseau = config.get_config('timezone')):
    """fonction de récupération de la date
    :param fuseau:      fuseau horaire ciblé  initialisé avec le fuseau horaire défini dans le fichier de config
    :returns:           retourne le jour le mois et l'année
    :rtype:             string
    """
    return GetTimestamp(fuseau, 1).strftime('%d/%m/%Y')
Exemplo n.º 10
0
def GetDay(fuseau = config.get_config('timezone')):
    """fonction de récupération du jour
    :param fuseau:      fuseau horaire ciblé  initialisé avec le fuseau horaire défini dans le fichier de config
    :returns:           retourne la position menssuelle du jour en cours
    :rtype:             number
    """
    return GetTimestamp(fuseau, 1).strftime('%d')
Exemplo n.º 11
0
def GetSecond(fuseau = config.get_config('timezone')):
    """fonction de récupération des secondes
    :param fuseau:      fuseau horaire ciblé  initialisé avec le fuseau horaire défini dans le fichier de config
    :returns:           retourne la seconde à deux chiffres en cours
    :rtype:             number
    """
    return GetTimestamp(fuseau, 1).strftime('%S')
Exemplo n.º 12
0
    async def authenticate(
            self, conn: HTTPConnection) -> Tuple[bool, Optional[CurrentUser]]:
        current_user = CurrentUser()
        authorization: str = conn.headers.get("Authorization")
        if not authorization:
            return False, current_user

        config = get_config()
        try:
            scheme, credentials = authorization.split(" ")
            if scheme.lower() != "bearer":
                return False, current_user
        except ValueError:
            return False, current_user

        if not credentials:
            return False, current_user

        try:
            payload = jwt.decode(
                credentials,
                config.JWT_SECRET_KEY,
                algorithms=[config.JWT_ALGORITHM],
            )
            user_id = payload.get("user_id")
        except jwt.exceptions.PyJWTError:
            return False, current_user

        current_user.id = user_id
        return True, current_user
Exemplo n.º 13
0
async def predict_on_image(image: UploadFile = File(...)):

    # tested with:
    #  curl -F "image=@C:\IMAG5746.jpg" http://f963acd213e2.ngrok.io/api/v0/infer --output 121212.jpg

    # uploaded file path-name    
    save_name = image.filename    
    save_path = get_config().save_path
    
    # clean up old prediction files
    try:
        await delete_tmp_files(save_path)        
    except Exception as ex:
        raise HTTPException(status_code=500, detail=str(ex))

    # save uploaded file   
    with open(Path(save_path, save_name), "wb") as buffer:
        shutil.copyfileobj(image.file, buffer)

    # call predicting routine
    try:        
        results = image_preprocess(bot, unet, save_path, save_name, debug_chat_id)          
    except Exception as ex:
        raise HTTPException(status_code=500, detail=str(ex))
    
    return FileResponse(str(Path(save_path, results[0])))
Exemplo n.º 14
0
def GetMonth(fuseau = config.get_config('timezone')):
    """fonction de récupération du mois
    :param fuseau:      fuseau horaire ciblé  initialisé avec le fuseau horaire défini dans le fichier de config
    :returns:           retourne le numéro du mois en cours
    :rtype:             number
    """
    return GetTimestamp(fuseau, 1).strftime('%m')
Exemplo n.º 15
0
 def __init__(self) -> None:
     config = get_config()
     assert os.path.isfile(
         config.weights), f"no such file: {config.weights}"
     assert config.backbone != None, "backbone is None"
     assert config.labels != None, "labels is none"
     self.config = config
     self.model = None
Exemplo n.º 16
0
def execute_case(filename):
        """
        执行接口测试用例的方法
        :param filename: 用例文件名称
        :return: 测试结果
        """
        conf.get_config(filename)

        list = eval(conf.get_title_list())

        for i in range(1, len(list)):
            title = list[i]

            number = conf.get_data(title, key=cs.NUMBER)

            name = conf.get_data(title, key=cs.NAME)
            method = conf.get_data(title, key=cs.METHOD)
            url = conf.get_data(title, key=cs.URL)
            data = conf.get_data(title, key=cs.DATA)
            _data = request.json.dumps(data,ensure_ascii=False,indent=4)
            headers = eval(conf.get_data(title, key=cs.HEADERS))
            # headers['Cookie']=cookie
            _headers = request.json.dumps(headers,ensure_ascii=False,indent=4)

            testUrl = cs.DOMAIN + url
            login = cs.LOGIN
            if(title == login):
                reponse = request.set_cookie_api(method, testUrl, data, headers)
                actualCode = str(reponse.get("code"))
            else:
                reponse = request.api(method, testUrl, data, headers)
                actualCode = str(reponse.get("code"))

            expectCode = str(conf.get_data(title, key=cs.CODE))

            if actualCode != expectCode:
                logging.info("新增一条接口失败报告")
                write_report(cs.API_TEST_FAIL % (name, number, method, testUrl, headers, data, reponse, expectCode, actualCode))
            else:
                logging.info("新增一条接口成功报告")
                write_report(cs.API_TEST_SUCCESS % (name, number, method, testUrl, headers, data, reponse, expectCode, actualCode))
Exemplo n.º 17
0
def GetTimestamp(fuseau = config.get_config('timezone'), date_format = 0):
    """fonction de récupération du timestamp actuel dans le fuseau horaire ciblé
    :param fuseau:      fuseau horaire ciblé  initialisé avec le fuseau horaire défini dans le fichier de config
    :param date_format: définit le retour soit sous forme de timestamp sous forme d'une date
    :returns:           date sous forme de timestamp ou de date formatée
    :rtype:             timestamp
    """
    timestamp      = datetime.now(timezone(fuseau))
    if date_format == 0:
        timestamp  = time.mktime(timestamp.timetuple())

    return timestamp
Exemplo n.º 18
0
def run_migrations_online():
    """Run migrations in 'online' mode.
    In this scenario we need to create an Engine
    and associate a connection with the context.
    """
    connectable = create_engine(get_config().DB_URL, poolclass=pool.NullPool)

    with connectable.connect() as connection:
        context.configure(connection=connection,
                          target_metadata=target_metadata)

        with context.begin_transaction():
            context.run_migrations()
Exemplo n.º 19
0
	def execute_case(self, filename):
		"""
		执行接口测试用例的方法
		:param filename: 用例文件名称
		:return: 测试结果
		"""
		conf.get_config(filename)
		list = eval(conf.get_title_list())
		# print("zheshi"+list)

		for i in range(1, len(list)):
			title = list[i]
			number = conf.get_data(title, key=cs.NUMBER)
			name = conf.get_data(title, key=cs.NAME)
			method = conf.get_data(title, key=cs.METHOD)
			url = conf.get_data(title, key=cs.URL)
			data = eval(conf.get_data(title, key=cs.DATA))
			_data = request.json.dumps(data, ensure_ascii=False, indent=4)
			headers = eval(conf.get_data(title, key=cs.HEADERS))
			_headers = request.json.dumps(headers, ensure_ascii=False, indent=4)
			testUrl = cs.TEST_URL + url
			actualCode = requests.request(method, testUrl, data=data, headers=headers)
			expectCode = conf.get_data(title, key=cs.CODE)
			# print(actualCode.status_code)
			response = json.loads(actualCode.text)
			if response["msg"] != expectCode:
				logging.info("新增一条接口失败报告")
				# response = json.loads(actualCode.text)
				# print(response)
				self.write_report(
					cs.API_TEST_FAIL % (name, number, method, testUrl, _headers, _data, expectCode, response["msg"],response))
				print("失败case编号",number)
				# actualCode.close()

			else:
				logging.info("新增一条接口成功报告")
				self.write_report(
					cs.API_TEST_SUCCESS % (name, number, method, testUrl, _headers, _data, expectCode, response["msg"],response))
				print(number)
Exemplo n.º 20
0
def create_app() -> FastAPI:
    config = get_config()
    app = FastAPI(
        title='Hide',
        description='Hide API',
        version='1.0.0',
        docs_url=None if config.ENV == 'production' else '/docs',
        redoc_url=None if config.ENV == 'production' else '/redoc',
    )
    init_routers(app=app)
    init_listeners(app=app)
    app.add_middleware(DBSessionMiddleware, db_url=config.DB_URL)

    return app
Exemplo n.º 21
0
def run_migrations_offline():
    """Run migrations in 'offline' mode.
    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.
    Calls to context.execute() here emit the given string to the
    script output.
    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(
        url=get_config().DB_URL,
        target_metadata=target_metadata,
        literal_binds=True,
        dialect_opts={"paramstyle": "named"},
    )

    with context.begin_transaction():
        context.run_migrations()
Exemplo n.º 22
0
def _real_main():
    utils.insure_filesystem()
    utils.setup_logging()
    logging.info(
        f"Starting UtopiaForReddit version {variables.version_human_friendly}")
    utils.setup_caching()
    logging.info("Loading config and saving defaults if needed.")
    variables.config = config.get_config().load().save_defaults()
    logging.info("Starting ui framework")
    loop = asyncio.get_event_loop()
    loop.set_exception_handler(global_exception_handler)
    app = WxAsyncApp(loop=loop)
    loop.set_debug(True)
    am = account_manager.AccountManager(True)
    # The account manager is either shown or passed through. In either case, the show call, are done in the create method of the account manager.
    # and then the main ui will be shown.
    # check for updates
    StartCoroutine(updater.check_for_updates(), am)
    # Show program tips
    tips.show_tips(None, False)
    loop.run_until_complete(app.MainLoop())
Exemplo n.º 23
0
async def tg_predict(msg: Message):

    # get chat_id and qty of images from TG
    msg = msg.dict()['message']
    chat_id = msg['chat']['id']       
    
    # process only if image exists
    if "photo" in msg.keys(): 

        # set variables                    
        n_photos = len(msg['photo'])-1    
        save_name = msg['photo'][n_photos]['file_id'] + ".jpg"
        save_path = get_config().save_path
        
        # get image from TG server
        file_info = bot.get_file(msg['photo'][n_photos]['file_id'])
        downloaded_file = bot.download_file(file_info.file_path)        
        
        # save image locally
        with open(Path(save_path, save_name),'wb') as new_file:
            new_file.write(downloaded_file) 
        
        # call predicting routines
        try:
            results = image_preprocess(bot, unet, save_path, save_name, chat_id)        
        except Exception as ex:
            raise HTTPException(status_code=500, detail=str(ex))
        
        # clean up all prediction files
        try:
            await delete_tmp_files(save_path)        
        except Exception as ex:
            raise HTTPException(status_code=500, detail=str(ex))
            
        return {"detail":"file processed"}

    else:
        bot.send_message(chat_id, 'Пришлите мне картинку, пожалуйста, я в другом виде данные не понимаю.')
        
Exemplo n.º 24
0
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker

from core.config import get_config

engine = create_engine(get_config().DB_URL)
session = scoped_session(
    sessionmaker(
        autocommit=False,
        autoflush=False,
        bind=engine,
    ))
Base = declarative_base()
Exemplo n.º 25
0
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker

from core.config import get_config

engine = create_engine(get_config().db_url)
session = scoped_session(
    sessionmaker(
        autocommit=False,
        autoflush=False,
        bind=engine,
    ))
Base = declarative_base()
Exemplo n.º 26
0
import uvicorn
from core.config import get_config

if __name__ == "__main__":
    config = get_config()
    uvicorn.run(
        app="app:app",
        host=config.APP_HOST,
        port=config.APP_PORT,
        reload=True if config.ENV != "production" else False,
        workers=1,
    )
Exemplo n.º 27
0
 def __init__(self):
     self.config = get_config()
Exemplo n.º 28
0
 def __init__(self):
     self.corpus = get_corpus()
     self.config = get_config()
     self.model = None
     self.vectorizer = None
Exemplo n.º 29
0
from fastapi import APIRouter, HTTPException, UploadFile, File  
from fastapi.responses import FileResponse
from core.unet.u_net import *
from core.config import get_config
import telebot
import shutil
import os
from pathlib import Path
from pydantic import BaseModel

# instantiate model
crop_size = get_config().crop_size
unet = define_unet(crop_size, crop_size, optimizer=Adam(learning_rate=1e-4))
unet.load_weights(get_config().weights)

# instantiate TG bot
bot = telebot.TeleBot(get_config().token)

# set TG chat for tests
if get_config().debug:
    debug_chat_id = get_config().debug_chat
else:
    debug_chat_id = None

router = APIRouter()

class Message(BaseModel):
        message: dict        

async def delete_tmp_files(targ_folder):
    '''Delete all files in a predictions folder'''
Exemplo n.º 30
0
class Corpus:
    _config = get_config()

    @classmethod
    def read_corpus_from_file(cls, file_path):
        """
        read interrogative train Params from local
        """
        return pd.read_csv(file_path)

    @classmethod
    def perform_word_segment(cls, corpus):
        """
        process word segmenting use jieba tokenizer
        """

        jieba.suggest_freq('小艾', True)
        jieba.suggest_freq('艾佳', True)
        jieba.suggest_freq('艾佳家居', True)
        jieba.suggest_freq('米兰星光', True)
        jieba.suggest_freq('诗意新居', True)
        jieba.suggest_freq('雅君壹格', True)
        jieba.suggest_freq('以爱之名', True)
        jieba.suggest_freq('艾师傅', True)
        jieba.suggest_freq('地暖', True)

        tokenizer = jieba.Tokenizer()
        corpus['tokens'] = corpus.content.astype('str').apply(
            lambda x: list(tokenizer.cut(x)))
        return corpus

    @classmethod
    def feature_extract(cls, train, tfidf_vectorizer_name, tfidf_save=True):
        """
        feature engineering, extract Tf-idf feature
        """
        vectorizer = TfidfVectorizer(smooth_idf=True,
                                     analyzer=analyzer,
                                     ngram_range=(1, 1),
                                     min_df=1,
                                     norm='l1')
        sparse_vector = vectorizer.fit_transform(
            train.tokens.apply(lambda x: ' '.join(x)).tolist())
        label = train.label.tolist()

        # tf-idf vectorizer save
        if tfidf_save:
            joblib.dump(
                vectorizer,
                cls._config.get(
                    'interrogative',
                    'tfidf_vectorizer_path').format(tfidf_vectorizer_name))

        return sparse_vector, label

    @classmethod
    def generator(cls, tfidf_vectorizer_name):
        """
        pre-process corpus and extract features
        """
        corpus_path = cls._config.get('interrogative', 'corpus_path')
        corpus = cls.read_corpus_from_file(corpus_path)
        train = cls.perform_word_segment(corpus)
        return cls.feature_extract(train, tfidf_vectorizer_name)

    def __init__(self):
        raise NotImplementedError()
Exemplo n.º 31
0
# Copyright (C)
# IGP @ ETHZ

# Code:

# Import python dependencies
import tensorflow as tf

# Import custom functions
from core import config
from core import network

print('The version of TF is {}'.format(tf.__version__))

config_arguments, unparsed_arguments = config.get_config()


def main(config_arguments):

    # Build the model and optimizer
    smooth_net = network.NetworkBuilder(config_arguments)

    print('Run mode "{}" selected.'.format(config_arguments.run_mode))
    # Select the run mode
    if config_arguments.run_mode == "train":
        smooth_net.train()
    elif config_arguments.run_mode == "test":

        # Evaluate the network
        smooth_net.test()
Exemplo n.º 32
0
from fastapi import FastAPI
import telebot
from api.v0.routes.api import router as api_router
from core.config import get_config


def get_application() -> FastAPI:
    project_name = get_config().project_name
    debug = get_config().debug
    version = get_config().version
    prefix = get_config().api_prefix

    application = FastAPI(title=project_name, debug=debug, version=version)
    application.include_router(api_router, prefix=prefix)
    return application


# TG bot setup

WEBHOOK_HOST = get_config().WEBHOOK_HOST
WEBHOOK_PORT = 443
WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/%s" % ("api/v0/tg")

bot = telebot.TeleBot(get_config().token)
bot.remove_webhook()
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH)

app = get_application()
Exemplo n.º 33
0
async def root() -> Pong:
    project_name = get_config().project_name
    print(project_name)
    version = get_config().version
    return Pong(pong=f"{project_name}, version {version}")
Exemplo n.º 34
0
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker

from core.config import get_config

engine = create_engine(get_config().DB_URL, pool_recycle=3600)
session = scoped_session(
    sessionmaker(
        autocommit=False,
        autoflush=False,
        bind=engine,
    ))
Base = declarative_base()
Exemplo n.º 35
0
from tensorflow.keras import Model
from tensorflow.keras.layers import Input, Concatenate, Convolution2D, MaxPooling2D, UpSampling2D
from pathlib import Path
from tensorflow.keras.optimizers import Adam
import cv2
import os
import time
import numpy as np
from core.config import get_config

crop_size = get_config().crop_size


def define_unet(img_rows, img_cols, optimizer):
    ''' Defines U-net with img_rows*img_cols input.
        Output: Keras Model.'''

    inputs = Input(shape=(img_rows, img_cols, 3))
    conv1 = Convolution2D(32, (3, 3), activation='relu',
                          padding='same')(inputs)
    conv1 = Convolution2D(32, (3, 3), activation='relu', padding='same')(conv1)
    pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)

    conv2 = Convolution2D(64, (3, 3), activation='relu', padding='same')(pool1)
    conv2 = Convolution2D(64, (3, 3), activation='relu', padding='same')(conv2)
    pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)

    conv3 = Convolution2D(128, (3, 3), activation='relu',
                          padding='same')(pool2)
    conv3 = Convolution2D(128, (3, 3), activation='relu',
                          padding='same')(conv3)
Exemplo n.º 36
0
def hello_world():
    print(dir(dbengine))
    return {"name": config.get_config("APP_NAME"), "age": 12}