mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Clean up some idioms in packaging tests.
- Use os.makedirs (I had forgotten about it!) - Let TempdirManager.write_file call os.path.join for us - Remove custom command added by test_dist - Use a skip instead of hiding a method with an underscore - Address pyflakes warnings
This commit is contained in:
parent
79d9c42b04
commit
f3f283a1cb
13 changed files with 40 additions and 37 deletions
|
@ -3,7 +3,6 @@
|
||||||
# Ripped from importlib tests, thanks Brett!
|
# Ripped from importlib tests, thanks Brett!
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import run_unittest, reap_children, reap_threads
|
from test.support import run_unittest, reap_children, reap_threads
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ class cleanTestCase(support.TempdirManager, support.LoggingCatcher,
|
||||||
if name == 'build_base':
|
if name == 'build_base':
|
||||||
continue
|
continue
|
||||||
for f in ('one', 'two', 'three'):
|
for f in ('one', 'two', 'three'):
|
||||||
self.write_file(os.path.join(path, f))
|
self.write_file((path, f))
|
||||||
|
|
||||||
# let's run the command
|
# let's run the command
|
||||||
cmd.all = True
|
cmd.all = True
|
||||||
|
|
|
@ -117,6 +117,11 @@ class InstallDataTestCase(support.TempdirManager,
|
||||||
dist.command_obj['install_distinfo'] = cmd
|
dist.command_obj['install_distinfo'] = cmd
|
||||||
cmd.run()
|
cmd.run()
|
||||||
|
|
||||||
|
# first a few sanity checks
|
||||||
|
self.assertEqual(os.listdir(scripts_dir), ['spamd'])
|
||||||
|
self.assertEqual(os.listdir(install_dir), ['Spamlib-0.1.dist-info'])
|
||||||
|
|
||||||
|
# now the real test
|
||||||
fn = os.path.join(install_dir, 'Spamlib-0.1.dist-info', 'RESOURCES')
|
fn = os.path.join(install_dir, 'Spamlib-0.1.dist-info', 'RESOURCES')
|
||||||
with open(fn, encoding='utf-8') as fp:
|
with open(fn, encoding='utf-8') as fp:
|
||||||
content = fp.read().strip()
|
content = fp.read().strip()
|
||||||
|
|
|
@ -93,21 +93,20 @@ class InstallTestCase(support.TempdirManager,
|
||||||
self.old_expand = os.path.expanduser
|
self.old_expand = os.path.expanduser
|
||||||
os.path.expanduser = _expanduser
|
os.path.expanduser = _expanduser
|
||||||
|
|
||||||
try:
|
def cleanup():
|
||||||
# this is the actual test
|
|
||||||
self._test_user_site()
|
|
||||||
finally:
|
|
||||||
_CONFIG_VARS['userbase'] = self.old_user_base
|
_CONFIG_VARS['userbase'] = self.old_user_base
|
||||||
_SCHEMES.set(scheme, 'purelib', self.old_user_site)
|
_SCHEMES.set(scheme, 'purelib', self.old_user_site)
|
||||||
os.path.expanduser = self.old_expand
|
os.path.expanduser = self.old_expand
|
||||||
|
|
||||||
def _test_user_site(self):
|
self.addCleanup(cleanup)
|
||||||
|
|
||||||
schemes = get_scheme_names()
|
schemes = get_scheme_names()
|
||||||
for key in ('nt_user', 'posix_user', 'os2_home'):
|
for key in ('nt_user', 'posix_user', 'os2_home'):
|
||||||
self.assertIn(key, schemes)
|
self.assertIn(key, schemes)
|
||||||
|
|
||||||
dist = Distribution({'name': 'xx'})
|
dist = Distribution({'name': 'xx'})
|
||||||
cmd = install_dist(dist)
|
cmd = install_dist(dist)
|
||||||
|
|
||||||
# making sure the user option is there
|
# making sure the user option is there
|
||||||
options = [name for name, short, lable in
|
options = [name for name, short, lable in
|
||||||
cmd.user_options]
|
cmd.user_options]
|
||||||
|
|
|
@ -139,7 +139,8 @@ class TestTest(TempdirManager,
|
||||||
cmd.run()
|
cmd.run()
|
||||||
self.assertEqual(['build has run'], record)
|
self.assertEqual(['build has run'], record)
|
||||||
|
|
||||||
def _test_works_with_2to3(self):
|
@unittest.skip('needs to be written')
|
||||||
|
def test_works_with_2to3(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_checks_requires(self):
|
def test_checks_requires(self):
|
||||||
|
|
|
@ -129,7 +129,7 @@ class UploadTestCase(support.TempdirManager, support.EnvironRestorer,
|
||||||
dist_files = [(command, pyversion, filename)]
|
dist_files = [(command, pyversion, filename)]
|
||||||
docs_path = os.path.join(self.tmp_dir, "build", "docs")
|
docs_path = os.path.join(self.tmp_dir, "build", "docs")
|
||||||
os.makedirs(docs_path)
|
os.makedirs(docs_path)
|
||||||
self.write_file(os.path.join(docs_path, "index.html"), "yellow")
|
self.write_file((docs_path, "index.html"), "yellow")
|
||||||
self.write_file(self.rc, PYPIRC)
|
self.write_file(self.rc, PYPIRC)
|
||||||
|
|
||||||
# let's run it
|
# let's run it
|
||||||
|
|
|
@ -71,9 +71,8 @@ class UploadDocsTestCase(support.TempdirManager,
|
||||||
if sample_dir is None:
|
if sample_dir is None:
|
||||||
sample_dir = self.mkdtemp()
|
sample_dir = self.mkdtemp()
|
||||||
os.mkdir(os.path.join(sample_dir, "docs"))
|
os.mkdir(os.path.join(sample_dir, "docs"))
|
||||||
self.write_file(os.path.join(sample_dir, "docs", "index.html"),
|
self.write_file((sample_dir, "docs", "index.html"), "Ce mortel ennui")
|
||||||
"Ce mortel ennui")
|
self.write_file((sample_dir, "index.html"), "Oh la la")
|
||||||
self.write_file(os.path.join(sample_dir, "index.html"), "Oh la la")
|
|
||||||
return sample_dir
|
return sample_dir
|
||||||
|
|
||||||
def test_zip_dir(self):
|
def test_zip_dir(self):
|
||||||
|
|
|
@ -80,8 +80,7 @@ class CreateTestCase(support.TempdirManager,
|
||||||
os.mkdir(os.path.join(tempdir, dir_))
|
os.mkdir(os.path.join(tempdir, dir_))
|
||||||
|
|
||||||
for file_ in files:
|
for file_ in files:
|
||||||
path = os.path.join(tempdir, file_)
|
self.write_file((tempdir, file_), 'xxx')
|
||||||
self.write_file(path, 'xxx')
|
|
||||||
|
|
||||||
mainprogram._find_files()
|
mainprogram._find_files()
|
||||||
mainprogram.data['packages'].sort()
|
mainprogram.data['packages'].sort()
|
||||||
|
|
|
@ -6,7 +6,7 @@ import textwrap
|
||||||
import packaging.dist
|
import packaging.dist
|
||||||
|
|
||||||
from packaging.dist import Distribution
|
from packaging.dist import Distribution
|
||||||
from packaging.command import set_command
|
from packaging.command import set_command, _COMMANDS
|
||||||
from packaging.command.cmd import Command
|
from packaging.command.cmd import Command
|
||||||
from packaging.errors import PackagingModuleError, PackagingOptionError
|
from packaging.errors import PackagingModuleError, PackagingOptionError
|
||||||
from packaging.tests import captured_stdout
|
from packaging.tests import captured_stdout
|
||||||
|
@ -28,6 +28,9 @@ class test_dist(Command):
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DistributionTestCase(support.TempdirManager,
|
class DistributionTestCase(support.TempdirManager,
|
||||||
support.LoggingCatcher,
|
support.LoggingCatcher,
|
||||||
|
@ -38,12 +41,18 @@ class DistributionTestCase(support.TempdirManager,
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(DistributionTestCase, self).setUp()
|
super(DistributionTestCase, self).setUp()
|
||||||
|
# XXX this is ugly, we should fix the functions to accept args
|
||||||
|
# (defaulting to sys.argv)
|
||||||
self.argv = sys.argv, sys.argv[:]
|
self.argv = sys.argv, sys.argv[:]
|
||||||
del sys.argv[1:]
|
del sys.argv[1:]
|
||||||
|
self._commands = _COMMANDS.copy()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
sys.argv = self.argv[0]
|
sys.argv = self.argv[0]
|
||||||
sys.argv[:] = self.argv[1]
|
sys.argv[:] = self.argv[1]
|
||||||
|
# XXX maybe we need a public API to remove commands
|
||||||
|
_COMMANDS.clear()
|
||||||
|
_COMMANDS.update(self._commands)
|
||||||
super(DistributionTestCase, self).tearDown()
|
super(DistributionTestCase, self).tearDown()
|
||||||
|
|
||||||
@unittest.skip('needs to be updated')
|
@unittest.skip('needs to be updated')
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import sys
|
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
from packaging.tests import unittest, support
|
from packaging.tests import unittest, support
|
||||||
|
|
|
@ -61,8 +61,7 @@ class UninstallTestCase(support.TempdirManager,
|
||||||
kw['pkg'] = pkg
|
kw['pkg'] = pkg
|
||||||
|
|
||||||
pkg_dir = os.path.join(project_dir, pkg)
|
pkg_dir = os.path.join(project_dir, pkg)
|
||||||
os.mkdir(pkg_dir)
|
os.makedirs(os.path.join(pkg_dir, 'sub'))
|
||||||
os.mkdir(os.path.join(pkg_dir, 'sub'))
|
|
||||||
|
|
||||||
self.write_file((project_dir, 'setup.cfg'), SETUP_CFG % kw)
|
self.write_file((project_dir, 'setup.cfg'), SETUP_CFG % kw)
|
||||||
self.write_file((pkg_dir, '__init__.py'), '#')
|
self.write_file((pkg_dir, '__init__.py'), '#')
|
||||||
|
|
|
@ -356,24 +356,20 @@ class UtilTestCase(support.EnvironRestorer,
|
||||||
#
|
#
|
||||||
root = self.mkdtemp()
|
root = self.mkdtemp()
|
||||||
pkg1 = os.path.join(root, 'pkg1')
|
pkg1 = os.path.join(root, 'pkg1')
|
||||||
os.mkdir(pkg1)
|
os.makedirs(os.path.join(pkg1, 'pkg2'))
|
||||||
self.write_file(os.path.join(pkg1, '__init__.py'))
|
os.makedirs(os.path.join(pkg1, 'pkg3', 'pkg6'))
|
||||||
os.mkdir(os.path.join(pkg1, 'pkg2'))
|
os.makedirs(os.path.join(pkg1, 'pkg4', 'pkg8'))
|
||||||
self.write_file(os.path.join(pkg1, 'pkg2', '__init__.py'))
|
os.makedirs(os.path.join(root, 'pkg5'))
|
||||||
os.mkdir(os.path.join(pkg1, 'pkg3'))
|
self.write_file((pkg1, '__init__.py'))
|
||||||
self.write_file(os.path.join(pkg1, 'pkg3', '__init__.py'))
|
self.write_file((pkg1, 'pkg2', '__init__.py'))
|
||||||
os.mkdir(os.path.join(pkg1, 'pkg3', 'pkg6'))
|
self.write_file((pkg1, 'pkg3', '__init__.py'))
|
||||||
self.write_file(os.path.join(pkg1, 'pkg3', 'pkg6', '__init__.py'))
|
self.write_file((pkg1, 'pkg3', 'pkg6', '__init__.py'))
|
||||||
os.mkdir(os.path.join(pkg1, 'pkg4'))
|
self.write_file((pkg1, 'pkg4', 'pkg8', '__init__.py'))
|
||||||
os.mkdir(os.path.join(pkg1, 'pkg4', 'pkg8'))
|
self.write_file((root, 'pkg5', '__init__.py'))
|
||||||
self.write_file(os.path.join(pkg1, 'pkg4', 'pkg8', '__init__.py'))
|
|
||||||
pkg5 = os.path.join(root, 'pkg5')
|
|
||||||
os.mkdir(pkg5)
|
|
||||||
self.write_file(os.path.join(pkg5, '__init__.py'))
|
|
||||||
|
|
||||||
res = find_packages([root], ['pkg1.pkg2'])
|
res = find_packages([root], ['pkg1.pkg2'])
|
||||||
self.assertEqual(set(res), set(['pkg1', 'pkg5', 'pkg1.pkg3',
|
self.assertEqual(sorted(res),
|
||||||
'pkg1.pkg3.pkg6']))
|
['pkg1', 'pkg1.pkg3', 'pkg1.pkg3.pkg6', 'pkg5'])
|
||||||
|
|
||||||
def test_resolve_name(self):
|
def test_resolve_name(self):
|
||||||
# test raw module name
|
# test raw module name
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""Tests for packaging.version."""
|
"""Tests for packaging.version."""
|
||||||
import doctest
|
import doctest
|
||||||
import os
|
|
||||||
|
|
||||||
from packaging.version import NormalizedVersion as V
|
from packaging.version import NormalizedVersion as V
|
||||||
from packaging.version import HugeMajorVersionNumError, IrrationalVersionError
|
from packaging.version import HugeMajorVersionNumError, IrrationalVersionError
|
||||||
|
@ -46,7 +45,6 @@ class VersionTestCase(unittest.TestCase):
|
||||||
def test_from_parts(self):
|
def test_from_parts(self):
|
||||||
|
|
||||||
for v, s in self.versions:
|
for v, s in self.versions:
|
||||||
parts = v.parts
|
|
||||||
v2 = V.from_parts(*v.parts)
|
v2 = V.from_parts(*v.parts)
|
||||||
self.assertEqual(v, v2)
|
self.assertEqual(v, v2)
|
||||||
self.assertEqual(str(v), str(v2))
|
self.assertEqual(str(v), str(v2))
|
||||||
|
@ -192,7 +190,7 @@ class VersionTestCase(unittest.TestCase):
|
||||||
'Hey (>=2.5,<2.7)')
|
'Hey (>=2.5,<2.7)')
|
||||||
|
|
||||||
for predicate in predicates:
|
for predicate in predicates:
|
||||||
v = VersionPredicate(predicate)
|
VersionPredicate(predicate)
|
||||||
|
|
||||||
self.assertTrue(VersionPredicate('Hey (>=2.5,<2.7)').match('2.6'))
|
self.assertTrue(VersionPredicate('Hey (>=2.5,<2.7)').match('2.6'))
|
||||||
self.assertTrue(VersionPredicate('Ho').match('2.6'))
|
self.assertTrue(VersionPredicate('Ho').match('2.6'))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue