|
1 | 1 | import dataclasses
|
2 | 2 |
|
| 3 | +import pytest |
3 | 4 | from helptext_utils import get_helptext_with_checks
|
4 | 5 |
|
5 | 6 | import tyro
|
@@ -83,3 +84,52 @@ class A:
|
83 | 84 | assert "(default: True)" in get_helptext_with_checks(A)
|
84 | 85 | assert "(default: False)" not in get_helptext_with_checks(A)
|
85 | 86 | assert "(default: None)" not in get_helptext_with_checks(A)
|
| 87 | + |
| 88 | + |
| 89 | +def test_flag_no_pairs() -> None: |
| 90 | + """Test for tyro.conf.FlagPairOff.""" |
| 91 | + |
| 92 | + @dataclasses.dataclass |
| 93 | + class A: |
| 94 | + x: tyro.conf.FlagCreatePairsOff[bool] |
| 95 | + y: tyro.conf.FlagCreatePairsOff[bool] = False |
| 96 | + z: tyro.conf.FlagCreatePairsOff[bool] = True |
| 97 | + |
| 98 | + assert tyro.cli( |
| 99 | + A, |
| 100 | + args=["--x", "True"], |
| 101 | + ) == A(True) |
| 102 | + assert tyro.cli( |
| 103 | + A, |
| 104 | + args=["--x", "True", "--y"], |
| 105 | + ) == A(True, True) |
| 106 | + assert tyro.cli( |
| 107 | + A, |
| 108 | + args=["--x", "True", "--y", "--no-z"], |
| 109 | + ) == A(True, True, False) |
| 110 | + |
| 111 | + with pytest.raises(SystemExit): |
| 112 | + tyro.cli( |
| 113 | + A, |
| 114 | + args=["--x", "True", "--y", "True"], |
| 115 | + ) |
| 116 | + with pytest.raises(SystemExit): |
| 117 | + tyro.cli( |
| 118 | + A, |
| 119 | + args=["--x", "True", "--no-y"], |
| 120 | + ) |
| 121 | + with pytest.raises(SystemExit): |
| 122 | + tyro.cli( |
| 123 | + A, |
| 124 | + args=["--x", "True", "--z"], |
| 125 | + ) |
| 126 | + with pytest.raises(SystemExit): |
| 127 | + tyro.cli( |
| 128 | + A, |
| 129 | + args=["--x"], |
| 130 | + ) |
| 131 | + with pytest.raises(SystemExit): |
| 132 | + tyro.cli( |
| 133 | + A, |
| 134 | + args=["--no-x"], |
| 135 | + ) |
0 commit comments