Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ dist/**
.env
libs/**
venv/**
.testenv/
6 changes: 5 additions & 1 deletion pbspro/test/pbspro_test/driver_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import datetime
import time
from typing import Any, Dict
from unittest.mock import Mock

import pytest
from hpc.autoscale.job.schedulernode import SchedulerNode

from pbspro.constants import PBSProJobStates
from pbspro.driver import PBSProDriver, parse_scheduler_node
from pbspro.parser import PBSProParser, get_pbspro_parser, set_pbspro_parser
from pbspro.pbscmd import PBSCMD
from pbspro.resource import BooleanType, LongType, PBSProResourceDefinition, StringType


Expand Down Expand Up @@ -51,9 +53,10 @@ def test_parse_scheduler_node() -> None:
def test_down_long_enough() -> None:
node = SchedulerNode("localhost", {})
now = datetime.datetime.now()
pbscmd = Mock(spec=PBSCMD)

# False: missing last_state_change_time
driver = PBSProDriver({}, down_timeout=300)
driver = PBSProDriver({}, pbscmd=pbscmd, down_timeout=300)
assert not driver._down_long_enough(now, node)

# False: last_state_change_time < 300 seconds ago
Expand All @@ -69,6 +72,7 @@ def test_down_long_enough() -> None:
last_state_change_time
)
assert driver._down_long_enough(now, node)
assert pbscmd.mock_calls == []


def _pbs_job(
Expand Down
22 changes: 22 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euo pipefail

PROJECT_ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
cd "$PROJECT_ROOT"

"${PYTHON:-python3}" -m venv --clear "$PROJECT_ROOT/.testenv"
TEST_PYTHON="$PROJECT_ROOT/.testenv/bin/python"
SCALELIB_VERSION=$("$TEST_PYTHON" -c 'from package import SCALELIB_VERSION; print(SCALELIB_VERSION)')
API_VERSION=$("$TEST_PYTHON" -c 'from package import CYCLECLOUD_API_VERSION; print(CYCLECLOUD_API_VERSION)')
SCALELIB=${CYCLECLOUD_SCALELIB:-"https://github.com/Azure/cyclecloud-scalelib/archive/refs/tags/$SCALELIB_VERSION.tar.gz"}
API_WHEEL=${CYCLECLOUD_API:-"https://github.com/Azure/cyclecloud-pbspro/releases/download/2023-03-29-bins/cyclecloud_api-$API_VERSION-py2.py3-none-any.whl"}

"$TEST_PYTHON" -m pip install --upgrade pip 'setuptools<72' wheel
"$TEST_PYTHON" -m pip install --no-build-isolation \
"$API_WHEEL" "$SCALELIB" -e "$PROJECT_ROOT/pbspro" pytest hypothesis PyYAML

TEST_PATHS=(pbspro/test)
if [[ -d "$PROJECT_ROOT/test_packaging" ]]; then
TEST_PATHS+=(test_packaging)
fi
exec "$TEST_PYTHON" -m pytest "${TEST_PATHS[@]}" "$@"
Loading