From 172decef851b5a766783dede48df58384e588cee Mon Sep 17 00:00:00 2001 From: Jo Basevi Date: Thu, 3 Aug 2023 14:48:00 +1000 Subject: [PATCH] add tests for modules option in config.yaml --- test/resources/config_legacy_modules.yaml | 3 +++ test/resources/config_modules.yaml | 7 ++++++ test/{ => resources}/config_mom5.yaml | 0 test/test_payu.py | 27 ++++++++++++++++------- 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 test/resources/config_legacy_modules.yaml create mode 100644 test/resources/config_modules.yaml rename test/{ => resources}/config_mom5.yaml (100%) diff --git a/test/resources/config_legacy_modules.yaml b/test/resources/config_legacy_modules.yaml new file mode 100644 index 00000000..6c99166d --- /dev/null +++ b/test/resources/config_legacy_modules.yaml @@ -0,0 +1,3 @@ +modules: + - module_1 + - module_2 \ No newline at end of file diff --git a/test/resources/config_modules.yaml b/test/resources/config_modules.yaml new file mode 100644 index 00000000..fb6af056 --- /dev/null +++ b/test/resources/config_modules.yaml @@ -0,0 +1,7 @@ +modules: + use: + - path/to/module/dir/1 + - path/to/module/dir/2 + load: + - module_1 + - module_2 \ No newline at end of file diff --git a/test/config_mom5.yaml b/test/resources/config_mom5.yaml similarity index 100% rename from test/config_mom5.yaml rename to test/resources/config_mom5.yaml diff --git a/test/test_payu.py b/test/test_payu.py index 01800194..d9ed5c26 100644 --- a/test/test_payu.py +++ b/test/test_payu.py @@ -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 @@ -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():