cpython/Lib/packaging/tests/test_run.py
Éric Araujo 6bbd775377 Consolidate tests for packaging.metadata.
New tests were added in test_metadata and old tests inherited from
distutils were still in test_dist, so I moved them into test_metadata
(except for one which was more at home in test_run) and merged
duplicates.

I also added some skips to lure contributors <wink>, optimized the
Metadata.update method a trifle, and added notes about a number of
issues.

A note: The tests in test_dist used to dump the Metadata objects to a
file in the METADATA format and look for strings in its contents; I
updated them to use the mapping API of Metadata instead.  For some
fields with special writing rules, I have added tests to ensure my
conversion did not lose anything.
2011-09-10 05:18:20 +02:00

92 lines
2.4 KiB
Python

"""Tests for packaging.run."""
import os
import sys
import shutil
from io import StringIO
from packaging import install
from packaging.tests import unittest, support, TESTFN
from packaging.run import main
from test.script_helper import assert_python_ok
# setup script that uses __file__
setup_using___file__ = """\
__file__
from packaging.run import setup
setup()
"""
setup_prints_cwd = """\
import os
print os.getcwd()
from packaging.run import setup
setup()
"""
class RunTestCase(support.TempdirManager,
support.LoggingCatcher,
unittest.TestCase):
def setUp(self):
super(RunTestCase, self).setUp()
self.old_stdout = sys.stdout
self.cleanup_testfn()
self.old_argv = sys.argv, sys.argv[:]
def tearDown(self):
sys.stdout = self.old_stdout
self.cleanup_testfn()
sys.argv = self.old_argv[0]
sys.argv[:] = self.old_argv[1]
super(RunTestCase, self).tearDown()
def cleanup_testfn(self):
path = TESTFN
if os.path.isfile(path):
os.remove(path)
elif os.path.isdir(path):
shutil.rmtree(path)
def write_setup(self, text, path=TESTFN):
with open(path, "w") as fp:
fp.write(text)
return path
# TODO restore the tests removed six months ago and port them to pysetup
def test_install(self):
# making sure install returns 0 or 1 exit codes
project = os.path.join(os.path.dirname(__file__), 'package.tgz')
install_path = self.mkdtemp()
old_get_path = install.get_path
install.get_path = lambda path: install_path
old_mod = os.stat(install_path).st_mode
os.chmod(install_path, 0)
old_stderr = sys.stderr
sys.stderr = StringIO()
try:
self.assertFalse(install.install(project))
self.assertEqual(main(['install', 'blabla']), 1)
finally:
sys.stderr = old_stderr
os.chmod(install_path, old_mod)
install.get_path = old_get_path
def test_show_help(self):
# smoke test, just makes sure some help is displayed
status, out, err = assert_python_ok('-m', 'packaging.run', '--help')
self.assertEqual(status, 0)
self.assertGreater(out, b'')
self.assertEqual(err, b'')
def test_suite():
return unittest.makeSuite(RunTestCase)
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")