Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""validate_range must reject non-finite opacity-like values."""

from __future__ import annotations

import pytest

from cli_anything.obs_studio.utils.obs_utils import validate_range


def test_nan_rejected() -> None:
with pytest.raises(ValueError, match="finite"):
validate_range(float("nan"), 0.0, 1.0, "Opacity")


def test_inf_rejected() -> None:
with pytest.raises(ValueError, match="finite"):
validate_range(float("inf"), 0.0, 1.0, "Opacity")


def test_in_range_ok() -> None:
assert validate_range(0.5, 0.0, 1.0, "Opacity") == 0.5
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""OBS Studio CLI - JSON helpers and utilities."""

import json
import math
import os
import copy
from typing import Dict, Any, List, Optional
Expand All @@ -27,6 +28,8 @@ def unique_name(name: str, items: List[Dict[str, Any]], key: str = "name") -> st
def validate_range(value: float, min_val: float, max_val: float, name: str) -> float:
"""Validate that a value is within range."""
val = float(value)
if not math.isfinite(val):
raise ValueError(f"{name} must be a finite number, got {val}")
if val < min_val or val > max_val:
raise ValueError(f"{name} must be between {min_val} and {max_val}, got {val}")
return val
Expand Down
Loading