def test_wheel_prerelease(): module_path = fixtures_dir / 'prerelease' WheelBuilder.make(Poetry.create(str(module_path)), NullVenv(), NullIO()) whl = module_path / 'dist' / 'prerelease-0.1b1-py2.py3-none-any.whl' assert whl.exists()
def test_complete(): module_path = fixtures_dir / 'complete' builder = CompleteBuilder(Poetry.create(module_path), NullVenv(True), NullIO()) builder.build() whl = module_path / 'dist' / 'my_package-1.2.3-py3-none-any.whl' assert whl.exists zip = zipfile.ZipFile(whl) try: entry_points = zip.read('my_package-1.2.3.dist-info/entry_points.txt') assert entry_points.decode() == """\ [console_scripts] my-2nd-script=my_package:main2 my-script=my_package:main """ wheel_data = zip.read('my_package-1.2.3.dist-info/WHEEL').decode() assert wheel_data == f"""\ Wheel-Version: 1.0 Generator: poetry {__version__} Root-Is-Purelib: true Tag: py3-none-any """ finally: zip.close()
def test_wheel_package(): module_path = fixtures_dir / 'complete' WheelBuilder.make(Poetry.create(str(module_path)), NullVenv(), NullIO()) whl = module_path / 'dist' / 'my_package-1.2.3-py3-none-any.whl' assert whl.exists()
def test_make_setup(): poetry = Poetry.create(project('complete')) builder = SdistBuilder(poetry, NullVenv(), NullIO()) setup = builder.build_setup() setup_ast = ast.parse(setup) setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)] ns = {} exec(compile(setup_ast, filename="setup.py", mode="exec"), ns) assert ns['packages'] == [ 'my_package', 'my_package.sub_pkg1', 'my_package.sub_pkg2' ] assert ns['install_requires'] == [ 'cleo (>=0.6.0.0,<0.7.0.0)' ] assert ns['entry_points'] == { 'console_scripts': [ 'my-script = my_package:main', 'my-2nd-script = my_package:main2', ] } assert ns['extras_require'] == { 'time': [ 'pendulum (>=1.4.0.0,<2.0.0.0)' ] }
def test_wheel_module(): module_path = fixtures_dir / 'module1' WheelBuilder.make(Poetry.create(str(module_path))) whl = module_path / 'dist' / 'module1-0.1-py2.py3-none-any.whl' assert whl.exists()
def test_package(): poetry = Poetry.create(project('complete')) builder = SdistBuilder(poetry) builder.build() sdist = fixtures_dir / 'complete' / 'dist' / 'my-package-1.2.3.tar.gz' assert sdist.exists()
def test_prelease(): poetry = Poetry.create(project('prerelease')) builder = SdistBuilder(poetry, NullVenv(), NullIO()) builder.build() sdist = fixtures_dir / 'prerelease' / 'dist' / 'prerelease-0.1b1.tar.gz' assert sdist.exists()
def test_complete(): module_path = fixtures_dir / 'complete' builder = CompleteBuilder(Poetry.create(module_path), NullVenv(True), NullIO()) builder.build() whl = module_path / 'dist' / 'my_package-1.2.3-py3-none-any.whl' assert whl.exists zip = zipfile.ZipFile(whl) try: entry_points = zip.read('my_package-1.2.3.dist-info/entry_points.txt') assert entry_points.decode() == """\ [console_scripts] my-2nd-script=my_package:main2 my-script=my_package:main """ wheel_data = zip.read('my_package-1.2.3.dist-info/WHEEL').decode() assert wheel_data == f"""\ Wheel-Version: 1.0 Generator: poetry {__version__} Root-Is-Purelib: true Tag: py3-none-any """ wheel_data = zip.read('my_package-1.2.3.dist-info/METADATA').decode() assert wheel_data == """\ Metadata-Version: 2.1 Name: my-package Version: 1.2.3 Summary: Some description. Home-page: https://poetry.eustace.io/ License: MIT Keywords: packaging,dependency,poetry Author: Sébastien Eustace Author-email: [email protected] Requires-Python: >= 3.6.0.0, < 4.0.0.0 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Provides-Extra: time Requires-Dist: cleo (>=0.6.0.0,<0.7.0.0) Requires-Dist: pendulum (>=1.4.0.0,<2.0.0.0); extra == "time" Description-Content-Type: text/x-rst My Package ========== """ finally: zip.close()
def test_with_c_extensions(): poetry = Poetry.create(project('extended')) builder = SdistBuilder(poetry, NullVenv(), NullIO()) builder.build() sdist = fixtures_dir / 'extended' / 'dist' / 'extended-0.1.tar.gz' assert sdist.exists() tar = tarfile.open(str(sdist), 'r') assert 'extended-0.1/build.py' in tar.getnames() assert 'extended-0.1/extended/extended.c' in tar.getnames()
def test_find_files_to_add(): poetry = Poetry.create(project('complete')) builder = SdistBuilder(poetry) result = builder.find_files_to_add() assert result == [ Path('README.rst'), Path('my_package/__init__.py'), Path('my_package/data1/test.json'), Path('my_package/sub_pkg1/__init__.py'), Path('my_package/sub_pkg2/__init__.py'), Path('my_package/sub_pkg2/data2/data.json'), Path('pyproject.toml'), ]
def test_poetry(): poetry = Poetry.create(str(fixtures_dir / 'sample_project')) package = poetry.package assert package.name == 'my-package' assert package.version == '1.2.3' assert package.description == 'Some description.' assert package.authors == ['Sébastien Eustace <*****@*****.**>'] assert package.license == 'MIT' assert str(package.readme.relative_to( fixtures_dir)) == "sample_project/README.rst" assert package.homepage == 'https://poetry.eustace.io' assert package.repository_url == 'https://github.com/sdispater/poetry' assert package.keywords == ["packaging", "dependency", "poetry"] assert package.python_versions == '~2.7 || ^3.6' assert str(package.python_constraint ) == '>= 2.7.0.0, < 2.8.0.0 || >= 3.6.0.0, < 4.0.0.0' dependencies = package.requires cleo = dependencies[0] assert cleo.pretty_constraint == '^0.6' assert not cleo.is_optional() pendulum = dependencies[1] assert pendulum.pretty_constraint == 'branch 2.0' assert pendulum.is_vcs() assert pendulum.vcs == 'git' assert pendulum.branch == '2.0' assert pendulum.source == 'https://github.com/sdispater/pendulum.git' assert pendulum.allows_prereleases() requests = dependencies[2] assert requests.pretty_constraint == '^2.18' assert not requests.is_vcs() assert not requests.allows_prereleases() assert requests.is_optional() assert requests.extras == ['security'] pathlib2 = dependencies[3] assert pathlib2.pretty_constraint == '^2.2' assert pathlib2.python_versions == '~2.7' assert not pathlib2.is_optional() assert 'db' in package.extras
def test_wheel_c_extension(): module_path = fixtures_dir / 'extended' builder = CompleteBuilder(Poetry.create(module_path), NullVenv(True), NullIO()) builder.build() sdist = fixtures_dir / 'extended' / 'dist' / 'extended-0.1.tar.gz' assert sdist.exists() tar = tarfile.open(str(sdist), 'r') assert 'extended-0.1/build.py' in tar.getnames() assert 'extended-0.1/extended/extended.c' in tar.getnames() whl = list((module_path / 'dist').glob('extended-0.1-cp3*-cp3*m-*.whl'))[0] assert whl.exists() zip = zipfile.ZipFile(whl) has_compiled_extension = False for name in zip.namelist(): if name.startswith('extended/extended') and name.endswith('.so'): has_compiled_extension = True assert has_compiled_extension try: wheel_data = zip.read('extended-0.1.dist-info/WHEEL').decode() assert re.match( """(?m)^\ Wheel-Version: 1.0 Generator: poetry {} Root-Is-Purelib: false Tag: cp3\d-cp3\dm-.+ $""".format(__version__), wheel_data) is not None finally: zip.close()