Skip to content

Commit dd3603d

Browse files
committed
relink.py: New fn process_args.
1 parent d2161d0 commit dd3603d

2 files changed

Lines changed: 58 additions & 7 deletions

File tree

relink.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,36 @@ def parse_arguments():
192192
help="Measure and display the execution time",
193193
)
194194

195-
return parser.parse_args()
195+
args = parser.parse_args()
196196

197-
def main():
197+
process_args(args)
198198

199-
args = parse_arguments()
199+
return args
200200

201+
202+
def process_args(args):
203+
"""
204+
Process parsed arguments and set derived attributes.
205+
206+
Sets the log_level attribute on args based on verbosity flags.
207+
208+
Args:
209+
args (argparse.Namespace): Parsed command-line arguments.
210+
"""
201211
# Configure logging based on verbosity flags
202212
if args.quiet:
203-
log_level = logging.WARNING
213+
args.log_level = logging.WARNING
204214
elif args.verbose:
205-
log_level = logging.DEBUG
215+
args.log_level = logging.DEBUG
206216
else:
207-
log_level = logging.INFO
217+
args.log_level = logging.INFO
218+
208219

209-
logging.basicConfig(level=log_level, format="%(message)s", stream=sys.stdout)
220+
def main():
221+
222+
args = parse_arguments()
223+
224+
logging.basicConfig(level=args.log_level, format="%(message)s", stream=sys.stdout)
210225

211226
my_username = os.environ["USER"]
212227

@@ -221,5 +236,6 @@ def main():
221236
elapsed_time = time.time() - start_time
222237
logger.info("Execution time: %.2f seconds", elapsed_time)
223238

239+
224240
if __name__ == "__main__":
225241
main()

tests/test_relink.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ def mock_symlink(src, dst):
615615
relink.find_and_replace_owned_files(source_dir, target_dir, username)
616616
assert "Error creating symlink" in caplog.text
617617

618+
618619
class TestEdgeCases:
619620
"""Test edge cases and error handling."""
620621

@@ -726,6 +727,7 @@ def mock_symlink(src, dst):
726727
assert "Error creating symlink" in caplog.text
727728
assert source_file in caplog.text
728729

730+
729731
class TestTiming:
730732
"""Test suite for timing functionality."""
731733

@@ -989,3 +991,36 @@ def test_command_line_execution_actual_run(self, mock_dirs):
989991

990992
# Verify success messages in output
991993
assert "Created symbolic link:" in result.stdout
994+
995+
996+
class TestProcessArgs:
997+
"""Test suite for process_args function."""
998+
999+
# pylint: disable=no-member
1000+
1001+
def test_process_args_quiet_sets_warning_level(self):
1002+
"""Test that quiet flag sets log level to WARNING."""
1003+
args = argparse.Namespace(quiet=True, verbose=False)
1004+
relink.process_args(args)
1005+
assert args.log_level == logging.WARNING
1006+
1007+
def test_process_args_verbose_sets_debug_level(self):
1008+
"""Test that verbose flag sets log level to DEBUG."""
1009+
args = argparse.Namespace(quiet=False, verbose=True)
1010+
relink.process_args(args)
1011+
assert args.log_level == logging.DEBUG
1012+
1013+
def test_process_args_default_sets_info_level(self):
1014+
"""Test that default (no flags) sets log level to INFO."""
1015+
args = argparse.Namespace(quiet=False, verbose=False)
1016+
relink.process_args(args)
1017+
assert args.log_level == logging.INFO
1018+
1019+
def test_process_args_modifies_args_in_place(self):
1020+
"""Test that process_args modifies the args object in place."""
1021+
args = argparse.Namespace(quiet=False, verbose=False)
1022+
original_args = args
1023+
relink.process_args(args)
1024+
# Should be the same object, modified in place
1025+
assert args is original_args
1026+
assert hasattr(args, "log_level")

0 commit comments

Comments
 (0)