小编B. *_*ray的帖子

如何检查日期是否在java之间的间隔?

我有六个int变量:currentMonth,currentDay,monthFrom,dayFrom,monthUntildayUntil.我需要检查今天的月份和日期是否在变量的范围内.

例如,如果currentMonth = 1,currentDay = 2,monthFrom = 11,dayFrom = 24,monthUntil = 3dayUntil = 3日期是在间隔,并且该方法应返回true.

我不知道怎么做.除了使用ifs检查每个可能的结果之外还有其他选择吗?

java date

6
推荐指数
2
解决办法
1951
查看次数

如何在测试 FastAPI 应用程序时触发生命周期启动和关闭?

作为 FastAPI 的新手,我正在努力测试比我在教程中看到的稍微困难的代码。fastapi_cache我像这样使用模块和 Redis:

from fastapi import Depends, FastAPI, Query, Request
from fastapi_cache.backends.redis import CACHE_KEY, RedisCacheBackend
from fastapi_cache import caches, close_caches

app = FastAPI()

def redis_cache():
    return caches.get(CACHE_KEY)    

@app.get('/cache')
async def test(
    cache: RedisCacheBackend = Depends(redis_cache),
    n: int = Query(
        ..., 
        gt=-1
    )
):  
    # code that uses redis cache

@app.on_event('startup')
async def on_startup() -> None:
    rc = RedisCacheBackend('redis://redis')
    caches.set(CACHE_KEY, rc)

@app.on_event('shutdown')
async def on_shutdown() -> None:
    await close_caches()
Run Code Online (Sandbox Code Playgroud)

test_main.py 看起来像这样:

import pytest
from httpx import AsyncClient
from …
Run Code Online (Sandbox Code Playgroud)

python testing redis pytest fastapi

4
推荐指数
1
解决办法
4973
查看次数

标签 统计

date ×1

fastapi ×1

java ×1

pytest ×1

python ×1

redis ×1

testing ×1