def test_unknown_logging(caplog): assert parse_bool(UNKNOWN[-1], fallback=True, warn=True) is True wrn = caplog.records[0] assert caplog.records == [wrn] assert wrn.levelname == "WARNING" assert "fallback" in wrn.message assert "True" in wrn.message
def test_logging(caplog): assert parse_bool(WRONG[-1], fallback=True, warn=True) is True exc, wrn = caplog.records assert exc.levelname == "ERROR" assert wrn.levelname == "WARNING" assert "Exception" in exc.message assert "lower" in exc.message assert "fallback" in wrn.message assert "True" in wrn.message
MIGR_DIR = path.abspath(path.join(ROOT_DIR, "migrate")) DATABASE = getenv("DATABASE", "sqlite://") DATABASE_DEV = getenv( "DATABASE_DEV", f"sqlite:///{path.abspath(path.join(ROOT_DIR, 'database_dev.sqlite'))}", ) SECRET_FILE = getenv("SECRET_FILE", "secret.key") SECRET_BASE = getenv("SECRET_BASE", ROOT_DIR) BLOCK_FILE = getenv("BLOCK_FILE", "blocklist.txt") BLOCK_BASE = getenv("BLOCK_BASE", ROOT_DIR) CSRF_STRICT = parse_bool(getenv("CSRF_STRICT", "true"), fallback=True) THEME = getenv("THEME", "default") TITLE = getenv("TITLE", APP_NAME) HTML_LANG = getenv("HTML_LANG", "en") DELAY_MIN = parse_int(getenv("DELAY_MIN", "0"), fallback=0) DELAY_MAX = parse_int(getenv("DELAY_MAX", "30"), fallback=30) DELAY_DEF = parse_int(getenv("DELAY_DEF", "6"), fallback=6) DELAY_STP = parse_int(getenv("DELAY_STP", "3"), fallback=3) SYM_POOL = "".join((ascii_letters, digits)) SYM_MINI = parse_int(getenv("SYM_MINI", "3"), fallback=3) PAGINATION = parse_int(getenv("PAGINATION", "100"), fallback=100)
def test_simple(): for val in TRUTHY: assert parse_bool(val, warn=False) is True for val in FALSY: assert parse_bool(val, warn=False) is False
def test_silent(caplog): assert parse_bool(WRONG[-1], fallback=True, warn=False) is True assert not caplog.records
def test_unknown_fallback(): for val in UNKNOWN: assert parse_bool(val, fallback=True, warn=False) is True assert parse_bool(val, fallback=False, warn=False) is False
def test_fallback(): for val in WRONG: assert parse_bool(val, fallback=True, warn=False) is True assert parse_bool(val, fallback=False, warn=False) is False
def test_case_insensitive(): for val in TRUTHY: assert parse_bool(val.upper(), warn=False) is True for val in FALSY: assert parse_bool(val.upper(), warn=False) is False