class ConfigTest(Config): """Test configuration.""" test_option: Option[bool] = Option(HELP_TEXT_BOOL, default=False, final=True) test_list_option: Option[List[int]] = Option(HELP_TEXT_LIST, default_factory=list) test_no_default: Option[int] = Option('For a test')
class MainConfig(Config): """Global configurations for all commands.""" report: Option[bool] = Option( 'Output a report after a task has completed.', default=False) progress: Option[bool] = Option('Print the progress of a task.', default=False) dataset: Option[str] = Option('The name of the dataset to create/use', final=True) output: Option[Path] = Option('Output directory', click_type=click.Path(file_okay=False, dir_okay=True, writable=True, resolve_path=True), converter=lambda p: Path(str(p)), default=Path('data'), final=True) force: Option[bool] = Option('Force regeneration of cached results', default=False) @property def output_directory(self) -> Path: """Get the output directory.""" return self.output / self.dataset
class CloneConfig(MainConfig): """Configuration for cloning.""" resume: Option[bool] = Option('Resuming cloning from a previous run.', default=True)
class ExtractRoleMetadataConfig(MainConfig): """Configuration for role metadata extraction.""" count: Option[int] = Option('Top number of roles to keep', required=False)
[(config_main, MainConfig), (config_disc, DiscoverConfig)]) def test_get_config_type(config_fun: Callable[[MainConfig], None], config_type: Type[MainConfig]) -> None: assert cli._get_configuration_type(config_fun) is config_type @pytest.mark.parametrize('config_fun', [config_no_anno, config_no_param, config_wrong_type]) def test_get_config_type_error( config_fun: Callable[[MainConfig], None]) -> None: with pytest.raises(TypeError): print(cli._get_configuration_type(config_fun)) opt1_: Option[bool] = Option('help value') opt2_: Option[str] = Option('help value 2') class MyConfig(MainConfig): opt1: Option[bool] = opt1_ opt2: Option[str] = opt2_ def test_get_config_options_main() -> None: opts = cli._get_configuration_options(MainConfig) assert (sorted( ['progress', 'report', 'cache', 'dataset', 'output', 'force']) == sorted(opts.keys())) assert (sorted( ['progress', 'report', 'cache', 'dataset', 'output',
class SubConfigTest(ConfigTest): """Test subconfiguration.""" test_new_option: Option[str] = Option(HELP_TEXT_SUB, default='test')
def test_get_attr_name_nonexistent() -> None: c = ConfigTest() o: Option[bool] = Option('test option') with pytest.raises(TypeError): o._get_attr_name(c)
class WrongAgainAgain(Config): conv: Option[Path] = Option('bla', default=Path('test'), default_factory=Path)
class ExtractVersionConfig(MainConfig): """Configuration for version extraction.""" always_use_commit_date: Option[bool] = Option( 'Always use the commit date rather than the tagged date', default=True)
def partial_option(**kwargs: Any) -> Option[str]: return Option('bla', default='test', **kwargs)
class Correct(Config): conv: Option[Path] = Option('bla', click_type=str, converter=Path)
class WrongAgain(Config): conv: Option[Path] = Option('bla', click_type=str)
class Wrong(Config): conv: Option[str] = Option('bla', converter=str)
class DiffConfig(MainConfig): """Configuration for structural diffing.""" dump_changes: Option[bool] = Option( 'Dump the extracted changes to the reports directory.', default=False)
class ExtractStructuralModelsConfig(MainConfig): """Configuration for structural model extraction.""" commits: Option[bool] = Option( 'Extract a structural model for each commit. If disabled, extracts for semantic versions only.', default=False)
def partial_option(**kwargs: Any) -> Option[str]: return Option('bla', default_factory=str, **kwargs)
class DiscoverConfig(MainConfig): """Configuration for discovery.""" count: Option[int] = Option('Number of roles to discover')