
CPython/Jython test_site_jy.py
By: a guest on
Mar 29th, 2012 | syntax:
Python | size: 1.25 KB | hits: 30 | expires: Never
"""Misc site tests
Made for Jython.
"""
from __future__ import with_statement
import os
import shutil
import subprocess
import sys
import unittest
from test import test_support
ENCODING_TEST = 'utf16'
SITECUSTOMIZE = """\
import sys
sys.setdefaultencoding(%r)
""" % ENCODING_TEST
class SiteCustomize(unittest.TestCase):
def setUp(self):
os.mkdir(test_support.TESTFN)
with open(os.path.join(test_support.TESTFN, 'sitecustomize.py'),
'w') as fp:
fp.write(SITECUSTOMIZE)
def tearDown(self):
shutil.rmtree(test_support.TESTFN)
def test_setdefaultencoding(self):
test = ('import sys;'
'print "%s|%s" % '
'(sys.getdefaultencoding(), sys.stdin.encoding)')
env = os.environ.copy()
env['PYTHONPATH'] = test_support.TESTFN
popen = subprocess.Popen([sys.executable, '-c', test],
stdout=subprocess.PIPE,
env=env)
result = popen.communicate()[0].rstrip()
self.assertEqual('%s|%s' % (ENCODING_TEST, ENCODING_TEST), result)
def test_main():
test_support.run_unittest(SiteCustomize)
if __name__ == '__main__':
test_main()