You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
5.9 KiB

9 years ago
  1. import unittest
  2. from gooey.python_bindings.argparse_to_json import *
  3. # I fixed all the tests!
  4. #
  5. # def test_parser_converts_to_correct_type(empty_parser, complete_parser, subparser):
  6. # assert convert(subparser)['layout_type'] == 'column'
  7. # assert convert(empty_parser)['layout_type'] == 'standard'
  8. # assert convert(complete_parser)['layout_type'] == 'standard'
  9. #
  10. #
  11. # def test_parser_without_subparser_recieves_root_entry(complete_parser):
  12. # '''
  13. # Non-subparser setups should receive a default root key called 'primary'
  14. # '''
  15. # result = convert(complete_parser)
  16. # assert 'primary' in result['widgets']
  17. #
  18. #
  19. # def test_grouping_structure(complete_parser):
  20. # '''
  21. # The output of the 'widgets' branch is now wrapped in another
  22. # layer to facilitate interop with the subparser structure
  23. #
  24. # old: widgets: []
  25. # new: widgets: {'a': {}, 'b': {}, ..}
  26. # '''
  27. # result = convert(complete_parser)
  28. # groupings = result['widgets']
  29. # # should now be a dict rather than a list
  30. # assert isinstance(groupings, dict)
  31. # # make sure our expected root keys are there
  32. # for name, group in groupings.items():
  33. # assert 'command' in group
  34. # assert 'contents' in group
  35. # # contents should be the old list of widget info
  36. # assert isinstance(group['contents'], list)
  37. #
  38. #
  39. # def test_subparser_uses_prog_value_if_available():
  40. # parser = argparse.ArgumentParser(description='qidev')
  41. # parser.add_argument('--verbose', help='be verbose', dest='verbose',
  42. # action='store_true', default=False)
  43. # subs = parser.add_subparsers(help='commands', dest='command')
  44. # # NO prog definition for the sub parser
  45. # subs.add_parser('config', help='configure defaults for qidev')
  46. #
  47. # # The stock parser name supplied above (e.g. config) is
  48. # # now in the converted doc
  49. # result = convert(parser)
  50. # assert 'config' in result['widgets']
  51. #
  52. # # new subparser
  53. # parser = argparse.ArgumentParser(description='qidev')
  54. # parser.add_argument('--verbose', help='be verbose', dest='verbose',
  55. # action='store_true', default=False)
  56. # subs = parser.add_subparsers(help='commands', dest='command')
  57. # # prog definition for the sub parser IS supplied
  58. # subs.add_parser('config', prog="My Config", help='configure defaults for qidev')
  59. #
  60. # # Should've picked up the prog value
  61. # result = convert(parser)
  62. # assert 'My Config' in result['widgets']
  63. #
  64. #
  65. # def test_convert_std_parser(complete_parser):
  66. # result = convert(complete_parser)
  67. # # grab the first entry from the dict
  68. # entry = result['widgets']['primary']['contents'][0]
  69. # print(entry)
  70. # assert 'type' in entry
  71. # assert 'required' in entry
  72. # assert 'data' in entry
  73. #
  74. #
  75. # def test_convert_sub_parser(subparser):
  76. # result = convert(subparser)
  77. # assert result['layout_type'] == 'column'
  78. # assert result['widgets']
  79. # assert isinstance(result['widgets'], dict)
  80. # assert len(result['widgets']) == 3
  81. #
  82. #
  83. # def test_has_required(empty_parser, complete_parser, subparser):
  84. # assert has_required(complete_parser._actions)
  85. # assert not has_required(empty_parser._actions)
  86. # assert not has_required(subparser._actions)
  87. #
  88. #
  89. # def test_has_subparsers(subparser, complete_parser):
  90. # assert has_subparsers(subparser._actions)
  91. # assert not has_subparsers(complete_parser._actions)
  92. #
  93. #
  94. # def test_is_required(complete_parser):
  95. # required = list(filter(is_required, complete_parser._actions))
  96. # assert len(required) == 4
  97. # for action in required:
  98. # print(action.dest.startswith('req'))
  99. #
  100. #
  101. # def test_is_optional(complete_parser):
  102. # optional = list(filter(is_optional, complete_parser._actions))
  103. # assert len(optional) == 10
  104. # for action in optional:
  105. # assert 'req' not in action.dest
  106. #
  107. #
  108. # def test_is_choice(empty_parser):
  109. # empty_parser.add_argument('--dropdown', choices=[1, 2])
  110. # assert is_choice(get_action(empty_parser, 'dropdown'))
  111. #
  112. # empty_parser.add_argument('--storetrue', action='store_true')
  113. # assert not is_choice(get_action(empty_parser, 'storetrue'))
  114. #
  115. # # make sure positionals are caught as well (issue #85)
  116. # empty_parser.add_argument('positional', choices=[1, 2])
  117. # assert is_choice(get_action(empty_parser, 'positional'))
  118. #
  119. #
  120. # def test_is_standard(empty_parser):
  121. # empty_parser.add_argument('--count', action='count')
  122. # assert not is_standard(get_action(empty_parser, 'count'))
  123. #
  124. # empty_parser.add_argument('--store', action='store')
  125. # assert is_standard(get_action(empty_parser, 'store'))
  126. #
  127. #
  128. # def test_is_counter(empty_parser):
  129. # empty_parser.add_argument('--count', action='count')
  130. # assert is_counter(get_action(empty_parser, 'count'))
  131. #
  132. # empty_parser.add_argument('--dropdown', choices=[1, 2])
  133. # assert not is_counter(get_action(empty_parser, 'dropdown'))
  134. #
  135. #
  136. # def test_mutually(exclusive_group):
  137. # target_arg = find_arg_by_option(exclusive_group, '-i')
  138. # json_result = build_radio_group(exclusive_group)
  139. #
  140. # data = json_result['data'][0]
  141. # assert 'RadioGroup' == json_result['type']
  142. # assert target_arg.choices == data['choices']
  143. # assert target_arg.help == data['help']
  144. # assert target_arg.option_strings == data['commands']
  145. # assert target_arg.dest == data['display_name']
  146. #
  147. #
  148. # def test_empty_mutex_group():
  149. # assert not build_radio_group(None)
  150. #
  151. #
  152. # def test_as_json_invalid_widget():
  153. # with pytest.raises(UnknownWidgetType):
  154. # action_to_json(None, 'InvalidWidget', None)
  155. #
  156. #
  157. # def get_action(parser, dest):
  158. # for action in parser._actions:
  159. # if action.dest == dest:
  160. # return action
  161. #
  162. #
  163. # def find_arg_by_option(group, option_string):
  164. # for arg in group:
  165. # if option_string in arg.option_strings:
  166. # return arg