Skip to content

Jobs Module TestsΒΆ

OverviewΒΆ

The jobs module tests (test_jobs.py) verify the job management and scheduling functionality, including environment variable handling and job directory management.

Test CasesΒΆ

test_get_jobidΒΆ

Tests the job ID retrieval function.

1
2
3
4
5
6
def test_get_jobid(self, mock_pbs_env):
    """Test get_jobid function."""
    jobid = jobs.get_jobid()
    assert isinstance(jobid, str)
    # Should be the job ID without the domain part
    assert jobid == "12345"

test_get_jobdir_from_envΒΆ

Verifies the job directory retrieval from environment variables.

1
2
3
4
5
6
7
def test_get_jobdir_from_env(self, mock_pbs_env):
    """Test get_jobdir_from_env function."""
    jobdir = jobs.get_jobdir_from_env()
    assert isinstance(jobdir, Path)
    assert jobdir.exists()
    # Should be in the home directory under SCHEDULER-jobs/jobid
    assert str(jobdir).startswith(str(Path.home()))

test_jobfile_functionsΒΆ

Tests the job file path generation functions.

def test_jobfile_functions(self, mock_pbs_env):
    """Test jobfile path functions."""
    # Test shell jobfile
    jobfile_sh = jobs.get_jobfile_sh()
    assert isinstance(jobfile_sh, Path)
    assert jobfile_sh.suffix == ".sh"

    # Test yaml jobfile
    jobfile_yaml = jobs.get_jobfile_yaml()
    assert isinstance(jobfile_yaml, Path)
    assert jobfile_yaml.suffix == ".yaml"

    # Test json jobfile
    jobfile_json = jobs.get_jobfile_json()
    assert isinstance(jobfile_json, Path)
    assert jobfile_json.suffix == ".json"

test_check_schedulerΒΆ

Verifies the scheduler validation function.

1
2
3
4
5
6
7
8
def test_check_scheduler(self):
    """Test check_scheduler function."""
    # Test with valid scheduler
    assert jobs.check_scheduler("PBS") is True

    # Test with invalid scheduler should raise
    with pytest.raises(AssertionError):
        jobs.check_scheduler("INVALID_SCHEDULER")

Running TestsΒΆ

python -m pytest tests/test_jobs.py