Skip to content

Commit

Permalink
Robustify SetupPyIntegrationTest. (pantsbuild#5610)
Browse files Browse the repository at this point in the history
Previously, when the pants `VERSION` was bumped and before publishing
the `test_setup_py_unregistered_pants_plugin` test would fail to resolve
`pantsbuild.pants` at the new version on pypi. Update the test to use a
custom-produced `pantsbuild.pants` distribution and share this logic
with `PantsRequirementIntegrationTest`.

Similar to pantsbuild#5519
  • Loading branch information
jsirois authored Mar 17, 2018
1 parent f9ee6fd commit f35e1e6
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 69 deletions.
13 changes: 11 additions & 2 deletions tests/python/pants_test/backend/python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,20 @@ python_tests(
python_tests(
name='integration',
sources=globs('*_integration.py'),
dependencies=[
':pants_requirement_integration_test_base',
'src/python/pants/base:build_environment',
],
tags={'integration'},
)

python_library(
name='pants_requirement_integration_test_base',
sources=['pants_requirement_integration_test_base.py'],
dependencies=[
'src/python/pants/base:build_environment',
'src/python/pants/util:contextutil',
'src/python/pants/util:dirutil',
'tests/python/pants_test:int-test',
],
tags={'integration'},
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# coding=utf-8
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import os
import shutil
import uuid
from contextlib import contextmanager

from pants.base.build_environment import get_buildroot, pants_version
from pants.util.contextutil import temporary_dir
from pants.util.dirutil import safe_walk
from pants_test.pants_run_integration_test import PantsRunIntegrationTest


class PantsRequirementIntegrationTestBase(PantsRunIntegrationTest):
@contextmanager
def _unstable_pants_version(self):
stable_version = pants_version()
unstable_version = b'{}+{}'.format(stable_version, uuid.uuid4().hex)
version_dir = os.path.join(get_buildroot(), 'src/python/pants')

with self.file_renamed(version_dir, 'VERSION', 'VERSION.orig'):
with open(os.path.join(version_dir, 'VERSION'), 'wb') as fp:
fp.write(unstable_version)

pants_run = self.run_pants(['--version'])
self.assert_success(pants_run)
self.assertEqual(unstable_version, pants_run.stdout_data.strip())

yield

def _iter_wheels(self, path):
for root, _, files in safe_walk(path):
for f in files:
if f.endswith('.whl'):
yield os.path.join(root, f)

@contextmanager
def create_unstable_pants_distribution(self):
with self._unstable_pants_version():
with temporary_dir() as dist_dir:
create_pants_dist_cmd = ['--pants-distdir={}'.format(dist_dir),
'setup-py',
'--run=bdist_wheel',
'src/python/pants:pants-packaged']
pants_run = self.run_pants(create_pants_dist_cmd)
self.assert_success(pants_run)

# Create a flat wheel repo from the results of setup-py above.
with temporary_dir() as repo:
for wheel in self._iter_wheels(dist_dir):
shutil.copy(wheel, os.path.join(repo, os.path.basename(wheel)))

yield repo
3 changes: 2 additions & 1 deletion tests/python/pants_test/backend/python/tasks/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ python_tests(
name='integration',
sources=globs('*_integration.py'),
dependencies=[
'3rdparty/python:pex',
'src/python/pants/util:contextutil',
'src/python/pants/util:process_handler',
'tests/python/pants_test/backend/python:pants_requirement_integration_test_base',
'tests/python/pants_test:int-test',
'3rdparty/python:pex',
],
tags={'integration'},
timeout=2400
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import re
import tarfile

from pants_test.pants_run_integration_test import PantsRunIntegrationTest
from pants_test.backend.python.pants_requirement_integration_test_base import \
PantsRequirementIntegrationTestBase


class SetupPyIntegrationTest(PantsRunIntegrationTest):
class SetupPyIntegrationTest(PantsRequirementIntegrationTestBase):

def assert_sdist(self, pants_run, key, files):
sdist_path = 'dist/{}-0.0.1.tar.gz'.format(key)
Expand Down Expand Up @@ -142,19 +143,19 @@ def test_setup_py_unregistered_pants_plugin(self):

self.maxDiff = None

command = [
'setup-py',
'testprojects/pants-plugins/src/python/test_pants_plugin',
]
pants_run = self.run_pants(command=command)
self.assert_success(pants_run)

self.assert_sdist(pants_run, 'test_pants_plugin', [
'test_pants_plugin/',
'test_pants_plugin/__init__.py',
'test_pants_plugin/pants_infra_tests.py',
'test_pants_plugin/register.py',
'test_pants_plugin/subsystems/',
'test_pants_plugin/subsystems/__init__.py',
'test_pants_plugin/subsystems/pants_test_infra.py',
])
with self.create_unstable_pants_distribution() as repo:
command = ['--python-repos-repos={}'.format(repo),
'setup-py',
'testprojects/pants-plugins/src/python/test_pants_plugin']
pants_run = self.run_pants(command=command)
self.assert_success(pants_run)

self.assert_sdist(pants_run, 'test_pants_plugin', [
'test_pants_plugin/',
'test_pants_plugin/__init__.py',
'test_pants_plugin/pants_infra_tests.py',
'test_pants_plugin/register.py',
'test_pants_plugin/subsystems/',
'test_pants_plugin/subsystems/__init__.py',
'test_pants_plugin/subsystems/pants_test_infra.py',
])
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
unicode_literals, with_statement)

import os
import shutil
import uuid
from contextlib import contextmanager

from pants.base.build_environment import get_buildroot, pants_version
from pants.util.contextutil import temporary_dir
from pants.util.dirutil import safe_walk
from pants_test.pants_run_integration_test import PantsRunIntegrationTest
from pants.base.build_environment import get_buildroot
from pants_test.backend.python.pants_requirement_integration_test_base import \
PantsRequirementIntegrationTestBase


class PantsRequirementIntegrationTest(PantsRunIntegrationTest):
class PantsRequirementIntegrationTest(PantsRequirementIntegrationTestBase):
"""A pants plugin should be able to depend on a pants_requirement() alone to
declare its dependencies on pants modules. This plugin, when added to the
pythonpath and backend_packages, should be able to declare new BUILD file
Expand All @@ -37,46 +33,6 @@ def run_with_testproject_backend_pkgs(self, cmd):
command = pre_cmd_args + cmd
return self.run_pants(command=command)

@contextmanager
def unstable_pants_version(self):
stable_version = pants_version()
unstable_version = b'{}+{}'.format(stable_version, uuid.uuid4().hex)
version_dir = os.path.join(get_buildroot(), 'src/python/pants')

with self.file_renamed(version_dir, 'VERSION', 'VERSION.orig'):
with open(os.path.join(version_dir, 'VERSION'), 'wb') as fp:
fp.write(unstable_version)

pants_run = self.run_pants(['--version'])
self.assert_success(pants_run)
self.assertEqual(unstable_version, pants_run.stdout_data.strip())

yield

def iter_wheels(self, path):
for root, _, files in safe_walk(path):
for f in files:
if f.endswith('.whl'):
yield os.path.join(root, f)

@contextmanager
def create_unstable_pants_distribution(self):
with self.unstable_pants_version():
with temporary_dir() as dist_dir:
create_pants_dist_cmd = ['--pants-distdir={}'.format(dist_dir),
'setup-py',
'--run=bdist_wheel',
'src/python/pants:pants-packaged']
pants_run = self.run_pants(create_pants_dist_cmd)
self.assert_success(pants_run)

# Create a flat wheel repo from the results of setup-py above.
with temporary_dir() as repo:
for wheel in self.iter_wheels(dist_dir):
shutil.copy(wheel, os.path.join(repo, os.path.basename(wheel)))

yield repo

def test_pants_requirement(self):
self.maxDiff = None

Expand Down

0 comments on commit f35e1e6

Please sign in to comment.