POMDPPlanners.tests package

Subpackages

Submodules

POMDPPlanners.tests.conftest module

POMDPPlanners.tests.test_metric_consistency module

POMDPPlanners.tests.test_metric_consistency_utils module

Reusable test utilities for verifying metric name consistency.

This module provides generic test functions to verify that the metric names declared by environments and policies match the actual metrics they produce.

POMDPPlanners.tests.test_metric_consistency_utils.verify_environment_metric_consistency(environment, histories)[source]

Verify that environment’s declared metric names match actual produced metrics.

This function checks that: 1. get_metric_names() returns the exact set of metric names 2. compute_metrics() produces MetricValue objects with those exact names 3. No extra or missing metrics

Parameters:
  • environment (Environment) – Environment instance to test

  • histories (List[History]) – List of episode histories to pass to compute_metrics()

Raises:

AssertionError – If declared and actual metric names don’t match

Return type:

None

Example

>>> from POMDPPlanners.environments.tiger_pomdp import TigerPOMDP
>>> from POMDPPlanners.simulations.episodes import run_episode
>>> from POMDPPlanners.core.belief import get_initial_belief
>>> from POMDPPlanners.planners.mcts_planners.pomcp import POMCP
>>> from POMDPPlanners.utils.logger import get_logger
>>>
>>> # Set up environment and run episodes
>>> env = TigerPOMDP(discount_factor=0.95)
>>> policy = POMCP(environment=env, discount_factor=0.95, depth=5,
...                exploration_constant=1.0, name="test", n_simulations=10)
>>> belief = get_initial_belief(env, n_particles=10)
>>> logger = get_logger("test", debug=False)
>>> history = run_episode(env, policy, belief, num_steps=3, logger=logger)
>>>
>>> # Verify consistency
>>> verify_environment_metric_consistency(env, [history])  # Should pass without error
POMDPPlanners.tests.test_metric_consistency_utils.verify_policy_class_metric_consistency(policy_class, policy_instance, belief)[source]

Verify policy class and instance metric consistency.

This is a convenience wrapper around verify_policy_metric_consistency() that also checks the policy class directly.

Parameters:
  • policy_class (Type[Policy]) – Policy class to test

  • policy_instance (Policy) – Instance of the policy class

  • belief (Belief) – Belief state to pass to policy.action()

Raises:

AssertionError – If declared and actual info variable names don’t match

Return type:

None

Example

>>> from POMDPPlanners.environments.tiger_pomdp import TigerPOMDP
>>> from POMDPPlanners.planners.mcts_planners.pomcp import POMCP
>>> from POMDPPlanners.core.belief import get_initial_belief
>>>
>>> env = TigerPOMDP(discount_factor=0.95)
>>> policy = POMCP(environment=env, discount_factor=0.95, depth=5,
...                exploration_constant=1.0, name="test", n_simulations=10)
>>> belief = get_initial_belief(env, n_particles=10)
>>>
>>> verify_policy_class_metric_consistency(POMCP, policy, belief)
POMDPPlanners.tests.test_metric_consistency_utils.verify_policy_metric_consistency(policy, belief)[source]

Verify that policy’s declared info variable names match actual produced names.

This function checks that: 1. get_info_variable_names() returns the exact set of info variable names 2. action() produces PolicyInfoVariable objects with those exact names 3. No extra or missing info variables

Parameters:
  • policy (Policy) – Policy instance to test

  • belief (Belief) – Belief state to pass to policy.action()

Raises:

AssertionError – If declared and actual info variable names don’t match

Return type:

None

Example

>>> from POMDPPlanners.environments.tiger_pomdp import TigerPOMDP
>>> from POMDPPlanners.planners.mcts_planners.pomcp import POMCP
>>> from POMDPPlanners.core.belief import get_initial_belief
>>>
>>> # Set up policy
>>> env = TigerPOMDP(discount_factor=0.95)
>>> policy = POMCP(environment=env, discount_factor=0.95, depth=5,
...                exploration_constant=1.0, name="test", n_simulations=10)
>>> belief = get_initial_belief(env, n_particles=10)
>>>
>>> # Verify consistency
>>> verify_policy_metric_consistency(policy, belief)  # Should pass without error

POMDPPlanners.tests.test_setup module

Tests to verify package installation and basic functionality.

POMDPPlanners.tests.test_setup.test_imports()[source]

Test that key package modules can be imported.

Purpose: Validates that all main POMDPPlanners modules can be successfully imported without errors

Given: POMDPPlanners package with core, planners, environments, utils, and simulations submodules When: Each main module is imported using importlib.import_module Then: All imports succeed without ImportError exceptions

Test type: unit

POMDPPlanners.tests.test_setup.test_package_installed()[source]

Test that the package is installed and importable.

Purpose: Validates that POMDPPlanners package is properly installed and accessible with correct version

Given: POMDPPlanners package should be installed in the Python environment with version 0.2.0 When: Package is imported and version is checked Then: Import succeeds without error and version matches expected 0.2.0

Test type: unit

POMDPPlanners.tests.test_setup.test_required_packages()[source]

Test that all required packages are installed with correct versions.

Purpose: Validates that all dependencies declared in pyproject.toml are properly installed with compatible versions

Given: POMDPPlanners package installed with dependencies declared in pyproject.toml When: Each required package is checked against installed packages using importlib.metadata Then: All requirements are satisfied without PackageNotFoundError or version conflicts

Test type: unit