test_Config.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # vim: set fileencoding=utf-8 :
  2. """
  3. Test L{gbp.config.GbpOptionParser}
  4. Test L{gbp.config.GbpOptionParserDebian}
  5. """
  6. from . import context
  7. def test_option_parser():
  8. """
  9. Methods tested:
  10. - L{gbp.config.GbpOptionParser.add_config_file_option}
  11. - L{gbp.config.GbpOptionParser.add_boolean_config_file_option}
  12. >>> import gbp.config
  13. >>> c = gbp.config.GbpOptionParser('common', prefix='test')
  14. >>> c.add_config_file_option(option_name='upstream-branch', dest='upstream')
  15. >>> c.add_boolean_config_file_option(option_name='overlay', dest='overlay')
  16. >>> c.add_boolean_config_file_option(option_name='track', dest='track')
  17. """
  18. def test_option_parser_debian():
  19. """
  20. Methods tested:
  21. - L{gbp.config.GbpOptionParserDebian.add_config_file_option}
  22. >>> import gbp.config
  23. >>> c = gbp.config.GbpOptionParserDebian('debian')
  24. >>> c.add_config_file_option(option_name='builder', dest='builder')
  25. Traceback (most recent call last):
  26. ...
  27. KeyError: 'builder'
  28. >>> c.add_config_file_option(option_name='builder', dest='builder', help='foo')
  29. """
  30. def test_option_group():
  31. """
  32. Methods tested:
  33. - L{gbp.config.GbpOptionGroup.add_config_file_option}
  34. - L{gbp.config.GbpOptionGroup.add_boolean_config_file_option}
  35. >>> import gbp.config
  36. >>> c = gbp.config.GbpOptionParser('debian')
  37. >>> g = gbp.config.GbpOptionGroup(c, 'wheezy')
  38. >>> g.add_config_file_option(option_name='debian-branch', dest='branch')
  39. >>> g.add_boolean_config_file_option(option_name='track', dest='track')
  40. """
  41. def test_tristate():
  42. """
  43. Methods tested:
  44. - L{gbp.config.GbpOptionParser.add_config_file_option}
  45. >>> import gbp.config
  46. >>> c = gbp.config.GbpOptionParser('tristate')
  47. >>> c.add_config_file_option(option_name="color", dest="color", type='tristate')
  48. >>> options, args= c.parse_args(['--color=auto'])
  49. >>> options.color
  50. auto
  51. """
  52. def test_filter():
  53. """
  54. The filter option should always parse as a list
  55. >>> import os
  56. >>> from gbp.config import GbpOptionParser
  57. >>> tmpdir = str(context.new_tmpdir('bar'))
  58. >>> confname = os.path.join(tmpdir, 'gbp.conf')
  59. >>> GbpOptionParser._set_config_file_value('bar', 'filter', 'asdf', filename=confname)
  60. >>> os.environ['GBP_CONF_FILES'] = confname
  61. >>> parser = GbpOptionParser('bar')
  62. >>> parser.config['filter']
  63. ['asdf']
  64. >>> f = open(confname, 'w')
  65. >>> ret = f.write("[bar]\\nfilter = ['this', 'is', 'a', 'list']\\n")
  66. >>> f.close()
  67. >>> parser = GbpOptionParser('bar')
  68. >>> parser.config['filter']
  69. ['this', 'is', 'a', 'list']
  70. >>> del os.environ['GBP_CONF_FILES']
  71. """