summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_site.py35
-rw-r--r--Lib/test/test_warnings.py9
2 files changed, 43 insertions, 1 deletions
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index b80d6e6995..329df4b98a 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -10,6 +10,7 @@ import builtins
import os
import sys
import encodings
+import subprocess
# Need to make sure to not import 'site' if someone specified ``-S`` at the
# command-line. Detect this by just making sure 'site' has not been imported
# already.
@@ -18,6 +19,11 @@ if "site" in sys.modules:
else:
raise TestSkipped("importation of site.py suppressed")
+if not os.path.isdir(site.USER_SITE):
+ # need to add user site directory for tests
+ os.makedirs(site.USER_SITE)
+ site.addsitedir(site.USER_SITE)
+
class HelperFunctionsTests(unittest.TestCase):
"""Tests for helper functions.
@@ -30,7 +36,7 @@ class HelperFunctionsTests(unittest.TestCase):
"""Save a copy of sys.path"""
self.sys_path = sys.path[:]
- def tearDown(self):
+
"""Restore sys.path"""
sys.path = self.sys_path
@@ -90,6 +96,33 @@ class HelperFunctionsTests(unittest.TestCase):
finally:
pth_file.cleanup()
+ def test_s_option(self):
+ usersite = site.USER_SITE
+ self.assert_(usersite in sys.path)
+
+ rc = subprocess.call([sys.executable, '-c',
+ 'import sys; sys.exit("%s" in sys.path)' % usersite])
+ self.assertEqual(rc, 1)
+
+ rc = subprocess.call([sys.executable, '-s', '-c',
+ 'import sys; sys.exit("%s" in sys.path)' % usersite])
+ self.assertEqual(rc, 0)
+
+ env = os.environ.copy()
+ env["PYTHONNOUSERSITE"] = "1"
+ rc = subprocess.call([sys.executable, '-c',
+ 'import sys; sys.exit("%s" in sys.path)' % usersite],
+ env=env)
+ self.assertEqual(rc, 0)
+
+ env = os.environ.copy()
+ env["PYTHONUSERBASE"] = "/tmp"
+ rc = subprocess.call([sys.executable, '-c',
+ 'import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))'],
+ env=env)
+ self.assertEqual(rc, 1)
+
+
class PthFile(object):
"""Helper class for handling testing of .pth files"""
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
index 945dbb34f3..fa2297ce28 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -388,6 +388,15 @@ class _WarningsTests(BaseTest):
result = stream.getvalue()
self.failUnless(text in result)
+ def test_showwarning_not_callable(self):
+ self.module.filterwarnings("always", category=UserWarning)
+ old_showwarning = self.module.showwarning
+ self.module.showwarning = 23
+ try:
+ self.assertRaises(TypeError, self.module.warn, "Warning!")
+ finally:
+ self.module.showwarning = old_showwarning
+
def test_show_warning_output(self):
# With showarning() missing, make sure that output is okay.
text = 'test show_warning'