Skip to content

Launch Module Testsยถ

Overviewยถ

The launch module tests (test_launch.py) verify the command launching functionality, including scheduler detection and bash command execution.

Test Casesยถ

test_command_existsยถ

Tests the command existence checking function.

1
2
3
4
5
6
7
def test_command_exists(self):
    """Test command_exists function."""
    # Test with a command that should exist
    assert launch.command_exists("python") is True
    
    # Test with a command that should not exist
    assert launch.command_exists("nonexistent_command_xyz") is False

test_get_schedulerยถ

Verifies the scheduler detection functionality.

1
2
3
4
5
6
def test_get_scheduler(self):
    """Test get_scheduler function."""
    scheduler = launch.get_scheduler()
    assert isinstance(scheduler, str)
    # Should be one of the known schedulers or "UNKNOWN"
    assert scheduler in ["PBS", "SLURM", "UNKNOWN"]

test_run_bash_commandยถ

Tests the bash command execution function.

1
2
3
4
5
def test_run_bash_command(self):
    """Test run_bash_command function."""
    # Test a simple command
    result = launch.run_bash_command("echo 'test'")
    assert result is not None

test_get_scheduler_from_pbsยถ

Verifies scheduler detection from PBS environment variables.

1
2
3
4
5
6
def test_get_scheduler_from_pbs(self, mock_pbs_env):
    """Test get_scheduler function with PBS environment."""
    # Set PBS environment variables
    os.environ["PBS_JOBID"] = "test.job"
    scheduler = launch.get_scheduler()
    assert scheduler == "PBS"

test_get_scheduler_from_slurmยถ

Tests scheduler detection from SLURM environment variables.

def test_get_scheduler_from_slurm(self):
    """Test get_scheduler function with SLURM environment."""
    # Save original environment
    original_env = os.environ.copy()
    
    # Set SLURM environment variables
    os.environ["SLURM_JOB_ID"] = "test.job"
    scheduler = launch.get_scheduler()
    assert scheduler == "SLURM"
    
    # Restore original environment
    os.environ.clear()
    os.environ.update(original_env)

Running Testsยถ

python -m pytest tests/test_launch.py