forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix/integration test for pants_requirement() (pantsbuild#5457)
### Problem It's not possible to use `pants_requirement()` to stand in for `python_requirement_library(requirements=[python_requirement('pantsbuild.pants==1.5.0.dev3')])` in a separate repo. This defeats the purpose of `pants_requirement()`, which expands into an `==` requirement on the pants version denoted in the repo's `pants.ini`. The error is: ``` u"There is no type registered for alias <class 'pants.backend.python.targets.python_requirement_library.PythonRequirementLibrary'>" ``` ### Solution `ParseContext#create_object()` accepts an alias as the first argument, not the class itself. [Changing `PythonRequirementLibrary` to `'python_requirement_library'` in `src/python/pants/backend/python/pants_requirement.py`](https://github.com/cosmicexplorer/pants/blob/1fc4ba0310d3fd20d26384e5e1c356e8f99b9eea/src/python/pants/backend/python/pants_requirement.py#L37) allows `pants_requirement()` to be used as documented. Integration tests were added in `tests/python/pants_test/backend/python{test_pants_requirement_integration,/tasks/test_setup_py_integration}.py`.
- Loading branch information
1 parent
7cdea9a
commit f55260a
Showing
16 changed files
with
200 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pants_requirement() |
15 changes: 15 additions & 0 deletions
15
testprojects/pants-plugins/src/python/test_pants_plugin/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
python_library( | ||
dependencies=[ | ||
'testprojects/pants-plugins/3rdparty/python/pants', | ||
'testprojects/pants-plugins/src/python/test_pants_plugin/subsystems', | ||
], | ||
provides=setup_py( | ||
name='test_pants_plugin', | ||
description='A test pants plugin', | ||
version='0.0.1', | ||
namespace_packages=[ | ||
'test_pants_plugin', | ||
'test_pants_plugin.subsystems', | ||
], | ||
) | ||
) |
1 change: 1 addition & 0 deletions
1
testprojects/pants-plugins/src/python/test_pants_plugin/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__import__('pkg_resources').declare_namespace(__name__) |
22 changes: 22 additions & 0 deletions
22
testprojects/pants-plugins/src/python/test_pants_plugin/pants_infra_tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 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) | ||
|
||
from test_pants_plugin.subsystems.pants_test_infra import PantsTestInfra | ||
|
||
from pants.backend.python.targets.python_tests import PythonTests | ||
|
||
|
||
class PantsInfraTests(object): | ||
|
||
def __init__(self, parse_context): | ||
self._parse_context = parse_context | ||
self._pants_test_infra = PantsTestInfra.global_instance() | ||
|
||
def __call__(self, dependencies=[], **kwargs): | ||
dependencies.extend(self._pants_test_infra.dependent_target_addrs()) | ||
self._parse_context.create_object( | ||
PythonTests.alias(), dependencies=dependencies, **kwargs) |
22 changes: 22 additions & 0 deletions
22
testprojects/pants-plugins/src/python/test_pants_plugin/register.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 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) | ||
|
||
from test_pants_plugin.pants_infra_tests import PantsInfraTests | ||
from test_pants_plugin.subsystems.pants_test_infra import PantsTestInfra | ||
|
||
from pants.build_graph.build_file_aliases import BuildFileAliases | ||
|
||
|
||
def build_file_aliases(): | ||
return BuildFileAliases( | ||
context_aware_object_factories={ | ||
'pants_infra_tests': PantsInfraTests, | ||
} | ||
) | ||
|
||
def global_subsystems(): | ||
return (PantsTestInfra,) |
5 changes: 5 additions & 0 deletions
5
testprojects/pants-plugins/src/python/test_pants_plugin/subsystems/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
python_library( | ||
dependencies=[ | ||
'testprojects/pants-plugins/3rdparty/python/pants', | ||
], | ||
) |
Empty file.
31 changes: 31 additions & 0 deletions
31
testprojects/pants-plugins/src/python/test_pants_plugin/subsystems/pants_test_infra.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 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) | ||
|
||
from pants.backend.python.targets.python_target import PythonTarget | ||
from pants.build_graph.target import Target | ||
from pants.subsystem.subsystem import Subsystem | ||
|
||
|
||
class PantsTestInfra(Subsystem): | ||
options_scope = 'pants-test-infra' | ||
|
||
@classmethod | ||
def register_options(cls, register): | ||
super(PantsTestInfra, cls).register_options(register) | ||
register('--pants-requirement-target', advanced=True, fingerprint=True, | ||
help='Address for a python target providing the pants sdist.', | ||
type=str, default=None) | ||
register('--pants-test-infra-target', advanced=True, fingerprint=True, | ||
help='Address for a python target providing the ' | ||
'pants test infra sdist.', | ||
type=str, default=None) | ||
|
||
def dependent_target_addrs(self): | ||
return [ | ||
self.get_options().pants_requirement_target, | ||
self.get_options().pants_test_infra_target, | ||
] |
1 change: 1 addition & 0 deletions
1
testprojects/pants-plugins/tests/python/test_pants_plugin/TEST_BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pants_infra_tests() |
Empty file.
15 changes: 15 additions & 0 deletions
15
...jects/pants-plugins/tests/python/test_pants_plugin/test_pants_plugin_pants_requirement.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# 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) | ||
|
||
from pants.base.build_environment import pants_version | ||
from pants.version import VERSION as _VERSION | ||
from pants_test.base_test import BaseTest | ||
|
||
|
||
class PantsPluginPantsRequirementTest(BaseTest): | ||
def test_version(self): | ||
self.assertEqual(pants_version(), _VERSION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tests/python/pants_test/backend/python/test_pants_requirement_integration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# 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 | ||
|
||
from pants.base.build_environment import get_buildroot | ||
from pants_test.pants_run_integration_test import PantsRunIntegrationTest | ||
|
||
|
||
class PantsRequirementIntegrationTest(PantsRunIntegrationTest): | ||
"""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 | ||
objects.""" | ||
|
||
def run_with_testproject_backend_pkgs(self, cmd): | ||
testproject_backend_src_dir = os.path.join( | ||
get_buildroot(), 'testprojects/pants-plugins/src/python') | ||
testproject_backend_pkg_name = 'test_pants_plugin' | ||
pants_req_addr = 'testprojects/pants-plugins/3rdparty/python/pants' | ||
pants_test_infra_addr = 'tests/python/pants_test:test_infra' | ||
pre_cmd_args = [ | ||
"--pythonpath=+['{}']".format(testproject_backend_src_dir), | ||
"--backend-packages=+['{}']".format(testproject_backend_pkg_name), | ||
"--pants-test-infra-pants-requirement-target={}".format(pants_req_addr), | ||
"--pants-test-infra-pants-test-infra-target={}".format(pants_test_infra_addr), | ||
] | ||
command = pre_cmd_args + cmd | ||
return self.run_pants(command=command) | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters