Esempio n. 1
0
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')
Esempio n. 2
0
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
Esempio n. 3
0
class CloneConfig(MainConfig):
    """Configuration for cloning."""

    resume: Option[bool] = Option('Resuming cloning from a previous run.',
                                  default=True)
Esempio n. 4
0
class ExtractRoleMetadataConfig(MainConfig):
    """Configuration for role metadata extraction."""

    count: Option[int] = Option('Top number of roles to keep', required=False)
Esempio n. 5
0
                         [(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',
Esempio n. 6
0
class SubConfigTest(ConfigTest):
    """Test subconfiguration."""
    test_new_option: Option[str] = Option(HELP_TEXT_SUB, default='test')
Esempio n. 7
0
def test_get_attr_name_nonexistent() -> None:
    c = ConfigTest()
    o: Option[bool] = Option('test option')

    with pytest.raises(TypeError):
        o._get_attr_name(c)
Esempio n. 8
0
 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)
Esempio n. 10
0
 def partial_option(**kwargs: Any) -> Option[str]:
     return Option('bla', default='test', **kwargs)
Esempio n. 11
0
 class Correct(Config):
     conv: Option[Path] = Option('bla', click_type=str, converter=Path)
Esempio n. 12
0
 class WrongAgain(Config):
     conv: Option[Path] = Option('bla', click_type=str)
Esempio n. 13
0
 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)
Esempio n. 15
0
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)
Esempio n. 16
0
 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')