test_setopt.py 966 B

123456789101112131415161718192021222324252627282930
  1. import io
  2. import configparser
  3. from setuptools.command import setopt
  4. class TestEdit:
  5. @staticmethod
  6. def parse_config(filename):
  7. parser = configparser.ConfigParser()
  8. with io.open(filename, encoding='utf-8') as reader:
  9. parser.read_file(reader)
  10. return parser
  11. @staticmethod
  12. def write_text(file, content):
  13. with io.open(file, 'wb') as strm:
  14. strm.write(content.encode('utf-8'))
  15. def test_utf8_encoding_retained(self, tmpdir):
  16. """
  17. When editing a file, non-ASCII characters encoded in
  18. UTF-8 should be retained.
  19. """
  20. config = tmpdir.join('setup.cfg')
  21. self.write_text(str(config), '[names]\njaraco=джарако')
  22. setopt.edit_config(str(config), dict(names=dict(other='yes')))
  23. parser = self.parse_config(str(config))
  24. assert parser.get('names', 'jaraco') == 'джарако'
  25. assert parser.get('names', 'other') == 'yes'