88from qtpy .QtWidgets import QApplication
99from shiver .shiver import Shiver
1010from shiver .configuration import Configuration , get_data
11+ from shiver .version import __version__ as current_version
1112
1213
1314def test_config_path_default ():
@@ -47,29 +48,29 @@ def test_config_path_does_not_exist(monkeypatch, tmp_path):
4748
4849
4950@pytest .mark .parametrize (
50- "user_conf_file " ,
51+ "user_conf_file_with_version " ,
5152 [
5253 """
5354 [generate_tab.oncat]
5455 #url to oncat portal
5556 oncat_url = https://oncat.ornl.gov
5657 #client id for on cat; it is unique for Shiver
57- client_id = 99025bb3-ce06-4f4b-bcf2-36ebf925cd1d
58+ client_id = 46c478f0-a472-4551-9264-a937626d5fc2
5859
5960 """
6061 ],
6162 indirect = True ,
6263)
63- def test_field_validate_fields_exist (monkeypatch , user_conf_file ):
64+ def test_field_validate_fields_exist (monkeypatch , user_conf_file_with_version ):
6465 """Test configuration validate all fields exist with the same values as templates
6566 Note: update the parameters if the fields increase"""
6667 # read the custom configuration file
67- monkeypatch .setattr ("shiver.configuration.CONFIG_PATH_FILE" , user_conf_file )
68+ monkeypatch .setattr ("shiver.configuration.CONFIG_PATH_FILE" , user_conf_file_with_version )
6869 user_config = Configuration ()
6970
70- assert user_config .config_file_path .endswith (user_conf_file ) is True
71+ assert user_config .config_file_path .endswith (user_conf_file_with_version ) is True
7172 # check if the file exists
72- assert os .path .exists (user_conf_file )
73+ assert os .path .exists (user_conf_file_with_version )
7374
7475 # check all fields are the same as the configuration template file
7576 project_directory = Path (__file__ ).resolve ().parent .parent .parent
@@ -79,11 +80,14 @@ def test_field_validate_fields_exist(monkeypatch, user_conf_file):
7980 # comments should be copied too
8081 for section in user_config .config .sections ():
8182 for field in user_config .config [section ]:
82- assert user_config .config [section ][field ] == template_config [section ][field ]
83+ if field != "version" :
84+ assert user_config .config [section ][field ] == template_config [section ][field ]
85+ else :
86+ assert user_config .config [section ][field ] == current_version
8387
8488
8589@pytest .mark .parametrize (
86- "user_conf_file " ,
90+ "user_conf_file_with_version " ,
8791 [
8892 """
8993 [generate_tab.oncat]
@@ -94,36 +98,40 @@ def test_field_validate_fields_exist(monkeypatch, user_conf_file):
9498 ],
9599 indirect = True ,
96100)
97- def test_field_validate_fields_same (monkeypatch , user_conf_file ):
98- """Test configuration validate all fields exist with their values; different from the template"""
101+ def test_field_validate_fields_same (monkeypatch , user_conf_file_with_version ):
102+ """Test configuration validate all fields exist with their values; different from the template,
103+ provided the version is the same"""
99104
100105 # read the custom configuration file
101- monkeypatch .setattr ("shiver.configuration.CONFIG_PATH_FILE" , user_conf_file )
106+ monkeypatch .setattr ("shiver.configuration.CONFIG_PATH_FILE" , user_conf_file_with_version )
102107 user_config = Configuration ()
103108
104109 # check if the file exists
105- assert os .path .exists (user_conf_file )
106- assert user_config .config_file_path == user_conf_file
110+ assert os .path .exists (user_conf_file_with_version )
111+ assert user_config .config_file_path == user_conf_file_with_version
107112
108113 # check all field values have the same values as the user configuration file
109114 assert get_data ("generate_tab.oncat" , "oncat_url" ) == "test_url"
110115 assert get_data ("generate_tab.oncat" , "client_id" ) == "0000-0000"
111116 # cast to bool
112117 assert get_data ("generate_tab.oncat" , "use_notes" ) is True
118+ assert get_data ("software.info" , "version" ) == current_version
113119
114120
115121@pytest .mark .parametrize (
116122 "user_conf_file" ,
117123 [
118124 """
119125 [generate_tab.oncat]
126+ oncat_url = test_url
120127 client_id = 0000-0000
128+ use_notes = True
121129 """
122130 ],
123131 indirect = True ,
124132)
125- def test_field_validate_fields_missing (monkeypatch , user_conf_file ):
126- """Test configuration validate missing fields added from the template """
133+ def test_field_validate_fields_update_different_version (monkeypatch , user_conf_file ):
134+ """Test configuration update all fields, provided the version is not the same """
127135
128136 # read the custom configuration file
129137 monkeypatch .setattr ("shiver.configuration.CONFIG_PATH_FILE" , user_conf_file )
@@ -133,6 +141,34 @@ def test_field_validate_fields_missing(monkeypatch, user_conf_file):
133141 assert os .path .exists (user_conf_file )
134142 assert user_config .config_file_path == user_conf_file
135143
144+ # check all field values have the same values as the user configuration file
145+ assert get_data ("generate_tab.oncat" , "oncat_url" ) != "test_url"
146+ assert get_data ("generate_tab.oncat" , "client_id" ) != "0000-0000"
147+ # version is included with the current version
148+ assert get_data ("software.info" , "version" ) == current_version
149+
150+
151+ @pytest .mark .parametrize (
152+ "user_conf_file_with_version" ,
153+ [
154+ """
155+ [generate_tab.oncat]
156+ client_id = 0000-0000
157+ """
158+ ],
159+ indirect = True ,
160+ )
161+ def test_field_validate_fields_missing (monkeypatch , user_conf_file_with_version ):
162+ """Test configuration validate missing fields added from the template"""
163+
164+ # read the custom configuration file
165+ monkeypatch .setattr ("shiver.configuration.CONFIG_PATH_FILE" , user_conf_file_with_version )
166+ user_config = Configuration ()
167+
168+ # check if the file exists
169+ assert os .path .exists (user_conf_file_with_version )
170+ assert user_config .config_file_path == user_conf_file_with_version
171+
136172 # check all field values have the same values as the user configuration file
137173 assert get_data ("generate_tab.oncat" , "oncat_url" ) == "https://oncat.ornl.gov"
138174 assert get_data ("generate_tab.oncat" , "client_id" ) == "0000-0000"
@@ -151,7 +187,7 @@ def test_get_data_valid(monkeypatch, user_conf_file):
151187 assert len (get_data ("generate_tab.oncat" , "" )) == 3
152188 # fields
153189 assert get_data ("generate_tab.oncat" , "oncat_url" ) == "https://oncat.ornl.gov"
154- assert get_data ("generate_tab.oncat" , "client_id" ) == "99025bb3-ce06-4f4b-bcf2-36ebf925cd1d "
190+ assert get_data ("generate_tab.oncat" , "client_id" ) == "46c478f0-a472-4551-9264-a937626d5fc2 "
155191 assert get_data ("generate_tab.oncat" , "use_notes" ) is False
156192
157193 assert config .is_valid ()
0 commit comments