Skip to content

Commit 801329f

Browse files
committed
tests: add Python resourcegraph tests
Problem: there are no tests for the Python resourcegraph class. Add some basic tests.
1 parent 911fe43 commit 801329f

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

t/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ set(ALL_TESTS
8585
t6002-graph-hwloc.t
8686
t8001-util-ion-R.t
8787
t9001-golang-basic.t
88+
python/t10001-resourcegraph.py
8889
)
8990
foreach(test ${ALL_TESTS})
9091
flux_add_test(NAME ${test}

t/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ TESTS = \
102102
t6001-match-formats.t \
103103
t6002-graph-hwloc.t \
104104
t8001-util-ion-R.t \
105-
t9001-golang-basic.t
105+
t9001-golang-basic.t \
106+
python/t10001-resourcegraph.py
106107

107108
check_SCRIPTS = $(TESTS)
108109

t/python/t10001-resourcegraph.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env python3
2+
3+
###############################################################
4+
# Copyright 2023 Lawrence Livermore National Security, LLC
5+
# (c.f. AUTHORS, NOTICE.LLNS, COPYING)
6+
#
7+
# This file is part of the Flux resource manager framework.
8+
# For details, see https://github.com/flux-framework.
9+
#
10+
# SPDX-License-Identifier: LGPL-3.0
11+
12+
import unittest
13+
import json
14+
import sys
15+
import pathlib
16+
17+
from pycotap import TAPTestRunner
18+
19+
# add fluxion to sys.path
20+
sys.path.insert(0, str(pathlib.Path(__file__).absolute().parents[2] / "src" / "python"))
21+
22+
from fluxion.resourcegraph.V1 import (
23+
FluxionResourceGraphV1,
24+
FluxionResourcePoolV1,
25+
FluxionResourceRelationshipV1,
26+
)
27+
28+
RV1 = {
29+
"version": 1,
30+
"execution": {
31+
"R_lite": [{"rank": "0", "children": {"core": "0-4"}}],
32+
"starttime": 0.0,
33+
"expiration": 0.0,
34+
"nodelist": ["compute01"],
35+
},
36+
}
37+
38+
RV1_2 = {
39+
"version": 1,
40+
"execution": {
41+
"R_lite": [{"rank": "0-10", "children": {"gpu": "0-1", "core": "0-7"}}],
42+
"starttime": 0.0,
43+
"expiration": 0.0,
44+
"nodelist": ["compute[0-10]"],
45+
},
46+
}
47+
48+
49+
class TestResourceGraph(unittest.TestCase):
50+
"""Test for the ResourceGraph class."""
51+
52+
def _check_metadata(self, metadata):
53+
if metadata["type"] in ("node", "core", "gpu", "cluster"):
54+
self.assertEqual(metadata["unit"], "")
55+
self.assertEqual(metadata["size"], 1)
56+
self.assertEqual(metadata["properties"], [])
57+
else:
58+
raise ValueError(metadata["type"])
59+
60+
def test_basic(self):
61+
graph = FluxionResourceGraphV1(RV1)
62+
self.assertTrue(graph.is_directed())
63+
j = graph.to_JSON()
64+
json.dumps(j) # make sure it doesn't throw an error
65+
self.assertTrue(j["graph"]["directed"])
66+
self.assertEqual(len(j["graph"]["nodes"]), len(graph.get_nodes()))
67+
self.assertEqual(len(j["graph"]["edges"]), len(graph.get_edges()))
68+
for node in graph.get_nodes():
69+
self._check_metadata(node.get_metadata())
70+
71+
def test_basic_2(self):
72+
graph = FluxionResourceGraphV1(RV1_2)
73+
self.assertTrue(graph.is_directed())
74+
j = graph.to_JSON()
75+
json.dumps(j)
76+
self.assertTrue(j["graph"]["directed"])
77+
self.assertEqual(len(j["graph"]["nodes"]), len(graph.get_nodes()))
78+
self.assertEqual(len(j["graph"]["edges"]), len(graph.get_edges()))
79+
for node in graph.get_nodes():
80+
self._check_metadata(node.get_metadata())
81+
82+
83+
unittest.main(testRunner=TAPTestRunner())

0 commit comments

Comments
 (0)