def test_sub_classes(setup_groups, sub_classes, expected): """Test the `sub_classes` constructor argument.""" entity_01, entity_02, entity_03 = setup_groups parameter_type = GroupParamType(sub_classes=sub_classes) results = [] for group in [entity_01, entity_02, entity_03]: try: parameter_type.convert(str(group.pk), None, None) except click.BadParameter: results.append(False) else: results.append(True) assert tuple(results) == expected
def setUpClass(cls): """ Create some groups to test the GroupParamType parameter type for the command line infrastructure We create an initial group with a random name and then on purpose create two groups with a name that matches exactly the ID and UUID, respectively, of the first one. This allows us to test the rules implemented to solve ambiguities that arise when determing the identifier type """ super(TestGroupParamType, cls).setUpClass() cls.param = GroupParamType() cls.entity_01 = Group.create(name='group_01') cls.entity_02 = Group.create(name=str(cls.entity_01.pk)) cls.entity_03 = Group.create(name=str(cls.entity_01.uuid))
def test_create_if_not_exist(setup_groups): """Test the `create_if_not_exist` constructor argument.""" label = 'non-existing-label-01' parameter_type = GroupParamType(create_if_not_exist=True) result = parameter_type.convert(label, None, None) assert isinstance(result, Group) label = 'non-existing-label-02' parameter_type = GroupParamType(create_if_not_exist=True, sub_classes=('aiida.groups:core.auto',)) result = parameter_type.convert(label, None, None) assert isinstance(result, AutoGroup) # Specifying more than one subclass when `create_if_not_exist=True` is not allowed. with pytest.raises(ValueError): GroupParamType(create_if_not_exist=True, sub_classes=('aiida.groups:core.auto', 'aiida.groups:core.import'))
if identifier is not None: return identifier try: return QueryBuilder().append(SsspFamily).first()[0] except exceptions.NotExistent: raise click.BadParameter( 'failed to automatically detect an SSSP family: install it with `aiida-sssp install`.' ) SSSP_FAMILY = OverridableOption( '-F', '--sssp-family', type=GroupParamType(sub_classes=('aiida.groups:sssp.family', )), required=False, callback=default_sssp_family, help='Select an SSSP family.') STRUCTURE = OverridableOption( '-S', '--structure', type=DataParamType(sub_classes=('aiida.data:structure', )), help='Filter for elements of the given structure.') VERSION = OverridableOption( '-v', '--version', type=click.STRING, required=False,
'cp2k', ]), default='cp2k', help="the format of the pseudopotential file") @click.option( '--duplicates', type=click.Choice(['ignore', 'error', 'new']), default='ignore', help= "Whether duplicates should be ignored, produce an error or uploaded as new version" ) @click.option('--ignore-invalid/--no-ignore-invalid', default=False, help="Whether to ignore invalid entries when parsing") @options.GROUP( type=GroupParamType(create_if_not_exist=True, sub_classes=('aiida.groups:gaussian.pseudo', )), help= "A group of type gaussian.pseudo to add created nodes to (will be created if it doesn't exist)." ) # fmt: on @decorators.with_dbenv() def import_pseudo(pseudopotential_file, fformat, sym, tags, duplicates, ignore_invalid, group): """ Add a pseudopotential from a file to the database """ from aiida_gaussian_datatypes.pseudopotential.data import Pseudopotential loaders = { "cp2k": Pseudopotential.from_cp2k,
"This command has been deprecated. Please use 'verdi archive import' instead." ) @click.argument('archives', nargs=-1, type=PathOrUrl(exists=True, readable=True)) @click.option( '-w', '--webpages', type=click.STRING, cls=options.MultipleValueOption, help= 'Discover all URL targets pointing to files with the .aiida extension for these HTTP addresses. ' 'Automatically discovered archive URLs will be downloaded and added to ARCHIVES for importing' ) @options.GROUP( type=GroupParamType(create_if_not_exist=True), help= 'Specify group to which all the import nodes will be added. If such a group does not exist, it will be' ' created automatically.') @click.option( '-e', '--extras-mode-existing', type=click.Choice(EXTRAS_MODE_EXISTING), default='keep_existing', help= 'Specify which extras from the export archive should be imported for nodes that are already contained in the ' 'database: ' 'ask: import all extras and prompt what to do for existing extras. ' 'keep_existing: import all extras and keep original value of existing extras. ' 'update_existing: import all extras and overwrite value of existing extras. ' 'mirror: import all extras and remove any existing extras that are not present in the archive. '
def parameter_type(): """Return an instance of the `GroupParamType`.""" return GroupParamType()