Skip to content

Commit

Permalink
Robustify PantsRequirementIntegrationTest.
Browse files Browse the repository at this point in the history
Previously changes to `pantsbuild.pants` requirements on master between
releases would leave to resolution conflicts in the
`test_pants_requirement` test. Make the test robust to these sort of
changes by producing and consuming a unique `pantsbuild.pants`
distribution for each run of the test.

Fixes #5519
  • Loading branch information
jsirois committed Feb 26, 2018
1 parent 114f2ff commit 77683ed
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 11 deletions.
2 changes: 2 additions & 0 deletions tests/python/pants_test/backend/python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ python_tests(
sources=globs('*_integration.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'},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
unicode_literals, with_statement)

import os
import shutil
import uuid
from contextlib import contextmanager

from pants.base.build_environment import get_buildroot
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


Expand All @@ -32,16 +37,54 @@ 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 os 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

tests_dir = 'testprojects/pants-plugins/tests/python/test_pants_plugin'
command = [
'test',
tests_dir,
]

tests_dir_absolute = os.path.join(get_buildroot(), tests_dir)
with self.file_renamed(tests_dir_absolute, 'TEST_BUILD', 'BUILD'):
pants_run = self.run_with_testproject_backend_pkgs(command)
self.assert_success(pants_run)
with self.create_unstable_pants_distribution() as repo:
tests_dir = 'testprojects/pants-plugins/tests/python/test_pants_plugin'
with self.file_renamed(os.path.join(get_buildroot(), tests_dir), 'TEST_BUILD', 'BUILD'):
test_pants_requirement_cmd = ['--python-repos-repos={}'.format(repo),
'test',
tests_dir]
pants_run = self.run_with_testproject_backend_pkgs(test_pants_requirement_cmd)
self.assert_success(pants_run)

0 comments on commit 77683ed

Please sign in to comment.