Skip to content

Commit de3468b

Browse files
Merge pull request #60 from HPCNow/main
froster v0.12.17 - test_config.py finished
2 parents f54f39f + b112952 commit de3468b

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "froster"
7-
version = "0.12.15"
7+
version = "0.12.17"
88
description = "Froster is a tool for easy data transfer between local file systems and AWS S3 storage."
99
authors = ["Victor Machado <[email protected]>"]
1010
readme = "README.md"

Diff for: tests/test_config.py

+32-17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import tempfile
77
from unittest.mock import patch
88
import unittest
9+
910
import warnings
1011
warnings.filterwarnings("always", category=ResourceWarning)
1112
warnings.filterwarnings("ignore", category=ResourceWarning)
@@ -54,6 +55,8 @@
5455

5556

5657
def init_froster(self):
58+
'''Initialize the froster objects.'''
59+
5760
self.cmd = Commands()
5861
self.parser = self.cmd.parse_arguments()
5962
self.args = self.parser.parse_args()
@@ -83,6 +86,7 @@ def init_froster(self):
8386

8487

8588
def deinit_froster(self):
89+
'''Deinitialize the froster objects.'''
8690

8791
if hasattr(self, 'cfg'):
8892
if hasattr(self.cfg, 'aws_dir') and os.path.exists(self.cfg.aws_dir):
@@ -114,6 +118,7 @@ def deinit_froster(self):
114118

115119

116120
def delete_buckets(self):
121+
'''Delete created S3 buckets if they exists.'''
117122

118123
if self.aws.check_credentials():
119124
# Get the buckets list
@@ -127,6 +132,8 @@ def delete_buckets(self):
127132

128133

129134
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+
130137
config = configparser.ConfigParser()
131138
config.read(ini_file)
132139
self.assertIn(section, config.sections())
@@ -135,16 +142,20 @@ def check_ini_file(self, ini_file, section, key, value):
135142

136143
@patch('builtins.print')
137144
class TestConfig(unittest.TestCase):
145+
'''Test the subcmd_confing method.'''
138146

139147
# Method executed only once before all tests
140148
@classmethod
141149
def setUpClass(cls):
150+
151+
# Check if the AWS credentials are set
142152
if AWS_ACCESS_KEY_ID is None or AWS_SECRET is None:
143153
raise ValueError("AWS credentials are not set")
144154

145155
# Method executed before every test
146156
def setUp(self):
147157

158+
# Initialize the froster objects
148159
init_froster(self)
149160

150161
# Delete any existing buckets
@@ -156,12 +167,13 @@ def tearDown(self):
156167
# Delete any existing buckets
157168
delete_buckets(self)
158169

170+
# Deinitialize the froster objects
159171
deinit_froster(self)
160172

161173
# HELPER RUNS
162174

163175
def helper_set_default_cli_arguments(self):
164-
'''- Set default arguments.'''
176+
'''- Set default cli arguments.'''
165177

