Add tests for auxillary.py
This commit is contained in:
parent
e07acdb4bb
commit
657276eb91
1 changed files with 50 additions and 1 deletions
|
|
@ -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
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue