test_master_env_config_migrate.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import os
  2. import sys
  3. import io
  4. MODULE_PATH = os.path.realpath(os.path.join(__file__, os.pardir, os.pardir, 'library'))
  5. sys.path.insert(1, MODULE_PATH)
  6. import master_env_config_migrate # noqa
  7. INFILE = u"""
  8. t1=Yes
  9. t2=A Space
  10. t3=An\ escaped
  11. t4="A quoted space"
  12. t5="a quoted \\
  13. escaped line"
  14. t6 = an unquoted multiline \\
  15. string
  16. """
  17. def test_read_write_ini():
  18. infile = io.StringIO(INFILE)
  19. outfile = io.StringIO()
  20. if master_env_config_migrate.CONFIG_PROXY_NEW:
  21. config = master_env_config_migrate.SectionlessParser()
  22. else:
  23. config = master_env_config_migrate.SectionlessParserOld()
  24. config.readfp(infile)
  25. config.write(outfile, False)
  26. print(outfile.getvalue())
  27. # TODO(michaelgugino): Come up with some clever way to assert the file is
  28. # correct.
  29. def test_read_write_ini_old():
  30. master_env_config_migrate.CONFIG_PROXY_NEW = False
  31. test_read_write_ini()
  32. # Contents for t.in:
  33. ############################
  34. # t1=This is a spaced string
  35. # t2="Quoted spaced string"
  36. # t3=Escaped\ spaced\ string
  37. # t4 = String
  38. # t5="Quoted multiline string\
  39. # with escaped newline"
  40. # t6=escaped\ spaced\\
  41. # multiline\ unquoted.
  42. if __name__ == '__main__':
  43. test_read_write_ini()
  44. test_read_write_ini_old()
  45. with open('t.in') as f:
  46. config = master_env_config_migrate.SectionlessParser()
  47. config.readfp(f)
  48. with open('t.out', 'w') as f:
  49. config.write(f, False)
  50. with open('t.in') as f:
  51. config = master_env_config_migrate.SectionlessParserOld()
  52. config.readfp(f)
  53. with open('t2.out', 'w') as f:
  54. config.write(f, False)