|
| 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