Skip to content
Snippets Groups Projects

Detect cycle automatically in update_config script

Merged Philipp Schmidt requested to merge feat/update-config-auto-cycle into master
Files
2
@@ -9,6 +9,7 @@ import yaml
@@ -9,6 +9,7 @@ import yaml
import zmq
import zmq
from webservice.update_config import (
from webservice.update_config import (
 
_find_cycle,
_add_available_configs_to_arg_parser,
_add_available_configs_to_arg_parser,
_create_new_config_from_args_input,
_create_new_config_from_args_input,
main,
main,
@@ -40,7 +41,7 @@ def test_main_sys_exit(capsys):
@@ -40,7 +41,7 @@ def test_main_sys_exit(capsys):
with pytest.raises(SystemExit):
with pytest.raises(SystemExit):
main()
main()
out, _ = capsys.readouterr()
out, _ = capsys.readouterr()
assert out == "Need to define all fields\n"
assert out == "Need to define all required fields\n"
EXPECTED_ZMQ_REQ = [
EXPECTED_ZMQ_REQ = [
@@ -85,6 +86,7 @@ def test_main(capsys):
@@ -85,6 +86,7 @@ def test_main(capsys):
EXPECTED_CONF = [
EXPECTED_CONF = [
{
{
 
'common-mode': {'type': bool},
'force-hg-if-below': {'type': int},
'force-hg-if-below': {'type': int},
'rel-gain': {'type': bool},
'rel-gain': {'type': bool},
'xray-gain': {'type': bool},
'xray-gain': {'type': bool},
@@ -99,6 +101,7 @@ EXPECTED_CONF = [
@@ -99,6 +101,7 @@ EXPECTED_CONF = [
'use-litframe-finder': {'type': str},
'use-litframe-finder': {'type': str},
'litframe-device-id': {'type': str},
'litframe-device-id': {'type': str},
'energy-threshold': {'type': int},
'energy-threshold': {'type': int},
 
'no-common-mode': {'type': bool},
'no-rel-gain': {'type': bool},
'no-rel-gain': {'type': bool},
'no-xray-gain': {'type': bool},
'no-xray-gain': {'type': bool},
'no-blc-noise': {'type': bool},
'no-blc-noise': {'type': bool},
@@ -174,3 +177,19 @@ def test_create_new_config_from_args_input(instrument, args, expected):
@@ -174,3 +177,19 @@ def test_create_new_config_from_args_input(instrument, args, expected):
available_conf=EXPECTED_CONF,
available_conf=EXPECTED_CONF,
)
)
assert new_conf == expected
assert new_conf == expected
 
 
 
def test_find_cycle(tmp_path):
 
proposal_path = tmp_path / 'CALLAB' / '202301' / 'p002003'
 
proposal_path.mkdir(parents=True, exist_ok=True)
 
 
assert _find_cycle('2003', tmp_path) == '202301'
 
assert _find_cycle('002003', tmp_path) == '202301'
 
 
with pytest.raises(ValueError):
 
# Not existing proposal.
 
_find_cycle('2004', tmp_path)
 
 
with pytest.raises(ValueError):
 
# Not a number.
 
_find_cycle('p2004', tmp_path)
Loading