Skip to content

Commit 8cba418

Browse files
Merge pull request #90 from NessieCanCode/document-testing-schemas-and-data
Use test fixtures for schema and slurmdb
2 parents 88ab3f4 + 21b08e0 commit 8cba418

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ python3 src/slurm_schema.py --output schema.json
130130
The resulting `schema.json` file can be compared with the list of
131131
tables and columns from your deployment.
132132

133+
### Testing with sample SlurmDB data
134+
135+
For unit tests and local development the repository includes two fixtures
136+
under `test/`:
137+
138+
- `example_slurm_schema_for_testing.json` – a pre-generated mapping of
139+
tables to columns for a minimal Slurm accounting database.
140+
- `example_slurmdb_for_testing.sql` – a small SQL dump containing the
141+
corresponding table definitions and a few dummy rows.
142+
143+
These files allow tests to verify table and column presence and operate on
144+
sample data without requiring access to a live SlurmDB instance.
145+
133146
## 📝 Development Notes
134147

135148
- Your UI components can access system files or commands using `cockpit.file()` and other Cockpit APIs.

test/unit/slurm_schema_dump.test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class SlurmSchemaDumpTests(unittest.TestCase):
66
def test_job_table_uses_cpus_req(self):
7-
schema = extract_schema_from_dump('test/test_db_dump.sql')
7+
schema = extract_schema_from_dump('test/example_slurmdb_for_testing.sql')
88
cols = schema.get('localcluster_job_table', [])
99
self.assertIn('cpus_req', cols)
1010
self.assertNotIn('cpus_alloc', cols)

test/unit/slurmdb_validation.test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
2+
import json
23
from slurmdb import SlurmDB
3-
from slurm_schema import extract_schema_from_dump, extract_schema
4+
from slurm_schema import extract_schema
45

56
class SlurmDBValidationTests(unittest.TestCase):
67
def test_invalid_cluster_rejected(self):
@@ -150,7 +151,8 @@ def fake_connect():
150151
self.assertIsNone(db._conn)
151152

152153
def test_fetch_usage_records_uses_cpus_req_if_alloc_missing(self):
153-
schema = extract_schema_from_dump('test/test_db_dump.sql')
154+
with open('test/example_slurm_schema_for_testing.json') as fh:
155+
schema = json.load(fh)
154156
job_cols = schema.get('localcluster_job_table', [])
155157

156158
class FakeCursor:

0 commit comments

Comments
 (0)