Skip to content

Commit 9843cbf

Browse files
committed
add tests for reservations
1 parent 38a6d4b commit 9843cbf

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

tests/integration/test_reservation.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#########################################################################
2+
# test_reservation.py - reservation integration tests
3+
#########################################################################
4+
# Copyright (C) 2025 Toni Harzendorf <[email protected]>
5+
#
6+
# This file is part of PySlurm
7+
#
8+
# PySlurm is free software; you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation; either version 2 of the License, or
11+
# (at your option) any later version.
12+
13+
# PySlurm is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License along
19+
# with PySlurm; if not, write to the Free Software Foundation, Inc.,
20+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21+
"""test_reservation.py - integration test reservation functionalities."""
22+
23+
import pyslurm
24+
from datetime import datetime
25+
26+
27+
def test_api_calls():
28+
start = datetime.now()
29+
duration = "1-00:00:00"
30+
resv = pyslurm.Reservation(
31+
name="testing",
32+
start_time=start,
33+
duration=duration,
34+
users=["root"],
35+
node_count=1,
36+
)
37+
resv.create()
38+
39+
reservations = pyslurm.Reservations.load()
40+
resv = reservations["testing"]
41+
assert len(reservations) == 1
42+
assert resv.name == "testing"
43+
assert resv.to_dict()
44+
45+
assert resv.start_time == int(start.timestamp())
46+
assert resv.duration == 60 * 24
47+
assert resv.end_time == resv.start_time + (60 * 60 * 24)
48+
49+
resv.duration += 60 * 24
50+
resv.modify()
51+
52+
resv = pyslurm.Reservation.load("testing")
53+
assert resv.name == "testing"
54+
assert resv.start_time == int(start.timestamp())
55+
assert resv.duration == 2 * 60 * 24
56+
assert resv.end_time == resv.start_time + (2 * 60 * 60 * 24)
57+
58+
resv.delete()
59+
reservations = pyslurm.Reservations.load()
60+
assert len(reservations) == 0

tests/unit/test_reservation.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#########################################################################
2+
# test_reservation.py - reservation unit tests
3+
#########################################################################
4+
# Copyright (C) 2025 Toni Harzendorf <[email protected]>
5+
#
6+
# This file is part of PySlurm
7+
#
8+
# PySlurm is free software; you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation; either version 2 of the License, or
11+
# (at your option) any later version.
12+
13+
# PySlurm is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License along
19+
# with PySlurm; if not, write to the Free Software Foundation, Inc.,
20+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21+
"""test_reservation.py - Unit test basic reservation functionalities."""
22+
23+
import pyslurm
24+
from datetime import datetime
25+
26+
27+
def test_create_instance():
28+
resv = pyslurm.Reservation("test")
29+
assert resv.name == "test"
30+
assert resv.accounts == []
31+
assert resv.start_time == None
32+
assert resv.end_time == None
33+
assert resv.duration == 0
34+
assert resv.is_active is False
35+
assert resv.cpus_by_node == {}
36+
assert resv.to_dict()
37+
38+
start = datetime.now()
39+
resv.start_time = start
40+
resv.duration = "1-00:00:00"
41+
42+
assert resv.start_time == int(start.timestamp())
43+
assert resv.duration == 60 * 24
44+
assert resv.end_time == resv.start_time + (60 * 60 * 24)
45+
46+
resv.duration += pyslurm.utils.timestr_to_mins("1-00:00:00")
47+
48+
assert resv.start_time == int(start.timestamp())
49+
assert resv.duration == 2 * 60 * 24
50+
assert resv.end_time == resv.start_time + (2 * 60 * 60 * 24)
51+
52+
start = datetime.fromisoformat("2022-04-03T06:00:00")
53+
end = resv.end_time
54+
resv.start_time = int(start.timestamp())
55+
56+
assert resv.start_time == int(start.timestamp())
57+
assert resv.end_time == end
58+
assert resv.duration == int((resv.end_time - resv.start_time) / 60)
59+
60+
duration = resv.duration
61+
resv.end_time += 60 * 60 * 24
62+
assert resv.start_time == int(start.timestamp())
63+
assert resv.end_time == end + (60 * 60 * 24)
64+
assert resv.duration == duration + (60 * 24)

0 commit comments

Comments
 (0)