test_program_helper.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from argparse import ArgumentParser
  2. import pytest
  3. from facefusion.program_helper import find_argument_group, remove_args, validate_actions
  4. def test_find_argument_group() -> None:
  5. program = ArgumentParser()
  6. program.add_argument_group('test-1')
  7. program.add_argument_group('test-2')
  8. assert find_argument_group(program, 'test-1')
  9. assert find_argument_group(program, 'test-2')
  10. assert find_argument_group(program, 'invalid') is None
  11. @pytest.mark.skip()
  12. def test_validate_args() -> None:
  13. pass
  14. def test_validate_actions() -> None:
  15. program = ArgumentParser()
  16. program.add_argument('--test-1', default = 'test_1', choices = [ 'test_1', 'test_2' ])
  17. program.add_argument('--test-2', default = 'test_2', choices= [ 'test_1', 'test_2' ], nargs = '+')
  18. assert validate_actions(program) is True
  19. args =\
  20. {
  21. 'test_1': 'test_2',
  22. 'test_2': [ 'test_1', 'test_3' ]
  23. }
  24. for action in program._actions:
  25. if action.dest in args:
  26. action.default = args[action.dest]
  27. assert validate_actions(program) is False
  28. def test_remove_args() -> None:
  29. program = ArgumentParser()
  30. program.add_argument('--test-1')
  31. program.add_argument('--test-2')
  32. program.add_argument('--test-3')
  33. actions = [ action.dest for action in program._actions ]
  34. assert 'test_1' in actions
  35. assert 'test_2' in actions
  36. assert 'test_3' in actions
  37. program = remove_args(program, [ 'test_1', 'test_2' ])
  38. actions = [ action.dest for action in program._actions ]
  39. assert 'test_1' not in actions
  40. assert 'test_2' not in actions
  41. assert 'test_3' in actions