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.

55 lines
1.8 KiB

  1. __author__ = 'Chris'
  2. import unittest
  3. from gooey.python_bindings import code_prep
  4. def test_split_line():
  5. line = "parser = ArgumentParser(description='Example Argparse Program')"
  6. assert "parser" == code_prep.split_line(line)[0]
  7. assert "ArgumentParser(description='Example Argparse Program')" == code_prep.split_line(line)[1]
  8. def test_update_parser_varname_assigns_new_name_to_parser_var():
  9. line = ["parser = ArgumentParser(description='Example Argparse Program')"]
  10. expected = "jarser = ArgumentParser(description='Example Argparse Program')"
  11. result = code_prep.update_parser_varname('jarser', line)[0]
  12. assert result == expected
  13. def test_update_parser_varname_assigns_new_name_to_parser_var__multiline():
  14. lines = '''
  15. import argparse
  16. from argparse import ArgumentParser
  17. parser = ArgumentParser(description='Example Argparse Program')
  18. parser.parse_args()
  19. '''.split('\n')
  20. line = "jarser = ArgumentParser(description='Example Argparse Program')"
  21. result = code_prep.update_parser_varname('jarser', lines)[2]
  22. assert line == result
  23. def test_take_imports_drops_all_non_imports_statements():
  24. lines = '''
  25. import argparse
  26. from argparse import ArgumentParser
  27. parser = ArgumentParser(description='Example Argparse Program')
  28. parser.parse_args()
  29. '''.split('\n')[1:]
  30. assert 2 == len(list(code_prep.take_imports(lines)))
  31. assert 'import argparse' == list(code_prep.take_imports(lines))[0]
  32. def test_drop_imports_excludes_all_imports_statements():
  33. lines = '''
  34. import argparse
  35. from argparse import ArgumentParser
  36. parser = ArgumentParser(description='Example Argparse Program')
  37. parser.parse_args()
  38. '''.split('\n')[1:]
  39. assert 2 == len(list(code_prep.take_imports(lines)))
  40. assert 'parser.parse_args()' == list(code_prep.drop_imports(lines))[1]