Advertisement
Guest User

CPython/Jython test_site_jy.py

a guest
Mar 29th, 2012
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement