6
6
import tempfile
7
7
from unittest .mock import patch
8
8
import unittest
9
+
9
10
import warnings
10
11
warnings .filterwarnings ("always" , category = ResourceWarning )
11
12
warnings .filterwarnings ("ignore" , category = ResourceWarning )
54
55
55
56
56
57
def init_froster (self ):
58
+ '''Initialize the froster objects.'''
59
+
57
60
self .cmd = Commands ()
58
61
self .parser = self .cmd .parse_arguments ()
59
62
self .args = self .parser .parse_args ()
@@ -83,6 +86,7 @@ def init_froster(self):
83
86
84
87
85
88
def deinit_froster (self ):
89
+ '''Deinitialize the froster objects.'''
86
90
87
91
if hasattr (self , 'cfg' ):
88
92
if hasattr (self .cfg , 'aws_dir' ) and os .path .exists (self .cfg .aws_dir ):
@@ -114,6 +118,7 @@ def deinit_froster(self):
114
118
115
119
116
120
def delete_buckets (self ):
121
+ '''Delete created S3 buckets if they exists.'''
117
122
118
123
if self .aws .check_credentials ():
119
124
# Get the buckets list
@@ -127,6 +132,8 @@ def delete_buckets(self):
127
132
128
133
129
134
def check_ini_file (self , ini_file , section , key , value ):
135
+ '''Check the value of a key in a section of an ini file.'''
136
+
130
137
config = configparser .ConfigParser ()
131
138
config .read (ini_file )
132
139
self .assertIn (section , config .sections ())
@@ -135,16 +142,20 @@ def check_ini_file(self, ini_file, section, key, value):
135
142
136
143
@patch ('builtins.print' )
137
144
class TestConfig (unittest .TestCase ):
145
+ '''Test the subcmd_confing method.'''
138
146
139
147
# Method executed only once before all tests
140
148
@classmethod
141
149
def setUpClass (cls ):
150
+
151
+ # Check if the AWS credentials are set
142
152
if AWS_ACCESS_KEY_ID is None or AWS_SECRET is None :
143
153
raise ValueError ("AWS credentials are not set" )
144
154
145
155
# Method executed before every test
146
156
def setUp (self ):
147
157
158
+ # Initialize the froster objects
148
159
init_froster (self )
149
160
150
161
# Delete any existing buckets
@@ -156,12 +167,13 @@ def tearDown(self):
156
167
# Delete any existing buckets
157
168
delete_buckets (self )
158
169
170
+ # Deinitialize the froster objects
159
171
deinit_froster (self )
160
172
161
173
# HELPER RUNS
162
174
163
175
def helper_set_default_cli_arguments (self ):
164
- '''- Set default arguments.'''
176
+ '''- Set default cli arguments.'''
165
177
166
178
self .cmd .args = Namespace (cores = 4 , debug = False , info = False , memory = 64 , noslurm = False , aws_profile = '' , version = False ,
167
179
subcmd = 'config' , aws = False , monitor = False , nih = False , print = False , s3 = False , shared = False , slurm = False , user = False )
@@ -190,7 +202,7 @@ def helper_run_subcmd_config(self, mock_print, mock_text, mock_prompt, mock_list
190
202
@patch ('inquirer.list_input' , side_effect = ['+ Create new profile' , AWS_REGION , '+ Create new bucket' , S3_STORAGE_CLASS ])
191
203
@patch ('inquirer.confirm' , side_effect = [True , False ])
192
204
def helper_run_subcmd_config_shared (self , mock_print , mock_text , mock_prompt , mock_list , mock_confirm ):
193
- '''- Helper that sets full configuration'''
205
+ '''- Helper that sets full configuration with shared directory '''
194
206
195
207
# Check that nothing is set yet
196
208
self .assertFalse (self .cfg .user_init )
@@ -209,7 +221,7 @@ def helper_run_subcmd_config_shared(self, mock_print, mock_text, mock_prompt, mo
209
221
@patch ('inquirer.list_input' , side_effect = ['+ Create new profile' , AWS_REGION , '+ Create new bucket' , S3_STORAGE_CLASS , AWS_PROFILE , AWS_REGION ])
210
222
@patch ('inquirer.confirm' , side_effect = [True , False , True , True ])
211
223
def helper_run_subcmd_config_shared_existing_config (self , mock_print , mock_text , mock_prompt , mock_list , mock_confirm ):
212
- '''- Helper that sets full configuration'''
224
+ '''- Helper that sets full configuration with a shared directory where there is already a shared configuration file '''
213
225
214
226
# Check that nothing is set yet
215
227
self .assertFalse (self .cfg .user_init )
@@ -231,7 +243,7 @@ def helper_run_subcmd_config_shared_existing_config(self, mock_print, mock_text,
231
243
@patch ('inquirer.list_input' , side_effect = ['+ Create new profile' , AWS_REGION_2 , '+ Create new bucket' , S3_STORAGE_CLASS_2 ])
232
244
@patch ('inquirer.confirm' , side_effect = [True , False , False ])
233
245
def helper_run_subcmd_config_overwrite (self , mock_print , mock_text , mock_prompt , mock_list , mock_confirm ):
234
- '''- Helper that sets full configuration'''
246
+ '''- Helper that sets full configuration and overwrites the current configuration '''
235
247
236
248
# Mock the CLI default arguments
237
249
self .helper_set_default_cli_arguments ()
@@ -244,7 +256,7 @@ def helper_run_subcmd_config_overwrite(self, mock_print, mock_text, mock_prompt,
244
256
@patch ('inquirer.list_input' , side_effect = ['+ Create new profile' , AWS_REGION , '+ Create new bucket' , S3_STORAGE_CLASS ])
245
257
@patch ('inquirer.confirm' , side_effect = [True , True , False ])
246
258
def helper_run_subcmd_config_shared_move_froster_archives_json (self , mock_print , mock_text , mock_prompt , mock_list , mock_confirm ):
247
- '''- Helper that sets full configuration'''
259
+ '''- Helper that sets full configuration with a shared directory and moves the froster-archives.json file '''
248
260
249
261
# Check that nothing is set yet
250
262
self .assertFalse (self .cfg .user_init )
@@ -294,7 +306,6 @@ def helper_run_subcmd_config_shared_move_config_sections(self, mock_print, mock_
294
306
# HELPER CHECKS
295
307
296
308
def helper_check_subcmd_config (self ):
297
- '''- Check the configuration files after setting full configuration'''
298
309
299
310
# Check that everything is set
300
311
self .assertTrue (self .cfg .user_init )
@@ -352,7 +363,7 @@ def helper_check_subcmd_config(self):
352
363
self .assertIn (S3_BUCKET_NAME , s3_buckets )
353
364
354
365
def helper_check_subcmd_config_shared (self ):
355
- '''- Check the configuration files after setting full configuration with shared directory'''
366
+
356
367
# Check that everything is set
357
368
self .assertTrue (self .cfg .user_init )
358
369
self .assertTrue (self .cfg .aws_init )
@@ -413,7 +424,7 @@ def helper_check_subcmd_config_shared(self):
413
424
self .assertIn (S3_BUCKET_NAME , s3_buckets )
414
425
415
426
def helper_check_subcmd_config_shared_existing_config (self ):
416
- '''- Check the configuration files after setting full configuration with shared directory'''
427
+
417
428
# Check that everything is set
418
429
self .assertTrue (self .cfg .user_init )
419
430
self .assertTrue (self .cfg .aws_init )
@@ -531,7 +542,6 @@ def helper_check_subcmd_config_overwrite(self):
531
542
self .assertIn (S3_BUCKET_NAME_2 , s3_buckets )
532
543
533
544
def helper_check_subcmd_config_shared_move_froster_archives_json (self ):
534
- '''- Check the configuration files after setting full configuration with shared directory'''
535
545
536
546
self .helper_check_subcmd_config_shared ()
537
547
@@ -550,14 +560,14 @@ def test_subcmd_config(self, mock_print):
550
560
551
561
self .helper_run_subcmd_config (None )
552
562
553
- self .helper_check_subcmd_config_not_shared ()
563
+ self .helper_check_subcmd_config ()
554
564
555
565
def test_subcmd_config_overwrite (self , mock_print ,):
556
- '''- Overwirte current configuration'''
566
+ '''- Set full configuration overwritting current configuration'''
557
567
558
568
self .helper_run_subcmd_config (None )
559
569
560
- self .helper_check_subcmd_config_not_shared ()
570
+ self .helper_check_subcmd_config ()
561
571
562
572
self .helper_run_subcmd_config_overwrite (None )
563
573
@@ -568,10 +578,10 @@ def test_subcmd_config_shared(self, mock_print):
568
578
569
579
self .helper_run_subcmd_config (None )
570
580
571
- self .helper_check_subcmd_config_not_shared ()
581
+ self .helper_check_subcmd_config ()
572
582
573
583
def test_subcmd_config_shared_existing_config (self , mock_print ):
574
- '''- Set full configuration with shared directory with existing '''
584
+ '''- Set full configuration with shared directory where there is already a shared configuration file '''
575
585
576
586
self .helper_run_subcmd_config_shared_existing_config (None )
577
587
@@ -585,7 +595,7 @@ def test_subcmd_config_shared_move_froster_archives_json(self, mock_print):
585
595
self .helper_check_subcmd_config_shared_move_froster_archives_json ()
586
596
587
597
def test_subcmd_config_shared_move_config (self , mock_print ):
588
- '''- Set full configuration then set shared and move the config sections to the shared directory config file'''
598
+ '''- Set full configuration and move config to the shared directory config file'''
589
599
590
600
# Not shared full configuration
591
601
self .helper_run_subcmd_config (None )
@@ -599,6 +609,7 @@ def test_subcmd_config_shared_move_config(self, mock_print):
599
609
600
610
@patch ('builtins.print' )
601
611
class TestConfigUser (unittest .TestCase ):
612
+ '''Test the set_user method.'''
602
613
603
614
# Method executed before every test
604
615
def setUp (self ):
@@ -630,6 +641,7 @@ def test_set_user(self, mock_print, mock_text):
630
641
631
642
@patch ('builtins.print' )
632
643
class TestConfigAWS (unittest .TestCase ):
644
+ '''Test the set_aws method.'''
633
645
634
646
# Method executed only once before all tests
635
647
@classmethod
@@ -832,6 +844,7 @@ def test_set_aws_do_not_overwrite_profile(self, mock_print, mock_prompt, mock_li
832
844
833
845
@patch ('builtins.print' )
834
846
class TestConfigShared (unittest .TestCase ):
847
+ '''Test the set_shared method.'''
835
848
836
849
# Method executed before every test
837
850
def setUp (self ):
@@ -996,6 +1009,7 @@ def test_set_shared_froster_shared_config_exist(self, mock_print, mock_confirm,
996
1009
997
1010
@patch ('builtins.print' )
998
1011
class TestConfigNIH (unittest .TestCase ):
1012
+ '''Test the set_nih method.'''
999
1013
1000
1014
# Method executed before every test
1001
1015
def setUp (self ):
@@ -1035,7 +1049,7 @@ def test_set_nih(self, mock_print, mock_confirm):
1035
1049
@patch ('inquirer.confirm' , side_effect = [True , True , False ])
1036
1050
@patch ('inquirer.prompt' , return_value = {'shared_dir' : SHARED_DIR })
1037
1051
def test_set_nih_when_shared_config (self , mock_print , mock_confirm , mock_promp ):
1038
- '''- Set the NIH flag to True and then to False.'''
1052
+ '''- Set the NIH flag to True and then to False when shared configuration .'''
1039
1053
1040
1054
# Call set_shared method
1041
1055
self .assertTrue (self .cfg .set_shared ())
@@ -1057,6 +1071,7 @@ def test_set_nih_when_shared_config(self, mock_print, mock_confirm, mock_promp):
1057
1071
1058
1072
@patch ('builtins.print' )
1059
1073
class TestConfigS3 (unittest .TestCase ):
1074
+ '''Test the set_s3 method.'''
1060
1075
1061
1076
# Method executed before every test
1062
1077
@patch ('inquirer.prompt' , return_value = {'aws_dir' : AWS_DEFAULT_PATH })
@@ -1112,7 +1127,7 @@ def test_set_s3(self, mock_print, mock_list, mock_text):
1112
1127
self .assertIn (S3_BUCKET_NAME , s3_buckets )
1113
1128
1114
1129
def test_set_s3_aws_not_init (self , mock_print ):
1115
- '''- Set_s3 method returns False if AWS credentials are not set.'''
1130
+ '''- set_s3 method returns False if AWS credentials are not set.'''
1116
1131
1117
1132
# Mock the aws_init variable
1118
1133
self .cfg .aws_init = False
0 commit comments