|
14 | 14 | import time |
15 | 15 | import unittest |
16 | 16 | import warnings |
17 | | -from dataclasses import asdict |
| 17 | +from dataclasses import asdict, dataclass |
18 | 18 | from pathlib import Path |
19 | 19 | from typing import Dict, List, Mapping, Tuple, Union |
20 | 20 | from unittest import mock |
|
43 | 43 | RoleStatus, |
44 | 44 | runopt, |
45 | 45 | runopts, |
| 46 | + StructuredRunOpt, |
46 | 47 | TORCHX_HOME, |
47 | 48 | Workspace, |
48 | 49 | ) |
@@ -550,6 +551,40 @@ def test_getset_metadata(self) -> None: |
550 | 551 | self.assertEqual(None, app.metadata.get("non_existent")) |
551 | 552 |
|
552 | 553 |
|
| 554 | +class StructuredRunOptTest(unittest.TestCase): |
| 555 | + |
| 556 | + @dataclass |
| 557 | + class UlimitTest(StructuredRunOpt): |
| 558 | + name: str |
| 559 | + hard: int |
| 560 | + soft: int |
| 561 | + |
| 562 | + def template(self) -> str: |
| 563 | + return "{name},{soft:d},{hard:d}" |
| 564 | + |
| 565 | + def test_structured_runopt(self) -> None: |
| 566 | + opt = self.UlimitTest(name="test", hard=100, soft=50) |
| 567 | + |
| 568 | + # Test class from_repr |
| 569 | + self.assertEqual( |
| 570 | + opt, |
| 571 | + self.UlimitTest.from_repr( |
| 572 | + "test,50,100", |
| 573 | + ), |
| 574 | + ) |
| 575 | + |
| 576 | + # Test repr |
| 577 | + self.assertEqual( |
| 578 | + "StructuredRunOptTest.UlimitTest(name='test', hard=100, soft=50)", repr(opt) |
| 579 | + ) |
| 580 | + |
| 581 | + # Test equality |
| 582 | + opt_other = self.UlimitTest(name="test", hard=100, soft=50) |
| 583 | + self.assertEqual(opt, opt_other) |
| 584 | + opt_other = self.UlimitTest(name="test", hard=100, soft=70) |
| 585 | + self.assertNotEqual(opt, opt_other) |
| 586 | + |
| 587 | + |
553 | 588 | class RunConfigTest(unittest.TestCase): |
554 | 589 | def get_cfg(self) -> Mapping[str, CfgVal]: |
555 | 590 | return { |
|
0 commit comments