我有六个int变量:currentMonth,currentDay,monthFrom,dayFrom,monthUntil和dayUntil.我需要检查今天的月份和日期是否在变量的范围内.
例如,如果currentMonth = 1,currentDay = 2,monthFrom = 11,dayFrom =
24,monthUntil = 3和dayUntil = 3日期是在间隔,并且该方法应返回true.
我不知道怎么做.除了使用ifs检查每个可能的结果之外还有其他选择吗?
作为 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)