166178
self.cmd.args = Namespace(cores=4, debug=False, info=False, memory=64, noslurm=False, aws_profile='', version=False,
167179
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
190202
@patch('inquirer.list_input', side_effect=['+ Create new profile', AWS_REGION, '+ Create new bucket', S3_STORAGE_CLASS])
191203
@patch('inquirer.confirm', side_effect=[True, False])
192204
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'''
194206

195207
# Check that nothing is set yet
196208
self.assertFalse(self.cfg.user_init)
@@ -209,7 +221,7 @@ def helper_run_subcmd_config_shared(self, mock_print, mock_text, mock_prompt, mo
209221
@patch('inquirer.list_input', side_effect=['+ Create new profile', AWS_REGION, '+ Create new bucket', S3_STORAGE_CLASS, AWS_PROFILE, AWS_REGION])
210222
@patch('inquirer.confirm', side_effect=[True, False, True, True])
211223
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'''
213225

214226
# Check that nothing is set yet
215227
self.assertFalse(self.cfg.user_init)
@@ -231,7 +243,7 @@ def helper_run_subcmd_config_shared_existing_config(self, mock_print, mock_text,
231243
@patch('inquirer.list_input', side_effect=['+ Create new profile', AWS_REGION_2, '+ Create new bucket', S3_STORAGE_CLASS_2])
232244
@patch('inquirer.confirm', side_effect=[True, False, False])
233245
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'''
235247

236248
# Mock the CLI default arguments
237249
self.helper_set_default_cli_arguments()
@@ -244,7 +256,7 @@ def helper_run_subcmd_config_overwrite(self, mock_print, mock_text, mock_prompt,
244256
@patch('inquirer.list_input', side_effect=['+ Create new profile', AWS_REGION, '+ Create new bucket', S3_STORAGE_CLASS])
245257
@patch('inquirer.confirm', side_effect=[True, True, False])
246258
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'''
248260

249261
# Check that nothing is set yet
250262
self.assertFalse(self.cfg.user_init)
@@ -294,7 +306,6 @@ def helper_run_subcmd_config_shared_move_config_sections(self, mock_print, mock_
294306
# HELPER CHECKS
295307

296308
def helper_check_subcmd_config(self):
297-
'''- Check the configuration files after setting full configuration'''
298309

299310
# Check that everything is set
300311
self.assertTrue(self.cfg.user_init)
@@ -352,7 +363,7 @@ def helper_check_subcmd_config(self):
352363
self.assertIn(S3_BUCKET_NAME, s3_buckets)
353364

354365
def helper_check_subcmd_config_shared(self):
355-
'''- Check the configuration files after setting full configuration with shared directory'''
366+
356367
# Check that everything is set
357368
self.assertTrue(self.cfg.user_init)
358369
self.assertTrue(self.cfg.aws_init)
@@ -413,7 +424,7 @@ def helper_check_subcmd_config_shared(self):
413424
self.assertIn(S3_BUCKET_NAME, s3_buckets)
414425

415426
def helper_check_subcmd_config_shared_existing_config(self):
416-
'''- Check the configuration files after setting full configuration with shared directory'''
427+
417428
# Check that everything is set
418429
self.assertTrue(self.cfg.user_init)
419430
self.assertTrue(self.cfg.aws_init)
@@ -531,7 +542,6 @@ def helper_check_subcmd_config_overwrite(self):
531542
self.assertIn(S3_BUCKET_NAME_2, s3_buckets)
532543

533544
def helper_check_subcmd_config_shared_move_froster_archives_json(self):
534-
'''- Check the configuration files after setting full configuration with shared directory'''
535545

536546
self.helper_check_subcmd_config_shared()
537547

@@ -550,14 +560,14 @@ def test_subcmd_config(self, mock_print):
550560

551561
self.helper_run_subcmd_config(None)
552562

553-
self.helper_check_subcmd_config_not_shared()
563+
self.helper_check_subcmd_config()
554564

555565
def test_subcmd_config_overwrite(self, mock_print,):
556-
'''- Overwirte current configuration'''
566+
'''- Set full configuration overwritting current configuration'''
557567

558568
self.helper_run_subcmd_config(None)
559569

560-
self.helper_check_subcmd_config_not_shared()
570+
self.helper_check_subcmd_config()
561571

562572
self.helper_run_subcmd_config_overwrite(None)
563573

@@ -568,10 +578,10 @@ def test_subcmd_config_shared(self, mock_print):
568578

569579
self.helper_run_subcmd_config(None)
570580

571-
self.helper_check_subcmd_config_not_shared()
581+
self.helper_check_subcmd_config()
572582

573583
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'''
575585

576586
self.helper_run_subcmd_config_shared_existing_config(None)
577587

@@ -585,7 +595,7 @@ def test_subcmd_config_shared_move_froster_archives_json(self, mock_print):
585595
self.helper_check_subcmd_config_shared_move_froster_archives_json()
586596

587597
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'''
589599

590600
# Not shared full configuration
591601
self.helper_run_subcmd_config(None)
@@ -599,6 +609,7 @@ def test_subcmd_config_shared_move_config(self, mock_print):
599609

600610
@patch('builtins.print')
601611
class TestConfigUser(unittest.TestCase):
612+
'''Test the set_user method.'''
602613

603614
# Method executed before every test
604615
def setUp(self):
@@ -630,6 +641,7 @@ def test_set_user(self, mock_print, mock_text):
630641

631642
@patch('builtins.print')
632643
class TestConfigAWS(unittest.TestCase):
644+
'''Test the set_aws method.'''
633645

634646
# Method executed only once before all tests
635647
@classmethod
@@ -832,6 +844,7 @@ def test_set_aws_do_not_overwrite_profile(self, mock_print, mock_prompt, mock_li
832844

833845
@patch('builtins.print')
834846
class TestConfigShared(unittest.TestCase):
847+
'''Test the set_shared method.'''
835848

836849
# Method executed before every test
837850
def setUp(self):
@@ -996,6 +1009,7 @@ def test_set_shared_froster_shared_config_exist(self, mock_print, mock_confirm,
9961009

9971010
@patch('builtins.print')
9981011
class TestConfigNIH(unittest.TestCase):
1012+
'''Test the set_nih method.'''
9991013

10001014
# Method executed before every test
10011015
def setUp(self):
@@ -1035,7 +1049,7 @@ def test_set_nih(self, mock_print, mock_confirm):
10351049
@patch('inquirer.confirm', side_effect=[True, True, False])
10361050
@patch('inquirer.prompt', return_value={'shared_dir': SHARED_DIR})
10371051
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.'''
10391053

10401054
# Call set_shared method
10411055
self.assertTrue(self.cfg.set_shared())
@@ -1057,6 +1071,7 @@ def test_set_nih_when_shared_config(self, mock_print, mock_confirm, mock_promp):
10571071

10581072
@patch('builtins.print')
10591073
class TestConfigS3(unittest.TestCase):
1074+
'''Test the set_s3 method.'''
10601075

10611076
# Method executed before every test
10621077
@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):
11121127
self.assertIn(S3_BUCKET_NAME, s3_buckets)
11131128

11141129
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.'''
11161131

11171132
# Mock the aws_init variable
11181133
self.cfg.aws_init = False

0 commit comments

Comments
 (0)