def test_disable_caching(self): """Test the `disable_caching` context manager with specific identifier.""" with disable_caching(identifier='aiida.calculations:arithmetic.add'): self.assertFalse( get_use_cache(identifier='aiida.calculations:arithmetic.add')) self.assertTrue( get_use_cache(identifier='aiida.calculations:arithmetic.add'))
def test_empty_enabled_disabled(self): # pylint: disable=no-self-use """Test that `aiida.manage.caching.configure` does not except when either `enabled` or `disabled` is `None`. This will happen when the configuration file specifies either one of the keys but no actual values, e.g.:: profile_name: default: False enabled: In this case, the dictionary parsed by yaml will contain `None` for the `enabled` key. Now this will be unlikely, but the same holds when all values are commented:: profile_name: default: False enabled: # - aiida.calculations:templatereplacer which is not unlikely to occurr in the wild. """ configuration = { get_profile().name: { 'default': True, 'enabled': None, 'disabled': None } } with tempfile.NamedTemporaryFile() as handle: yaml.dump(configuration, handle, encoding='utf-8') configure(config_file=handle.name) # Check that `get_use_cache` also does not except get_use_cache(identifier='aiida.calculations:templatereplacer')
def test_configuration(configure_caching, config_dict, enabled, disabled): """Check that different caching configurations give the expected result. """ with configure_caching(config_dict=config_dict): for identifier in enabled: assert get_use_cache(identifier=identifier) for identifier in disabled: assert not get_use_cache(identifier=identifier)
def test_contextmanager_disable_global(self): """Test the `disable_caching` context manager without specific identifier.""" with disable_caching(): self.assertTrue( get_use_cache(identifier='aiida.calculations:arithmetic.add') ) # explicitly set, hence not overwritten self.assertFalse( get_use_cache( identifier='aiida.calculations:templatereplacer'))
def test_disable_caching_global(configure_caching): """ Check that using disable_caching for a specific identifier works. """ specific_identifier = 'some_ident' with configure_caching(config_dict={'default': True, 'enabled': [specific_identifier]}): with disable_caching(): assert not get_use_cache(identifier='some_other_ident') assert not get_use_cache(identifier=specific_identifier)
def test_ambiguous_configuration(configure_caching, config_dict, valid_identifiers, invalid_identifiers): """ Check that calling 'get_use_cache' on identifiers for which the configuration is ambiguous raises a ConfigurationError. """ with configure_caching(config_dict=config_dict): for identifier in valid_identifiers: get_use_cache(identifier=identifier) for identifier in invalid_identifiers: with pytest.raises(exceptions.ConfigurationError): get_use_cache(identifier=identifier)
def test_empty_enabled_disabled(configure_caching): """Test that `aiida.manage.caching.configure` does not except when either `enabled` or `disabled` is `None`. This will happen when the configuration file specifies either one of the keys but no actual values, e.g.:: profile_name: default: False enabled: In this case, the dictionary parsed by yaml will contain `None` for the `enabled` key. Now this will be unlikely, but the same holds when all values are commented:: profile_name: default: False enabled: # - aiida.calculations:templatereplacer which is not unlikely to occurr in the wild. """ with configure_caching(config_dict={ 'default': True, 'enabled': None, 'disabled': None }): # Check that `get_use_cache` also does not except, and works as expected assert get_use_cache(identifier='aiida.calculations:templatereplacer')
def test_enable_caching_specific(configure_caching): """ Check that using enable_caching for a specific identifier works. """ identifier = 'some_ident' with configure_caching({'default_enabled': False}): with enable_caching(identifier=identifier): assert get_use_cache(identifier=identifier)
def test_disable_caching_specific(configure_caching): """ Check that using disable_caching for a specific identifier works. """ identifier = 'some_ident' with configure_caching({'default': True}): with disable_caching(identifier=identifier): assert not get_use_cache(identifier=identifier)
def test_no_enabled_disabled(configure_caching): """Test that `aiida.manage.caching.configure` does not except when either `enabled` or `disabled` do not exist. This will happen when the configuration file does not specify these values:: profile_name: default: False """ with configure_caching(config_dict={'default': False}): # Check that `get_use_cache` also does not except, and works as expected assert not get_use_cache(identifier='aiida.calculations:templatereplacer')
def verdi_config_caching(disabled): """List caching-enabled process types for the current profile.""" from aiida.plugins.entry_point import ENTRY_POINT_STRING_SEPARATOR, get_entry_point_names from aiida.manage.caching import get_use_cache for group in ['aiida.calculations', 'aiida.workflows']: for entry_point in get_entry_point_names(group): identifier = ENTRY_POINT_STRING_SEPARATOR.join([group, entry_point]) if get_use_cache(identifier=identifier): if not disabled: echo.echo(identifier) elif disabled: echo.echo(identifier)
def test_invalid_identifier(configure_caching): """Test `get_use_cache` raises a `TypeError` if identifier is not a string.""" with configure_caching({}): with pytest.raises(TypeError): get_use_cache(identifier=int)
def test_contextmanager_enable_explicit(self): """Test the `enable_caching` context manager.""" with enable_caching(identifier='aiida.calculations:templatereplacer'): self.assertTrue( get_use_cache( identifier='aiida.calculations:templatereplacer'))
def test_caching_enabled(self): """Test `get_use_cache` when specifying identifier.""" self.assertFalse( get_use_cache(identifier='aiida.calculations:templatereplacer'))
def test_default(self): """Verify that when not specifying any specific identifier, the `default` is used, which is set to `True`.""" self.assertTrue(get_use_cache())
def test_invalid_config(self): """Test `get_use_cache` raises a `TypeError` if identifier is not a valid entry point string.""" with self.assertRaises(TypeError): get_use_cache(identifier=int)
def test_default(configure_caching): """Verify that when not specifying any specific identifier, the `default` is used, which is set to `True`.""" with configure_caching({'default_enabled': True}): assert get_use_cache()
def test_default(use_default_configuration): # pylint: disable=unused-argument """Verify that when not specifying any specific identifier, the `default` is used, which is set to `True`.""" assert get_use_cache()
def test_invalid_identifier(use_default_configuration): # pylint: disable=unused-argument """Test `get_use_cache` raises a `TypeError` if identifier is not a string.""" with pytest.raises(TypeError): get_use_cache(identifier=int)