| 1 | n/a | """Tests for packaging.config.""" |
|---|
| 2 | n/a | import os |
|---|
| 3 | n/a | import sys |
|---|
| 4 | n/a | |
|---|
| 5 | n/a | from packaging import command |
|---|
| 6 | n/a | from packaging.dist import Distribution |
|---|
| 7 | n/a | from packaging.errors import PackagingFileError, PackagingOptionError |
|---|
| 8 | n/a | from packaging.compiler import new_compiler, _COMPILERS |
|---|
| 9 | n/a | from packaging.command.sdist import sdist |
|---|
| 10 | n/a | |
|---|
| 11 | n/a | from packaging.tests import unittest, support |
|---|
| 12 | n/a | from packaging.tests.support import requires_zlib |
|---|
| 13 | n/a | |
|---|
| 14 | n/a | |
|---|
| 15 | n/a | SETUP_CFG = """ |
|---|
| 16 | n/a | [metadata] |
|---|
| 17 | n/a | name = RestingParrot |
|---|
| 18 | n/a | version = 0.6.4 |
|---|
| 19 | n/a | author = Carl Meyer |
|---|
| 20 | n/a | author_email = carl@oddbird.net |
|---|
| 21 | n/a | maintainer = Ãric Araujo |
|---|
| 22 | n/a | maintainer_email = merwok@netwok.org |
|---|
| 23 | n/a | summary = A sample project demonstrating packaging |
|---|
| 24 | n/a | description-file = %(description-file)s |
|---|
| 25 | n/a | keywords = packaging, sample project |
|---|
| 26 | n/a | |
|---|
| 27 | n/a | classifier = |
|---|
| 28 | n/a | Development Status :: 4 - Beta |
|---|
| 29 | n/a | Environment :: Console (Text Based) |
|---|
| 30 | n/a | Environment :: X11 Applications :: GTK; python_version < '3' |
|---|
| 31 | n/a | License :: OSI Approved :: MIT License |
|---|
| 32 | n/a | Programming Language :: Python |
|---|
| 33 | n/a | Programming Language :: Python :: 2 |
|---|
| 34 | n/a | Programming Language :: Python :: 3 |
|---|
| 35 | n/a | |
|---|
| 36 | n/a | requires_python = >=2.4, <3.2 |
|---|
| 37 | n/a | |
|---|
| 38 | n/a | requires_dist = |
|---|
| 39 | n/a | PetShoppe |
|---|
| 40 | n/a | MichaelPalin (> 1.1) |
|---|
| 41 | n/a | pywin32; sys.platform == 'win32' |
|---|
| 42 | n/a | pysqlite2; python_version < '2.5' |
|---|
| 43 | n/a | inotify (0.0.1); sys.platform == 'linux2' |
|---|
| 44 | n/a | |
|---|
| 45 | n/a | requires_external = libxml2 |
|---|
| 46 | n/a | |
|---|
| 47 | n/a | provides_dist = packaging-sample-project (0.2) |
|---|
| 48 | n/a | unittest2-sample-project |
|---|
| 49 | n/a | |
|---|
| 50 | n/a | project_url = |
|---|
| 51 | n/a | Main repository, http://bitbucket.org/carljm/sample-distutils2-project |
|---|
| 52 | n/a | Fork in progress, http://bitbucket.org/Merwok/sample-distutils2-project |
|---|
| 53 | n/a | |
|---|
| 54 | n/a | [files] |
|---|
| 55 | n/a | packages_root = src |
|---|
| 56 | n/a | |
|---|
| 57 | n/a | packages = one |
|---|
| 58 | n/a | two |
|---|
| 59 | n/a | three |
|---|
| 60 | n/a | |
|---|
| 61 | n/a | modules = haven |
|---|
| 62 | n/a | |
|---|
| 63 | n/a | scripts = |
|---|
| 64 | n/a | script1.py |
|---|
| 65 | n/a | scripts/find-coconuts |
|---|
| 66 | n/a | bin/taunt |
|---|
| 67 | n/a | |
|---|
| 68 | n/a | package_data = |
|---|
| 69 | n/a | cheese = data/templates/* doc/* |
|---|
| 70 | n/a | doc/images/*.png |
|---|
| 71 | n/a | |
|---|
| 72 | n/a | |
|---|
| 73 | n/a | extra_files = %(extra-files)s |
|---|
| 74 | n/a | |
|---|
| 75 | n/a | # Replaces MANIFEST.in |
|---|
| 76 | n/a | # FIXME no, it's extra_files |
|---|
| 77 | n/a | # (but sdist_extra is a better name, should use it) |
|---|
| 78 | n/a | sdist_extra = |
|---|
| 79 | n/a | include THANKS HACKING |
|---|
| 80 | n/a | recursive-include examples *.txt *.py |
|---|
| 81 | n/a | prune examples/sample?/build |
|---|
| 82 | n/a | |
|---|
| 83 | n/a | resources= |
|---|
| 84 | n/a | bm/ {b1,b2}.gif = {icon} |
|---|
| 85 | n/a | Cf*/ *.CFG = {config}/baBar/ |
|---|
| 86 | n/a | init_script = {script}/JunGle/ |
|---|
| 87 | n/a | |
|---|
| 88 | n/a | [global] |
|---|
| 89 | n/a | commands = |
|---|
| 90 | n/a | packaging.tests.test_config.FooBarBazTest |
|---|
| 91 | n/a | |
|---|
| 92 | n/a | compilers = |
|---|
| 93 | n/a | packaging.tests.test_config.DCompiler |
|---|
| 94 | n/a | |
|---|
| 95 | n/a | setup_hooks = %(setup-hooks)s |
|---|
| 96 | n/a | |
|---|
| 97 | n/a | |
|---|
| 98 | n/a | |
|---|
| 99 | n/a | [install_dist] |
|---|
| 100 | n/a | sub_commands = foo |
|---|
| 101 | n/a | """ |
|---|
| 102 | n/a | |
|---|
| 103 | n/a | SETUP_CFG_PKGDATA_BUGGY_1 = """ |
|---|
| 104 | n/a | [files] |
|---|
| 105 | n/a | package_data = foo.* |
|---|
| 106 | n/a | """ |
|---|
| 107 | n/a | |
|---|
| 108 | n/a | SETUP_CFG_PKGDATA_BUGGY_2 = """ |
|---|
| 109 | n/a | [files] |
|---|
| 110 | n/a | package_data = |
|---|
| 111 | n/a | foo.* |
|---|
| 112 | n/a | """ |
|---|
| 113 | n/a | |
|---|
| 114 | n/a | # Can not be merged with SETUP_CFG else install_dist |
|---|
| 115 | n/a | # command will fail when trying to compile C sources |
|---|
| 116 | n/a | # TODO use a DummyCommand to mock build_ext |
|---|
| 117 | n/a | EXT_SETUP_CFG = """ |
|---|
| 118 | n/a | [files] |
|---|
| 119 | n/a | packages = one |
|---|
| 120 | n/a | two |
|---|
| 121 | n/a | parent.undeclared |
|---|
| 122 | n/a | |
|---|
| 123 | n/a | [extension:one.speed_coconuts] |
|---|
| 124 | n/a | sources = c_src/speed_coconuts.c |
|---|
| 125 | n/a | extra_link_args = "`gcc -print-file-name=libgcc.a`" -shared |
|---|
| 126 | n/a | define_macros = HAVE_CAIRO HAVE_GTK2 |
|---|
| 127 | n/a | libraries = gecodeint gecodekernel -- sys.platform != 'win32' |
|---|
| 128 | n/a | GecodeInt GecodeKernel -- sys.platform == 'win32' |
|---|
| 129 | n/a | |
|---|
| 130 | n/a | [extension: two.fast_taunt] |
|---|
| 131 | n/a | sources = cxx_src/utils_taunt.cxx |
|---|
| 132 | n/a | cxx_src/python_module.cxx |
|---|
| 133 | n/a | include_dirs = /usr/include/gecode |
|---|
| 134 | n/a | /usr/include/blitz |
|---|
| 135 | n/a | extra_compile_args = -fPIC -O2 |
|---|
| 136 | n/a | -DGECODE_VERSION=$(./gecode_version) -- sys.platform != 'win32' |
|---|
| 137 | n/a | /DGECODE_VERSION=win32 -- sys.platform == 'win32' |
|---|
| 138 | n/a | language = cxx |
|---|
| 139 | n/a | |
|---|
| 140 | n/a | # corner case: if the parent package of an extension is declared but |
|---|
| 141 | n/a | # not its grandparent, it's legal |
|---|
| 142 | n/a | [extension: parent.undeclared._speed] |
|---|
| 143 | n/a | sources = parent/undeclared/_speed.c |
|---|
| 144 | n/a | """ |
|---|
| 145 | n/a | |
|---|
| 146 | n/a | EXT_SETUP_CFG_BUGGY_1 = """ |
|---|
| 147 | n/a | [extension: realname] |
|---|
| 148 | n/a | name = crash_here |
|---|
| 149 | n/a | """ |
|---|
| 150 | n/a | |
|---|
| 151 | n/a | EXT_SETUP_CFG_BUGGY_2 = """ |
|---|
| 152 | n/a | [files] |
|---|
| 153 | n/a | packages = ham |
|---|
| 154 | n/a | |
|---|
| 155 | n/a | [extension: spam.eggs] |
|---|
| 156 | n/a | """ |
|---|
| 157 | n/a | |
|---|
| 158 | n/a | EXT_SETUP_CFG_BUGGY_3 = """ |
|---|
| 159 | n/a | [files] |
|---|
| 160 | n/a | packages = ok |
|---|
| 161 | n/a | ok.works |
|---|
| 162 | n/a | |
|---|
| 163 | n/a | [extension: ok.works.breaks._ext] |
|---|
| 164 | n/a | """ |
|---|
| 165 | n/a | |
|---|
| 166 | n/a | HOOKS_MODULE = """ |
|---|
| 167 | n/a | import logging |
|---|
| 168 | n/a | |
|---|
| 169 | n/a | logger = logging.getLogger('packaging') |
|---|
| 170 | n/a | |
|---|
| 171 | n/a | def logging_hook(config): |
|---|
| 172 | n/a | logger.warning('logging_hook called') |
|---|
| 173 | n/a | """ |
|---|
| 174 | n/a | |
|---|
| 175 | n/a | |
|---|
| 176 | n/a | class DCompiler: |
|---|
| 177 | n/a | name = 'd' |
|---|
| 178 | n/a | description = 'D Compiler' |
|---|
| 179 | n/a | |
|---|
| 180 | n/a | def __init__(self, *args): |
|---|
| 181 | n/a | pass |
|---|
| 182 | n/a | |
|---|
| 183 | n/a | |
|---|
| 184 | n/a | def version_hook(config): |
|---|
| 185 | n/a | config['metadata']['version'] += '.dev1' |
|---|
| 186 | n/a | |
|---|
| 187 | n/a | |
|---|
| 188 | n/a | def first_hook(config): |
|---|
| 189 | n/a | config['files']['modules'] += '\n first' |
|---|
| 190 | n/a | |
|---|
| 191 | n/a | |
|---|
| 192 | n/a | def third_hook(config): |
|---|
| 193 | n/a | config['files']['modules'] += '\n third' |
|---|
| 194 | n/a | |
|---|
| 195 | n/a | |
|---|
| 196 | n/a | class FooBarBazTest: |
|---|
| 197 | n/a | |
|---|
| 198 | n/a | def __init__(self, dist): |
|---|
| 199 | n/a | self.distribution = dist |
|---|
| 200 | n/a | self._record = [] |
|---|
| 201 | n/a | |
|---|
| 202 | n/a | @classmethod |
|---|
| 203 | n/a | def get_command_name(cls): |
|---|
| 204 | n/a | return 'foo' |
|---|
| 205 | n/a | |
|---|
| 206 | n/a | def run(self): |
|---|
| 207 | n/a | self._record.append('foo has run') |
|---|
| 208 | n/a | |
|---|
| 209 | n/a | def nothing(self): |
|---|
| 210 | n/a | pass |
|---|
| 211 | n/a | |
|---|
| 212 | n/a | def get_source_files(self): |
|---|
| 213 | n/a | return [] |
|---|
| 214 | n/a | |
|---|
| 215 | n/a | ensure_finalized = finalize_options = initialize_options = nothing |
|---|
| 216 | n/a | |
|---|
| 217 | n/a | |
|---|
| 218 | n/a | class ConfigTestCase(support.TempdirManager, |
|---|
| 219 | n/a | support.EnvironRestorer, |
|---|
| 220 | n/a | support.LoggingCatcher, |
|---|
| 221 | n/a | unittest.TestCase): |
|---|
| 222 | n/a | |
|---|
| 223 | n/a | restore_environ = ['PLAT'] |
|---|
| 224 | n/a | |
|---|
| 225 | n/a | def setUp(self): |
|---|
| 226 | n/a | super(ConfigTestCase, self).setUp() |
|---|
| 227 | n/a | tempdir = self.mkdtemp() |
|---|
| 228 | n/a | self.working_dir = os.getcwd() |
|---|
| 229 | n/a | os.chdir(tempdir) |
|---|
| 230 | n/a | self.tempdir = tempdir |
|---|
| 231 | n/a | |
|---|
| 232 | n/a | def write_setup(self, kwargs=None): |
|---|
| 233 | n/a | opts = {'description-file': 'README', 'extra-files': '', |
|---|
| 234 | n/a | 'setup-hooks': 'packaging.tests.test_config.version_hook'} |
|---|
| 235 | n/a | if kwargs: |
|---|
| 236 | n/a | opts.update(kwargs) |
|---|
| 237 | n/a | self.write_file('setup.cfg', SETUP_CFG % opts, encoding='utf-8') |
|---|
| 238 | n/a | |
|---|
| 239 | n/a | def get_dist(self): |
|---|
| 240 | n/a | dist = Distribution() |
|---|
| 241 | n/a | dist.parse_config_files() |
|---|
| 242 | n/a | return dist |
|---|
| 243 | n/a | |
|---|
| 244 | n/a | def test_config(self): |
|---|
| 245 | n/a | self.write_setup() |
|---|
| 246 | n/a | self.write_file('README', 'yeah') |
|---|
| 247 | n/a | os.mkdir('bm') |
|---|
| 248 | n/a | self.write_file(('bm', 'b1.gif'), '') |
|---|
| 249 | n/a | self.write_file(('bm', 'b2.gif'), '') |
|---|
| 250 | n/a | os.mkdir('Cfg') |
|---|
| 251 | n/a | self.write_file(('Cfg', 'data.CFG'), '') |
|---|
| 252 | n/a | self.write_file('init_script', '') |
|---|
| 253 | n/a | |
|---|
| 254 | n/a | # try to load the metadata now |
|---|
| 255 | n/a | dist = self.get_dist() |
|---|
| 256 | n/a | |
|---|
| 257 | n/a | # check what was done |
|---|
| 258 | n/a | self.assertEqual(dist.metadata['Author'], 'Carl Meyer') |
|---|
| 259 | n/a | self.assertEqual(dist.metadata['Author-Email'], 'carl@oddbird.net') |
|---|
| 260 | n/a | |
|---|
| 261 | n/a | # the hook adds .dev1 |
|---|
| 262 | n/a | self.assertEqual(dist.metadata['Version'], '0.6.4.dev1') |
|---|
| 263 | n/a | |
|---|
| 264 | n/a | wanted = [ |
|---|
| 265 | n/a | 'Development Status :: 4 - Beta', |
|---|
| 266 | n/a | 'Environment :: Console (Text Based)', |
|---|
| 267 | n/a | "Environment :: X11 Applications :: GTK; python_version < '3'", |
|---|
| 268 | n/a | 'License :: OSI Approved :: MIT License', |
|---|
| 269 | n/a | 'Programming Language :: Python', |
|---|
| 270 | n/a | 'Programming Language :: Python :: 2', |
|---|
| 271 | n/a | 'Programming Language :: Python :: 3'] |
|---|
| 272 | n/a | self.assertEqual(dist.metadata['Classifier'], wanted) |
|---|
| 273 | n/a | |
|---|
| 274 | n/a | wanted = ['packaging', 'sample project'] |
|---|
| 275 | n/a | self.assertEqual(dist.metadata['Keywords'], wanted) |
|---|
| 276 | n/a | |
|---|
| 277 | n/a | self.assertEqual(dist.metadata['Requires-Python'], '>=2.4, <3.2') |
|---|
| 278 | n/a | |
|---|
| 279 | n/a | wanted = ['PetShoppe', |
|---|
| 280 | n/a | 'MichaelPalin (> 1.1)', |
|---|
| 281 | n/a | "pywin32; sys.platform == 'win32'", |
|---|
| 282 | n/a | "pysqlite2; python_version < '2.5'", |
|---|
| 283 | n/a | "inotify (0.0.1); sys.platform == 'linux2'"] |
|---|
| 284 | n/a | |
|---|
| 285 | n/a | self.assertEqual(dist.metadata['Requires-Dist'], wanted) |
|---|
| 286 | n/a | urls = [('Main repository', |
|---|
| 287 | n/a | 'http://bitbucket.org/carljm/sample-distutils2-project'), |
|---|
| 288 | n/a | ('Fork in progress', |
|---|
| 289 | n/a | 'http://bitbucket.org/Merwok/sample-distutils2-project')] |
|---|
| 290 | n/a | self.assertEqual(dist.metadata['Project-Url'], urls) |
|---|
| 291 | n/a | |
|---|
| 292 | n/a | self.assertEqual(dist.packages, ['one', 'two', 'three']) |
|---|
| 293 | n/a | self.assertEqual(dist.py_modules, ['haven']) |
|---|
| 294 | n/a | self.assertEqual(dist.package_data, |
|---|
| 295 | n/a | {'cheese': ['data/templates/*', 'doc/*', |
|---|
| 296 | n/a | 'doc/images/*.png']}) |
|---|
| 297 | n/a | self.assertEqual(dist.data_files, |
|---|
| 298 | n/a | {'bm/b1.gif': '{icon}/b1.gif', |
|---|
| 299 | n/a | 'bm/b2.gif': '{icon}/b2.gif', |
|---|
| 300 | n/a | 'Cfg/data.CFG': '{config}/baBar/data.CFG', |
|---|
| 301 | n/a | 'init_script': '{script}/JunGle/init_script'}) |
|---|
| 302 | n/a | |
|---|
| 303 | n/a | self.assertEqual(dist.package_dir, 'src') |
|---|
| 304 | n/a | |
|---|
| 305 | n/a | # Make sure we get the foo command loaded. We use a string comparison |
|---|
| 306 | n/a | # instead of assertIsInstance because the class is not the same when |
|---|
| 307 | n/a | # this test is run directly: foo is packaging.tests.test_config.Foo |
|---|
| 308 | n/a | # because get_command_class uses the full name, but a bare "Foo" in |
|---|
| 309 | n/a | # this file would be __main__.Foo when run as "python test_config.py". |
|---|
| 310 | n/a | # The name FooBarBazTest should be unique enough to prevent |
|---|
| 311 | n/a | # collisions. |
|---|
| 312 | n/a | self.assertEqual(dist.get_command_obj('foo').__class__.__name__, |
|---|
| 313 | n/a | 'FooBarBazTest') |
|---|
| 314 | n/a | |
|---|
| 315 | n/a | # did the README got loaded ? |
|---|
| 316 | n/a | self.assertEqual(dist.metadata['description'], 'yeah') |
|---|
| 317 | n/a | |
|---|
| 318 | n/a | # do we have the D Compiler enabled ? |
|---|
| 319 | n/a | self.assertIn('d', _COMPILERS) |
|---|
| 320 | n/a | d = new_compiler(compiler='d') |
|---|
| 321 | n/a | self.assertEqual(d.description, 'D Compiler') |
|---|
| 322 | n/a | |
|---|
| 323 | n/a | # check error reporting for invalid package_data value |
|---|
| 324 | n/a | self.write_file('setup.cfg', SETUP_CFG_PKGDATA_BUGGY_1) |
|---|
| 325 | n/a | self.assertRaises(PackagingOptionError, self.get_dist) |
|---|
| 326 | n/a | |
|---|
| 327 | n/a | self.write_file('setup.cfg', SETUP_CFG_PKGDATA_BUGGY_2) |
|---|
| 328 | n/a | self.assertRaises(PackagingOptionError, self.get_dist) |
|---|
| 329 | n/a | |
|---|
| 330 | n/a | def test_multiple_description_file(self): |
|---|
| 331 | n/a | self.write_setup({'description-file': 'README CHANGES'}) |
|---|
| 332 | n/a | self.write_file('README', 'yeah') |
|---|
| 333 | n/a | self.write_file('CHANGES', 'changelog2') |
|---|
| 334 | n/a | dist = self.get_dist() |
|---|
| 335 | n/a | self.assertEqual(dist.metadata.requires_files, ['README', 'CHANGES']) |
|---|
| 336 | n/a | |
|---|
| 337 | n/a | def test_multiline_description_file(self): |
|---|
| 338 | n/a | self.write_setup({'description-file': 'README\n CHANGES'}) |
|---|
| 339 | n/a | self.write_file('README', 'yeah') |
|---|
| 340 | n/a | self.write_file('CHANGES', 'changelog') |
|---|
| 341 | n/a | dist = self.get_dist() |
|---|
| 342 | n/a | self.assertEqual(dist.metadata['description'], 'yeah\nchangelog') |
|---|
| 343 | n/a | self.assertEqual(dist.metadata.requires_files, ['README', 'CHANGES']) |
|---|
| 344 | n/a | |
|---|
| 345 | n/a | def test_parse_extensions_in_config(self): |
|---|
| 346 | n/a | self.write_file('setup.cfg', EXT_SETUP_CFG) |
|---|
| 347 | n/a | dist = self.get_dist() |
|---|
| 348 | n/a | |
|---|
| 349 | n/a | ext_modules = dict((mod.name, mod) for mod in dist.ext_modules) |
|---|
| 350 | n/a | self.assertEqual(len(ext_modules), 3) |
|---|
| 351 | n/a | ext = ext_modules.get('one.speed_coconuts') |
|---|
| 352 | n/a | self.assertEqual(ext.sources, ['c_src/speed_coconuts.c']) |
|---|
| 353 | n/a | self.assertEqual(ext.define_macros, ['HAVE_CAIRO', 'HAVE_GTK2']) |
|---|
| 354 | n/a | libs = ['gecodeint', 'gecodekernel'] |
|---|
| 355 | n/a | if sys.platform == 'win32': |
|---|
| 356 | n/a | libs = ['GecodeInt', 'GecodeKernel'] |
|---|
| 357 | n/a | self.assertEqual(ext.libraries, libs) |
|---|
| 358 | n/a | self.assertEqual(ext.extra_link_args, |
|---|
| 359 | n/a | ['`gcc -print-file-name=libgcc.a`', '-shared']) |
|---|
| 360 | n/a | |
|---|
| 361 | n/a | ext = ext_modules.get('two.fast_taunt') |
|---|
| 362 | n/a | self.assertEqual(ext.sources, |
|---|
| 363 | n/a | ['cxx_src/utils_taunt.cxx', 'cxx_src/python_module.cxx']) |
|---|
| 364 | n/a | self.assertEqual(ext.include_dirs, |
|---|
| 365 | n/a | ['/usr/include/gecode', '/usr/include/blitz']) |
|---|
| 366 | n/a | cargs = ['-fPIC', '-O2'] |
|---|
| 367 | n/a | if sys.platform == 'win32': |
|---|
| 368 | n/a | cargs.append("/DGECODE_VERSION=win32") |
|---|
| 369 | n/a | else: |
|---|
| 370 | n/a | cargs.append('-DGECODE_VERSION=$(./gecode_version)') |
|---|
| 371 | n/a | self.assertEqual(ext.extra_compile_args, cargs) |
|---|
| 372 | n/a | self.assertEqual(ext.language, 'cxx') |
|---|
| 373 | n/a | |
|---|
| 374 | n/a | self.write_file('setup.cfg', EXT_SETUP_CFG_BUGGY_1) |
|---|
| 375 | n/a | self.assertRaises(PackagingOptionError, self.get_dist) |
|---|
| 376 | n/a | |
|---|
| 377 | n/a | self.write_file('setup.cfg', EXT_SETUP_CFG_BUGGY_2) |
|---|
| 378 | n/a | self.assertRaises(PackagingOptionError, self.get_dist) |
|---|
| 379 | n/a | |
|---|
| 380 | n/a | self.write_file('setup.cfg', EXT_SETUP_CFG_BUGGY_3) |
|---|
| 381 | n/a | self.assertRaises(PackagingOptionError, self.get_dist) |
|---|
| 382 | n/a | |
|---|
| 383 | n/a | def test_project_setup_hook_works(self): |
|---|
| 384 | n/a | # Bug #11637: ensure the project directory is on sys.path to allow |
|---|
| 385 | n/a | # project-specific hooks |
|---|
| 386 | n/a | self.write_setup({'setup-hooks': 'hooks.logging_hook'}) |
|---|
| 387 | n/a | self.write_file('README', 'yeah') |
|---|
| 388 | n/a | self.write_file('hooks.py', HOOKS_MODULE) |
|---|
| 389 | n/a | self.get_dist() |
|---|
| 390 | n/a | self.assertEqual(['logging_hook called'], self.get_logs()) |
|---|
| 391 | n/a | self.assertIn('hooks', sys.modules) |
|---|
| 392 | n/a | |
|---|
| 393 | n/a | def test_missing_setup_hook_warns(self): |
|---|
| 394 | n/a | self.write_setup({'setup-hooks': 'does._not.exist'}) |
|---|
| 395 | n/a | self.write_file('README', 'yeah') |
|---|
| 396 | n/a | self.get_dist() |
|---|
| 397 | n/a | logs = self.get_logs() |
|---|
| 398 | n/a | self.assertEqual(1, len(logs)) |
|---|
| 399 | n/a | self.assertIn('cannot find setup hook', logs[0]) |
|---|
| 400 | n/a | |
|---|
| 401 | n/a | def test_multiple_setup_hooks(self): |
|---|
| 402 | n/a | self.write_setup({ |
|---|
| 403 | n/a | 'setup-hooks': '\n packaging.tests.test_config.first_hook' |
|---|
| 404 | n/a | '\n packaging.tests.test_config.missing_hook' |
|---|
| 405 | n/a | '\n packaging.tests.test_config.third_hook', |
|---|
| 406 | n/a | }) |
|---|
| 407 | n/a | self.write_file('README', 'yeah') |
|---|
| 408 | n/a | dist = self.get_dist() |
|---|
| 409 | n/a | |
|---|
| 410 | n/a | self.assertEqual(['haven', 'first', 'third'], dist.py_modules) |
|---|
| 411 | n/a | logs = self.get_logs() |
|---|
| 412 | n/a | self.assertEqual(1, len(logs)) |
|---|
| 413 | n/a | self.assertIn('cannot find setup hook', logs[0]) |
|---|
| 414 | n/a | |
|---|
| 415 | n/a | def test_metadata_requires_description_files_missing(self): |
|---|
| 416 | n/a | self.write_setup({'description-file': 'README README2'}) |
|---|
| 417 | n/a | self.write_file('README', 'yeah') |
|---|
| 418 | n/a | self.write_file('README2', 'yeah') |
|---|
| 419 | n/a | os.mkdir('src') |
|---|
| 420 | n/a | self.write_file(('src', 'haven.py'), '#') |
|---|
| 421 | n/a | self.write_file('script1.py', '#') |
|---|
| 422 | n/a | os.mkdir('scripts') |
|---|
| 423 | n/a | self.write_file(('scripts', 'find-coconuts'), '#') |
|---|
| 424 | n/a | os.mkdir('bin') |
|---|
| 425 | n/a | self.write_file(('bin', 'taunt'), '#') |
|---|
| 426 | n/a | |
|---|
| 427 | n/a | for pkg in ('one', 'two', 'three'): |
|---|
| 428 | n/a | pkg = os.path.join('src', pkg) |
|---|
| 429 | n/a | os.mkdir(pkg) |
|---|
| 430 | n/a | self.write_file((pkg, '__init__.py'), '#') |
|---|
| 431 | n/a | |
|---|
| 432 | n/a | dist = self.get_dist() |
|---|
| 433 | n/a | cmd = sdist(dist) |
|---|
| 434 | n/a | cmd.finalize_options() |
|---|
| 435 | n/a | cmd.get_file_list() |
|---|
| 436 | n/a | self.assertRaises(PackagingFileError, cmd.make_distribution) |
|---|
| 437 | n/a | |
|---|
| 438 | n/a | @requires_zlib |
|---|
| 439 | n/a | def test_metadata_requires_description_files(self): |
|---|
| 440 | n/a | # Create the following file structure: |
|---|
| 441 | n/a | # README |
|---|
| 442 | n/a | # README2 |
|---|
| 443 | n/a | # script1.py |
|---|
| 444 | n/a | # scripts/ |
|---|
| 445 | n/a | # find-coconuts |
|---|
| 446 | n/a | # bin/ |
|---|
| 447 | n/a | # taunt |
|---|
| 448 | n/a | # src/ |
|---|
| 449 | n/a | # haven.py |
|---|
| 450 | n/a | # one/__init__.py |
|---|
| 451 | n/a | # two/__init__.py |
|---|
| 452 | n/a | # three/__init__.py |
|---|
| 453 | n/a | |
|---|
| 454 | n/a | self.write_setup({'description-file': 'README\n README2', |
|---|
| 455 | n/a | 'extra-files': '\n README3'}) |
|---|
| 456 | n/a | self.write_file('README', 'yeah 1') |
|---|
| 457 | n/a | self.write_file('README2', 'yeah 2') |
|---|
| 458 | n/a | self.write_file('README3', 'yeah 3') |
|---|
| 459 | n/a | os.mkdir('src') |
|---|
| 460 | n/a | self.write_file(('src', 'haven.py'), '#') |
|---|
| 461 | n/a | self.write_file('script1.py', '#') |
|---|
| 462 | n/a | os.mkdir('scripts') |
|---|
| 463 | n/a | self.write_file(('scripts', 'find-coconuts'), '#') |
|---|
| 464 | n/a | os.mkdir('bin') |
|---|
| 465 | n/a | self.write_file(('bin', 'taunt'), '#') |
|---|
| 466 | n/a | |
|---|
| 467 | n/a | for pkg in ('one', 'two', 'three'): |
|---|
| 468 | n/a | pkg = os.path.join('src', pkg) |
|---|
| 469 | n/a | os.mkdir(pkg) |
|---|
| 470 | n/a | self.write_file((pkg, '__init__.py'), '#') |
|---|
| 471 | n/a | |
|---|
| 472 | n/a | dist = self.get_dist() |
|---|
| 473 | n/a | self.assertIn('yeah 1\nyeah 2', dist.metadata['description']) |
|---|
| 474 | n/a | |
|---|
| 475 | n/a | cmd = sdist(dist) |
|---|
| 476 | n/a | cmd.finalize_options() |
|---|
| 477 | n/a | cmd.get_file_list() |
|---|
| 478 | n/a | self.assertRaises(PackagingFileError, cmd.make_distribution) |
|---|
| 479 | n/a | |
|---|
| 480 | n/a | self.write_setup({'description-file': 'README\n README2', |
|---|
| 481 | n/a | 'extra-files': '\n README2\n README'}) |
|---|
| 482 | n/a | dist = self.get_dist() |
|---|
| 483 | n/a | cmd = sdist(dist) |
|---|
| 484 | n/a | cmd.finalize_options() |
|---|
| 485 | n/a | cmd.get_file_list() |
|---|
| 486 | n/a | cmd.make_distribution() |
|---|
| 487 | n/a | with open('MANIFEST') as fp: |
|---|
| 488 | n/a | self.assertIn('README\nREADME2\n', fp.read()) |
|---|
| 489 | n/a | |
|---|
| 490 | n/a | def test_sub_commands(self): |
|---|
| 491 | n/a | self.write_setup() |
|---|
| 492 | n/a | self.write_file('README', 'yeah') |
|---|
| 493 | n/a | os.mkdir('src') |
|---|
| 494 | n/a | self.write_file(('src', 'haven.py'), '#') |
|---|
| 495 | n/a | self.write_file('script1.py', '#') |
|---|
| 496 | n/a | os.mkdir('scripts') |
|---|
| 497 | n/a | self.write_file(('scripts', 'find-coconuts'), '#') |
|---|
| 498 | n/a | os.mkdir('bin') |
|---|
| 499 | n/a | self.write_file(('bin', 'taunt'), '#') |
|---|
| 500 | n/a | |
|---|
| 501 | n/a | for pkg in ('one', 'two', 'three'): |
|---|
| 502 | n/a | pkg = os.path.join('src', pkg) |
|---|
| 503 | n/a | os.mkdir(pkg) |
|---|
| 504 | n/a | self.write_file((pkg, '__init__.py'), '#') |
|---|
| 505 | n/a | |
|---|
| 506 | n/a | # try to run the install command to see if foo is called |
|---|
| 507 | n/a | self.addCleanup(command._COMMANDS.__delitem__, 'foo') |
|---|
| 508 | n/a | dist = self.get_dist() |
|---|
| 509 | n/a | dist.run_command('install_dist') |
|---|
| 510 | n/a | cmd = dist.get_command_obj('foo') |
|---|
| 511 | n/a | self.assertEqual(cmd.__class__.__name__, 'FooBarBazTest') |
|---|
| 512 | n/a | self.assertEqual(cmd._record, ['foo has run']) |
|---|
| 513 | n/a | |
|---|
| 514 | n/a | |
|---|
| 515 | n/a | def test_suite(): |
|---|
| 516 | n/a | return unittest.makeSuite(ConfigTestCase) |
|---|
| 517 | n/a | |
|---|
| 518 | n/a | if __name__ == '__main__': |
|---|
| 519 | n/a | unittest.main(defaultTest='test_suite') |
|---|