Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

CPython/Jython test_site_jy.py

By: a guest on Mar 29th, 2012  |  syntax: Python  |  size: 1.25 KB  |  views: 35  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. """Misc site tests
  2.  
  3. Made for Jython.
  4. """
  5. from __future__ import with_statement
  6. import os
  7. import shutil
  8. import subprocess
  9. import sys
  10. import unittest
  11. from test import test_support
  12.  
  13. ENCODING_TEST = 'utf16'
  14.  
  15. SITECUSTOMIZE = """\
  16. import sys
  17. sys.setdefaultencoding(%r)
  18. """ % ENCODING_TEST
  19.  
  20. class SiteCustomize(unittest.TestCase):
  21.  
  22.     def setUp(self):
  23.         os.mkdir(test_support.TESTFN)
  24.         with open(os.path.join(test_support.TESTFN, 'sitecustomize.py'),
  25.                   'w') as fp:
  26.             fp.write(SITECUSTOMIZE)
  27.  
  28.     def tearDown(self):
  29.         shutil.rmtree(test_support.TESTFN)
  30.  
  31.     def test_setdefaultencoding(self):
  32.         test = ('import sys;'
  33.                 'print "%s|%s" % '
  34.                 '(sys.getdefaultencoding(), sys.stdin.encoding)')
  35.         env = os.environ.copy()
  36.         env['PYTHONPATH'] = test_support.TESTFN
  37.         popen = subprocess.Popen([sys.executable, '-c', test],
  38.                                  stdout=subprocess.PIPE,
  39.                                  env=env)
  40.         result = popen.communicate()[0].rstrip()
  41.         self.assertEqual('%s|%s' % (ENCODING_TEST, ENCODING_TEST), result)
  42.  
  43.  
  44. def test_main():
  45.     test_support.run_unittest(SiteCustomize)
  46.  
  47.  
  48. if __name__ == '__main__':
  49.     test_main()