Skip to content

Commit

Permalink
Scheduler: Add tests for bad configuration entries
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange05 committed Dec 8, 2023
1 parent c90ebec commit dbf9f86
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions loki/bulk/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class TransformationConfig:

_re_dimension = re.compile(r'\%dimensions\.(.*?)\%')

def __init__(self, name, module, classname=None, path=None, options=None):
def __init__(self, name, module, classname=None, path=None, options={}):
self.name = name
self.module = module
self.classname = classname or self.name
Expand Down Expand Up @@ -164,7 +164,7 @@ def instantiate(self):

# Check for and return Transformation class
if not hasattr(mod, self.classname):
raise RuntimeError('Failed to load Transformation class!')
raise RuntimeError(f'Failed to load Transformation class: {self.classname}')

# Attempt to instantiate transformation from config
try:
Expand Down
31 changes: 31 additions & 0 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,37 @@ def test_transformation_config(config):
assert transformation.module_suffix == '_roll'
assert not transformation.replace_ignore_items

# Test for errors when failing to instantiate a transformation
bad_config = config.copy()
bad_config['transformations'] = {
'DependencyTrafo': { # <= typo
'module': 'loki.transform',
'options': {}
}
}
with pytest.raises(RuntimeError):
cfg = SchedulerConfig.from_dict(bad_config)

worse_config = config.copy()
worse_config['transformations'] = {
'DependencyTransform': {
'module': 'loki.transformats', # <= typo
'options': {}
}
}
with pytest.raises(ModuleNotFoundError):
cfg = SchedulerConfig.from_dict(worse_config)

worst_config = config.copy()
worst_config['transformations'] = {
'DependencyTransform': {
'module': 'loki.transform',
'options': {'hello': 'Dave'}
}
}
with pytest.raises(RuntimeError):
cfg = SchedulerConfig.from_dict(worst_config)


def test_transformation_config_external_with_dimension(here, config):
"""
Expand Down

0 comments on commit dbf9f86

Please sign in to comment.