Skip to content

Commit

Permalink
add tests for modules option in config.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Jo Basevi committed Aug 3, 2023
1 parent b9d9454 commit 172dece
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
3 changes: 3 additions & 0 deletions test/resources/config_legacy_modules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
modules:
- module_1
- module_2
7 changes: 7 additions & 0 deletions test/resources/config_modules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
modules:
use:
- path/to/module/dir/1
- path/to/module/dir/2
load:
- module_1
- module_2
File renamed without changes.
27 changes: 19 additions & 8 deletions test/test_payu.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_movetree():


def test_read_config():
config_path = os.path.join('test', 'config_mom5.yaml')
config_path = os.path.join('test', 'resources', 'config_mom5.yaml')
config = payu.fsops.read_config(config_path)

# Test control_path is not set in read_config
Expand All @@ -151,17 +151,28 @@ def test_read_config():
assert(config.pop('modules') == {})
assert(config == {})

# Test transform legacy modules option
with open(config_tmp, 'w') as f:
f.write('modules:\n - test_user_defined_module')
os.remove(config_tmp)

def test_read_config_modules_legacy_option():
# Test transform legacy modules option
config_path = os.path.join('test', 'resources', 'config_legacy_modules.yaml')

config = payu.fsops.read_config(config_tmp)
config = payu.fsops.read_config(config_path)
modules_config = config.get('modules', {})
assert(modules_config.get('load', []) == ['test_user_defined_module'])

assert(modules_config.get('load', []) == ['module_1', 'module_2'])
assert(modules_config.get('use', []) == [])

os.remove(config_tmp)

def test_read_config_modules_option():
# Test modules with load/use options is unchanged
config_path = os.path.join('test', 'resources', 'config_modules.yaml')

config = payu.fsops.read_config(config_path)
modules_config = config.get('modules', {})

assert(modules_config.get('load', []) == ['module_1', 'module_2'])
assert(modules_config.get('use', []) == ['path/to/module/dir/1', 'path/to/module/dir/2'])


def test_make_symlink():
Expand Down

0 comments on commit 172dece

Please sign in to comment.