From 657276eb9177669dc4e4bda468759ea64c93ee20 Mon Sep 17 00:00:00 2001 From: rasmusvt Date: Wed, 6 Apr 2022 15:57:30 +0200 Subject: [PATCH] Add tests for auxillary.py --- beamtime/test/test_auxillary.py | 51 ++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/beamtime/test/test_auxillary.py b/beamtime/test/test_auxillary.py index 5a9e85e..668b792 100644 --- a/beamtime/test/test_auxillary.py +++ b/beamtime/test/test_auxillary.py @@ -1,4 +1,5 @@ import beamtime.auxillary as aux +import os def test_swap_values(): @@ -26,4 +27,52 @@ def test_floor() -> None: assert aux.floor(2.02, 1) == 2.0 assert aux.floor(2.02, 0.01) == 2.02 - assert aux.floor(2.013, 0.01) == 2.01 \ No newline at end of file + assert aux.floor(2.013, 0.01) == 2.01 + + + +def test_options() -> None: + + + options = {} + required_options = ['test1', 'test2', 'test3', 'test4'] + default_options = { + 'test1': 1, + 'test2': 2, + 'test3': 3, + 'test4': 4, + 'test5': 5, + } + + + options = aux.update_options(options=options, required_options=required_options, default_options=default_options) + + assert options['test1'] == default_options['test1'] + assert len(options.items()) == len(required_options) + assert 'test5' not in options.keys() + + +def test_save_options() -> None: + + options = {'test1': 1, 'test2': 2} + path = 'tmp.dat' + + aux.save_options(options, path) + + assert os.path.isfile(path) + + os.remove(path) + + +def test_load_options() -> None: + + options = {'test1': 1, 'test2': 2} + path = 'tmp.dat' + + aux.save_options(options, path) + + loaded_options = aux.load_options(path) + + assert (loaded_options['test1'] == 1) and (loaded_options['test2'] == 2) + + os.remove(path) \ No newline at end of file