Skip to content

Commit

Permalink
Test gen
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Feb 18, 2025
1 parent e4f0e49 commit a7a0c19
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tyro/extras/_base_configs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Mapping, Optional, Sequence, Tuple, TypeVar, Union

from typing_extensions import Annotated

from tyro.conf._markers import Suppress

from .._typing import TypeForm
Expand Down
1 change: 1 addition & 0 deletions src/tyro/extras/_subcommand_cli_from_dict.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Callable, Dict, Optional, Sequence, TypeVar, Union, overload

from typing_extensions import Annotated

from tyro.conf._markers import Marker, Suppress

from .._cli import cli
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, Callable, Literal, Tuple

from helptext_utils import get_helptext_with_checks
from torch import nn

import tyro
Expand Down Expand Up @@ -89,6 +90,7 @@ class ExperimentConfig:
),
},
prefix_names=False, # Omit prefixes in subcommands themselves.
sort_subcommands=True, # Sort subcommands alphabetically.
)


Expand Down Expand Up @@ -120,6 +122,10 @@ class BaseConfig:
data_config: AnnotatedDataParserUnion = DataConfig(test=0)


def test_sorted_alphabetically() -> None:
assert "{big,small}" in get_helptext_with_checks(ExperimentConfigDataParserUnion)


def test_base_configs_nested() -> None:
def main(cfg: BaseConfig) -> BaseConfig:
return cfg
Expand Down Expand Up @@ -230,3 +236,17 @@ def test_overridable_config_helper():
},
args=["small-data", "--test", "100"],
) == DataConfig(100)


def test_overridable_config_helper_single():
assert tyro.extras.overridable_config_cli(
{
"small-data": (
"Small data",
DataConfig(
test=2221,
),
),
},
args=["small-data", "--test", "100"],
) == DataConfig(100)

0 comments on commit a7a0c19

Please sign in to comment.