2011-05-19 08:07:25 -03:00
|
|
|
"""Tests for packaging.create."""
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import sysconfig
|
|
|
|
from textwrap import dedent
|
2011-11-06 06:32:47 -04:00
|
|
|
from packaging import create
|
2011-05-19 08:07:25 -03:00
|
|
|
from packaging.create import MainProgram, ask_yn, ask, main
|
|
|
|
|
|
|
|
from packaging.tests import support, unittest
|
2011-11-06 06:32:47 -04:00
|
|
|
from packaging.tests.support import Inputs
|
2011-05-19 08:07:25 -03:00
|
|
|
|
|
|
|
|
|
|
|
class CreateTestCase(support.TempdirManager,
|
|
|
|
support.EnvironRestorer,
|
2011-11-06 06:32:47 -04:00
|
|
|
support.LoggingCatcher,
|
2011-05-19 08:07:25 -03:00
|
|
|
unittest.TestCase):
|
|
|
|
|
2011-06-06 15:59:56 -03:00
|
|
|
maxDiff = None
|
2011-05-19 08:07:25 -03:00
|
|
|
restore_environ = ['PLAT']
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(CreateTestCase, self).setUp()
|
|
|
|
self.wdir = self.mkdtemp()
|
|
|
|
os.chdir(self.wdir)
|
|
|
|
# patch sysconfig
|
|
|
|
self._old_get_paths = sysconfig.get_paths
|
|
|
|
sysconfig.get_paths = lambda *args, **kwargs: {
|
|
|
|
'man': sys.prefix + '/share/man',
|
|
|
|
'doc': sys.prefix + '/share/doc/pyxfoil', }
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
sysconfig.get_paths = self._old_get_paths
|
2011-11-06 06:32:47 -04:00
|
|
|
if hasattr(create, 'input'):
|
|
|
|
del create.input
|
2011-05-23 14:07:56 -03:00
|
|
|
super(CreateTestCase, self).tearDown()
|
2011-05-19 08:07:25 -03:00
|
|
|
|
|
|
|
def test_ask_yn(self):
|
2011-11-06 06:32:47 -04:00
|
|
|
create.input = Inputs('y')
|
2011-05-19 08:07:25 -03:00
|
|
|
self.assertEqual('y', ask_yn('is this a test'))
|
|
|
|
|
|
|
|
def test_ask(self):
|
2011-11-06 06:32:47 -04:00
|
|
|
create.input = Inputs('a', 'b')
|
2011-05-19 08:07:25 -03:00
|
|
|
self.assertEqual('a', ask('is this a test'))
|
|
|
|
self.assertEqual('b', ask(str(list(range(0, 70))), default='c',
|
|
|
|
lengthy=True))
|
|
|
|
|
|
|
|
def test_set_multi(self):
|
|
|
|
mainprogram = MainProgram()
|
2011-11-06 06:32:47 -04:00
|
|
|
create.input = Inputs('aaaaa')
|
2011-05-19 08:07:25 -03:00
|
|
|
mainprogram.data['author'] = []
|
|
|
|
mainprogram._set_multi('_set_multi test', 'author')
|
|
|
|
self.assertEqual(['aaaaa'], mainprogram.data['author'])
|
|
|
|
|
|
|
|
def test_find_files(self):
|
|
|
|
# making sure we scan a project dir correctly
|
|
|
|
mainprogram = MainProgram()
|
|
|
|
|
|
|
|
# building the structure
|
|
|
|
tempdir = self.wdir
|
|
|
|
dirs = ['pkg1', 'data', 'pkg2', 'pkg2/sub']
|
2011-06-06 16:55:43 -03:00
|
|
|
files = [
|
|
|
|
'README',
|
|
|
|
'data/data1',
|
|
|
|
'foo.py',
|
|
|
|
'pkg1/__init__.py',
|
|
|
|
'pkg1/bar.py',
|
|
|
|
'pkg2/__init__.py',
|
|
|
|
'pkg2/sub/__init__.py',
|
|
|
|
]
|
2011-05-19 08:07:25 -03:00
|
|
|
|
|
|
|
for dir_ in dirs:
|
|
|
|
os.mkdir(os.path.join(tempdir, dir_))
|
|
|
|
|
|
|
|
for file_ in files:
|
2011-10-19 03:49:20 -03:00
|
|
|
self.write_file((tempdir, file_), 'xxx')
|
2011-05-19 08:07:25 -03:00
|
|
|
|
|
|
|
mainprogram._find_files()
|
|
|
|
mainprogram.data['packages'].sort()
|
|
|
|
|
|
|
|
# do we have what we want?
|
|
|
|
self.assertEqual(mainprogram.data['packages'],
|
|
|
|
['pkg1', 'pkg2', 'pkg2.sub'])
|
|
|
|
self.assertEqual(mainprogram.data['modules'], ['foo'])
|
|
|
|
data_fn = os.path.join('data', 'data1')
|
2011-06-06 16:55:43 -03:00
|
|
|
self.assertEqual(mainprogram.data['extra_files'],
|
|
|
|
['README', data_fn])
|
2011-05-19 08:07:25 -03:00
|
|
|
|
|
|
|
def test_convert_setup_py_to_cfg(self):
|
|
|
|
self.write_file((self.wdir, 'setup.py'),
|
|
|
|
dedent("""
|
2011-05-19 13:45:32 -03:00
|
|
|
# coding: utf-8
|
2011-05-19 08:07:25 -03:00
|
|
|
from distutils.core import setup
|
|
|
|
|
|
|
|
long_description = '''My super Death-scription
|
|
|
|
barbar is now on the public domain,
|
|
|
|
ho, baby !'''
|
|
|
|
|
|
|
|
setup(name='pyxfoil',
|
|
|
|
version='0.2',
|
|
|
|
description='Python bindings for the Xfoil engine',
|
|
|
|
long_description=long_description,
|
|
|
|
maintainer='André Espaze',
|
|
|
|
maintainer_email='andre.espaze@logilab.fr',
|
|
|
|
url='http://www.python-science.org/project/pyxfoil',
|
|
|
|
license='GPLv2',
|
|
|
|
packages=['pyxfoil', 'babar', 'me'],
|
|
|
|
data_files=[
|
|
|
|
('share/doc/pyxfoil', ['README.rst']),
|
|
|
|
('share/man', ['pyxfoil.1']),
|
|
|
|
],
|
|
|
|
py_modules=['my_lib', 'mymodule'],
|
|
|
|
package_dir={
|
|
|
|
'babar': '',
|
|
|
|
'me': 'Martinique/Lamentin',
|
|
|
|
},
|
|
|
|
package_data={
|
|
|
|
'babar': ['Pom', 'Flora', 'Alexander'],
|
|
|
|
'me': ['dady', 'mumy', 'sys', 'bro'],
|
|
|
|
'pyxfoil': ['fengine.so'],
|
|
|
|
},
|
|
|
|
scripts=['my_script', 'bin/run'],
|
|
|
|
)
|
2011-05-19 13:45:32 -03:00
|
|
|
"""), encoding='utf-8')
|
2011-11-06 06:32:47 -04:00
|
|
|
create.input = Inputs('y')
|
2011-05-19 08:07:25 -03:00
|
|
|
main()
|
|
|
|
|
2011-09-18 15:11:48 -03:00
|
|
|
path = os.path.join(self.wdir, 'setup.cfg')
|
|
|
|
with open(path, encoding='utf-8') as fp:
|
2011-06-06 15:59:56 -03:00
|
|
|
contents = fp.read()
|
|
|
|
|
|
|
|
self.assertEqual(contents, dedent("""\
|
|
|
|
[metadata]
|
|
|
|
name = pyxfoil
|
|
|
|
version = 0.2
|
|
|
|
summary = Python bindings for the Xfoil engine
|
|
|
|
download_url = UNKNOWN
|
|
|
|
home_page = http://www.python-science.org/project/pyxfoil
|
|
|
|
maintainer = André Espaze
|
|
|
|
maintainer_email = andre.espaze@logilab.fr
|
|
|
|
description = My super Death-scription
|
|
|
|
|barbar is now on the public domain,
|
|
|
|
|ho, baby !
|
|
|
|
|
|
|
|
[files]
|
|
|
|
packages = pyxfoil
|
|
|
|
babar
|
|
|
|
me
|
|
|
|
modules = my_lib
|
|
|
|
mymodule
|
|
|
|
scripts = my_script
|
|
|
|
bin/run
|
2012-02-05 05:26:16 -04:00
|
|
|
package_data =
|
|
|
|
babar = Pom
|
|
|
|
Flora
|
|
|
|
Alexander
|
|
|
|
me = dady
|
|
|
|
mumy
|
|
|
|
sys
|
|
|
|
bro
|
|
|
|
pyxfoil = fengine.so
|
2011-06-06 15:59:56 -03:00
|
|
|
|
|
|
|
resources =
|
|
|
|
README.rst = {doc}
|
|
|
|
pyxfoil.1 = {man}
|
|
|
|
|
|
|
|
"""))
|
2011-05-19 08:07:25 -03:00
|
|
|
|
|
|
|
def test_convert_setup_py_to_cfg_with_description_in_readme(self):
|
|
|
|
self.write_file((self.wdir, 'setup.py'),
|
|
|
|
dedent("""
|
2011-05-19 13:45:32 -03:00
|
|
|
# coding: utf-8
|
2011-05-19 08:07:25 -03:00
|
|
|
from distutils.core import setup
|
2011-05-19 10:51:27 -03:00
|
|
|
with open('README.txt') as fp:
|
2011-05-19 08:07:25 -03:00
|
|
|
long_description = fp.read()
|
|
|
|
|
|
|
|
setup(name='pyxfoil',
|
|
|
|
version='0.2',
|
|
|
|
description='Python bindings for the Xfoil engine',
|
|
|
|
long_description=long_description,
|
|
|
|
maintainer='André Espaze',
|
|
|
|
maintainer_email='andre.espaze@logilab.fr',
|
|
|
|
url='http://www.python-science.org/project/pyxfoil',
|
|
|
|
license='GPLv2',
|
|
|
|
packages=['pyxfoil'],
|
|
|
|
package_data={'pyxfoil': ['fengine.so', 'babar.so']},
|
|
|
|
data_files=[
|
|
|
|
('share/doc/pyxfoil', ['README.rst']),
|
|
|
|
('share/man', ['pyxfoil.1']),
|
|
|
|
],
|
|
|
|
)
|
2011-05-19 13:45:32 -03:00
|
|
|
"""), encoding='utf-8')
|
2011-05-19 08:07:25 -03:00
|
|
|
self.write_file((self.wdir, 'README.txt'),
|
|
|
|
dedent('''
|
|
|
|
My super Death-scription
|
|
|
|
barbar is now in the public domain,
|
|
|
|
ho, baby!
|
|
|
|
'''))
|
2011-11-06 06:32:47 -04:00
|
|
|
create.input = Inputs('y')
|
2011-05-19 08:07:25 -03:00
|
|
|
main()
|
2011-09-18 15:11:48 -03:00
|
|
|
|
|
|
|
path = os.path.join(self.wdir, 'setup.cfg')
|
|
|
|
with open(path, encoding='utf-8') as fp:
|
2011-06-06 15:59:56 -03:00
|
|
|
contents = fp.read()
|
|
|
|
|
|
|
|
self.assertEqual(contents, dedent("""\
|
|
|
|
[metadata]
|
|
|
|
name = pyxfoil
|
|
|
|
version = 0.2
|
|
|
|
summary = Python bindings for the Xfoil engine
|
|
|
|
download_url = UNKNOWN
|
|
|
|
home_page = http://www.python-science.org/project/pyxfoil
|
|
|
|
maintainer = André Espaze
|
|
|
|
maintainer_email = andre.espaze@logilab.fr
|
|
|
|
description-file = README.txt
|
|
|
|
|
|
|
|
[files]
|
|
|
|
packages = pyxfoil
|
2012-02-05 05:26:16 -04:00
|
|
|
package_data =
|
|
|
|
pyxfoil = fengine.so
|
|
|
|
babar.so
|
2011-06-06 15:59:56 -03:00
|
|
|
|
|
|
|
resources =
|
|
|
|
README.rst = {doc}
|
|
|
|
pyxfoil.1 = {man}
|
|
|
|
|
|
|
|
"""))
|
2011-05-19 08:07:25 -03:00
|
|
|
|
|
|
|
|
|
|
|
def test_suite():
|
|
|
|
return unittest.makeSuite(CreateTestCase)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(defaultTest='test_suite')
|