wonderful-iron-54019
09/15/2020, 6:59 PMwonderful-iron-54019
09/15/2020, 6:59 PMwonderful-iron-54019
09/15/2020, 6:59 PMwonderful-iron-54019
09/15/2020, 6:59 PMfrom pants.engine.target import Target
from pants.testutil.test_base import TestBase
from targets.cloud_formation import CloudFormationStack
from .deploy_cloud_formation import get_digest_path
class CloudFormationTests(TestBase):
def test_get_digest_path(self) -> None:
"""Tests that given a Target we can get the path of a file in its digest"""
target = self.make_target(
spec="targets:mytarget",
target_type=CloudFormationStack,
stack_name="mystack",
template_file="temp.yaml",
)
wonderful-iron-54019
09/15/2020, 7:00 PM/Users/jerkelens/.pex/installed_wheels/3b9417b721fe8046939c4c27f886514cfc662352/pantsbuild.pants.testutil-1.30.0-py36.py37.py38-none-any.whl/pants/test
util/test_base.py:241: in make_target
name=address.target_name, address=address, build_graph=self.build_graph, **kwargs
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <[AttributeError("'CloudFormationStack' object has no attribute 'field_values'") raised in repr()] CloudFormationStack object at 0x10ce23c90>
args = ()
kwargs = {'address': Address(targets, mytarget), 'build_graph': <pants.engine.legacy.graph.LegacyBuildGraph object at 0x10ce23050>, 'name': 'mytarget',
'stack_name': 'mystack', ...}
@wraps(prev_init)
def new_init(self, *args: Any, **kwargs: Any) -> None:
> prev_init(self, *args, **kwargs)
E TypeError: __init__() got an unexpected keyword argument 'name'
/Users/jerkelens/.pex/installed_wheels/8f29d6fb12e6a07fd5f39bcdb51280c3d64ca46a/pantsbuild.pants-1.30.0-cp37-cp37m-macosx_10_11_x86_64.whl/pants/util/m
eta.py:182: TypeError
wonderful-iron-54019
09/15/2020, 7:00 PMwonderful-iron-54019
09/15/2020, 7:00 PMhundreds-father-404
09/15/2020, 7:05 PMself.make_target
uses the v1 engine and returns a v1 Target, rather than a v2 target. We deleted that in 2.0
Instead, use self.add_to_build_file("project/util", "python_library(sources=['f1.py'])
Then, “request” the target by using self.request_single_product(WrappedTarget, Address("project/util").target
, where that .target
at the end “unwraps” the WrappedTarget
to get you the underlying Target
class.
(In 2.0, you would instead use self.get_target(Address("project/util"))
. Sorry that 1.30 testing is not at all cleaned up..)hundreds-father-404
09/15/2020, 7:05 PMTestBase
is totally hermetic.
@classmethod
def target_types(cls):
return [PythonLibrary]
wonderful-iron-54019
09/15/2020, 7:41 PMwonderful-iron-54019
09/15/2020, 7:41 PMhundreds-father-404
09/15/2020, 7:43 PMTestBase
is deprecated in favor of the Pytest style RuleRunner
. Not yet deleted tho.
* You can use that nice new get_target()
method
* It’s now request_product()
, rather than request_single_product()
hundreds-father-404
09/15/2020, 7:44 PMhundreds-father-404
09/15/2020, 10:26 PMrun_rule_with_mocks
. You likely want to use Approach #3 instead, given the nature of your plugins, but FYI
https://www.pantsbuild.org/v2.0/docs/rules-api-testing#approach-2-run_rule_with_mocks-unit-tests-for-rules
Working on fleshing out the Approach #3 RuleRunner
docs now