本文整理汇总了Python中pants.engine.rules.GraphMaker类的典型用法代码示例。如果您正苦于以下问题:Python GraphMaker类的具体用法?Python GraphMaker怎么用?Python GraphMaker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GraphMaker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_noop_removal_transitive
def test_noop_removal_transitive(self):
# If a noop-able rule has rules that depend on it,
# they should be removed from the graph.
rules = [
(Exactly(B), (Select(C),), noop),
(Exactly(A), (Select(B),), noop),
(Exactly(A), tuple(), noop),
]
intrinsics = [
(D, C, BoringRule(C))
]
graphmaker = GraphMaker(RuleIndex.create(rules, intrinsics),
root_subject_fns=_suba_root_subject_fns,
)
subgraph = graphmaker.generate_subgraph(SubA(), requested_product=A)
self.assert_equal_with_printing(dedent("""
{
root_subject_types: (SubA,)
root_rules:
Select(A) for SubA => ((Exactly(A), (), noop) of SubA,)
all_rules:
(Exactly(A), (), noop) of SubA => (,)
}""").strip(), subgraph)
示例2: test_full_graph_for_planner_example
def test_full_graph_for_planner_example(self):
symbol_table_cls = TargetTable
address_mapper = AddressMapper(symbol_table_cls, JsonParser, '*.BUILD.json')
tasks = create_graph_tasks(address_mapper, symbol_table_cls) + create_fs_tasks()
intrinsics = create_fs_intrinsics('Let us pretend that this is a ProjectTree!')
rule_index = RuleIndex.create(tasks, intrinsics)
graphmaker = GraphMaker(rule_index,
root_subject_fns={k: lambda p: Select(p) for k in (Address, # TODO, use the actual fns.
PathGlobs,
SingleAddress,
SiblingAddresses,
DescendantAddresses,
AscendantAddresses
)})
fullgraph = graphmaker.full_graph()
print('---diagnostic------')
print(fullgraph.error_message())
print('/---diagnostic------')
print(fullgraph)
# Assert that all of the rules specified the various task fns are present
declared_rules = rule_index.all_rules()
rules_remaining_in_graph_strs = set(str(r.rule) for r in fullgraph.rule_dependencies.keys())
declared_rule_strings = set(str(r) for r in declared_rules)
self.assertEquals(declared_rule_strings,
rules_remaining_in_graph_strs
)
# statically assert that the number of dependency keys is fixed
self.assertEquals(41, len(fullgraph.rule_dependencies))
示例3: test_select_dependencies_recurse_with_different_type
def test_select_dependencies_recurse_with_different_type(self):
rules = [
(Exactly(A), (SelectDependencies(B, SubA, field_types=(C, D,)),), noop),
(B, (Select(A),), noop),
(C, (Select(SubA),), noop),
(SubA, tuple(), noop)
]
graphmaker = GraphMaker(RuleIndex.create(rules, tuple()),
root_subject_fns=_suba_root_subject_fns)
subgraph = graphmaker.generate_subgraph(SubA(), requested_product=A)
self.assert_equal_with_printing(dedent("""
{
root_subject_types: (SubA,)
root_rules:
Select(A) for SubA => ((Exactly(A), (SelectDependencies(B, SubA, field_types=(C, D,)),), noop) of SubA,)
all_rules:
(B, (Select(A),), noop) of C => ((Exactly(A), (SelectDependencies(B, SubA, field_types=(C, D,)),), noop) of C,)
(B, (Select(A),), noop) of D => ((Exactly(A), (SelectDependencies(B, SubA, field_types=(C, D,)),), noop) of D,)
(Exactly(A), (SelectDependencies(B, SubA, field_types=(C, D,)),), noop) of C => ((SubA, (), noop) of C, (B, (Select(A),), noop) of C, (B, (Select(A),), noop) of D,)
(Exactly(A), (SelectDependencies(B, SubA, field_types=(C, D,)),), noop) of D => ((SubA, (), noop) of D, (B, (Select(A),), noop) of C, (B, (Select(A),), noop) of D,)
(Exactly(A), (SelectDependencies(B, SubA, field_types=(C, D,)),), noop) of SubA => (SubjectIsProduct(SubA), (B, (Select(A),), noop) of C, (B, (Select(A),), noop) of D,)
(SubA, (), noop) of C => (,)
(SubA, (), noop) of D => (,)
}""").strip(),
subgraph)
示例4: test_smallest_full_test
def test_smallest_full_test(self):
rules = [
(Exactly(A), (Select(SubA),), noop)
]
graphmaker = GraphMaker(NodeBuilder.create(rules, tuple()),
root_subject_fns={k: lambda p: Select(p) for k in (SubA,)})
fullgraph = graphmaker.full_graph()
self.assert_equal_with_printing(dedent("""
{
root_subject_types: (SubA,)
root_rules: (Exactly(A), (Select(SubA),), noop) of SubA
(Exactly(A), (Select(SubA),), noop) of SubA => (SubjectIsProduct(SubA),)
}""").strip(), fullgraph)
示例5: test_single_rule_depending_on_subject_selection
def test_single_rule_depending_on_subject_selection(self):
rules = [
(Exactly(A), (Select(SubA),), noop)
]
graphmaker = GraphMaker(NodeBuilder.create(rules, tuple()),
root_subject_fns=_suba_root_subject_fns)
subgraph = graphmaker.generate_subgraph(SubA(), requested_product=A)
self.assert_equal_with_printing(dedent("""
{
root_subject_types: (SubA,)
root_rules: (Exactly(A), (Select(SubA),), noop) of SubA
(Exactly(A), (Select(SubA),), noop) of SubA => (SubjectIsProduct(SubA),)
}""").strip(), subgraph)
示例6: test_select_literal
def test_select_literal(self):
literally_a = A()
rules = [
(B, (SelectLiteral(literally_a, A),), noop)
]
graphmaker = GraphMaker(NodeBuilder.create(rules, tuple()),
root_subject_fns=_suba_root_subject_fns)
subgraph = graphmaker.generate_subgraph(SubA(), requested_product=B)
self.assert_equal_with_printing(dedent("""
{
root_subject_types: (SubA,)
root_rules: (B, (SelectLiteral(A(), A),), noop) of SubA
(B, (SelectLiteral(A(), A),), noop) of SubA => (Literal(A(), A),)
}""").strip(), subgraph)
示例7: test_select_dependencies_non_matching_subselector_because_of_intrinsic
def test_select_dependencies_non_matching_subselector_because_of_intrinsic(self):
rules = [
(Exactly(A), (SelectDependencies(B, SubA, field_types=(D,)),), noop),
]
intrinsics = [
(C, B, noop),
]
graphmaker = GraphMaker(RuleIndex.create(rules, intrinsics),
root_subject_fns=_suba_root_subject_fns)
subgraph = graphmaker.generate_subgraph(SubA(), requested_product=A)
self.assert_equal_with_printing('{empty graph}', subgraph)
self.assert_equal_with_printing(dedent("""
Rules with errors: 1
(Exactly(A), (SelectDependencies(B, SubA, field_types=(D,)),), noop):
no matches for Select(B) when resolving SelectDependencies(B, SubA, field_types=(D,)) with subject types: D""").strip(),
subgraph.error_message())
示例8: test_depends_on_multiple_one_noop
def test_depends_on_multiple_one_noop(self):
rules = [
(B, (Select(A),), noop),
(A, (Select(C),), noop),
(A, (Select(SubA),), noop)
]
graphmaker = GraphMaker(NodeBuilder.create(rules, tuple()),
root_subject_fns=_suba_root_subject_fns)
subgraph = graphmaker.generate_subgraph(SubA(), requested_product=B)
self.assert_equal_with_printing(dedent("""
{
root_subject_types: (SubA,)
root_rules: (B, (Select(A),), noop) of SubA
(A, (Select(SubA),), noop) of SubA => (SubjectIsProduct(SubA),)
(B, (Select(A),), noop) of SubA => ((A, (Select(SubA),), noop) of SubA,)
}""").strip(), subgraph)
示例9: test_select_dependencies_with_subject_as_first_subselector
def test_select_dependencies_with_subject_as_first_subselector(self):
rules = [
(Exactly(A), (SelectDependencies(B, SubA, field_types=(D,)),), noop),
(B, (Select(D),), noop),
]
graphmaker = GraphMaker(NodeBuilder.create(rules, tuple()),
root_subject_fns=_suba_root_subject_fns)
subgraph = graphmaker.generate_subgraph(SubA(), requested_product=A)
self.assert_equal_with_printing(dedent("""
{
root_subject_types: (SubA,)
root_rules: (Exactly(A), (SelectDependencies(B, SubA, u'dependencies', field_types=(D,)),), noop) of SubA
(B, (Select(D),), noop) of D => (SubjectIsProduct(D),)
(Exactly(A), (SelectDependencies(B, SubA, u'dependencies', field_types=(D,)),), noop) of SubA => (SubjectIsProduct(SubA), (B, (Select(D),), noop) of D,)
}""").strip(),
subgraph)
示例10: test_successful_when_one_field_type_is_unfulfillable
def test_successful_when_one_field_type_is_unfulfillable(self):
# NB We may want this to be a warning, since it may not be intentional
rules = [
(B, (Select(SubA),), noop),
(D, (Select(Exactly(B)), SelectDependencies(B, SubA, field_types=(SubA, C))), noop)
]
graphmaker = GraphMaker(NodeBuilder.create(rules, tuple()),
root_subject_fns=_suba_root_subject_fns)
subgraph = graphmaker.generate_subgraph(SubA(), requested_product=D)
self.assert_equal_with_printing(dedent("""
{
root_subject_types: (SubA,)
root_rules: (D, (Select(Exactly(B)), SelectDependencies(B, SubA, u'dependencies', field_types=(SubA, C,))), noop) of SubA
(B, (Select(SubA),), noop) of SubA => (SubjectIsProduct(SubA),)
(D, (Select(Exactly(B)), SelectDependencies(B, SubA, u'dependencies', field_types=(SubA, C,))), noop) of SubA => ((B, (Select(SubA),), noop) of SubA, SubjectIsProduct(SubA), (B, (Select(SubA),), noop) of SubA,)
}""").strip(),
subgraph)
示例11: test_smallest_full_test_multiple_root_subject_types
def test_smallest_full_test_multiple_root_subject_types(self):
rules = [
(Exactly(A), (Select(SubA),), noop),
(Exactly(B), (Select(A),), noop)
]
select_p = lambda p: Select(p)
graphmaker = GraphMaker(NodeBuilder.create(rules, tuple()),
root_subject_fns=OrderedDict([(SubA, select_p), (A, select_p)]))
fullgraph = graphmaker.full_graph()
self.assert_equal_with_printing(dedent("""
{
root_subject_types: (SubA, A,)
root_rules: (Exactly(A), (Select(SubA),), noop) of SubA, (Exactly(B), (Select(A),), noop) of A, (Exactly(B), (Select(A),), noop) of SubA, SubjectIsProduct(A)
(Exactly(A), (Select(SubA),), noop) of SubA => (SubjectIsProduct(SubA),)
(Exactly(B), (Select(A),), noop) of A => (SubjectIsProduct(A),)
(Exactly(B), (Select(A),), noop) of SubA => ((Exactly(A), (Select(SubA),), noop) of SubA,)
}""").strip(),
fullgraph)
示例12: test_one_level_of_recursion
def test_one_level_of_recursion(self):
rules = [
(Exactly(A), (Select(B),), noop),
(B, (Select(SubA),), noop)
]
graphmaker = GraphMaker(RuleIndex.create(rules, tuple()),
root_subject_fns=_suba_root_subject_fns)
subgraph = graphmaker.generate_subgraph(SubA(), requested_product=A)
self.assert_equal_with_printing(dedent("""
{
root_subject_types: (SubA,)
root_rules:
Select(A) for SubA => ((Exactly(A), (Select(B),), noop) of SubA,)
all_rules:
(B, (Select(SubA),), noop) of SubA => (SubjectIsProduct(SubA),)
(Exactly(A), (Select(B),), noop) of SubA => ((B, (Select(SubA),), noop) of SubA,)
}""").strip(), subgraph)
示例13: test_multiple_depend_on_same_rule
def test_multiple_depend_on_same_rule(self):
rules = [
(B, (Select(A),), noop),
(C, (Select(A),), noop),
(A, (Select(SubA),), noop)
]
graphmaker = GraphMaker(NodeBuilder.create(rules, tuple()),
root_subject_fns=_suba_root_subject_fns)
subgraph = graphmaker.full_graph()
self.assert_equal_with_printing(dedent("""
{
root_subject_types: (SubA,)
root_rules: (A, (Select(SubA),), noop) of SubA, (B, (Select(A),), noop) of SubA, (C, (Select(A),), noop) of SubA
(A, (Select(SubA),), noop) of SubA => (SubjectIsProduct(SubA),)
(B, (Select(A),), noop) of SubA => ((A, (Select(SubA),), noop) of SubA,)
(C, (Select(A),), noop) of SubA => ((A, (Select(SubA),), noop) of SubA,)
}""").strip(), subgraph)
示例14: test_noop_removal_full_single_subject_type
def test_noop_removal_full_single_subject_type(self):
intrinsics = {(B, C): BoringRule(C)}
rules = [
# C is provided by an intrinsic, but only if the subject is B.
(Exactly(A), (Select(C),), noop),
(Exactly(A), tuple(), noop),
]
graphmaker = GraphMaker(NodeBuilder.create(rules,
intrinsic_providers=(IntrinsicProvider(intrinsics),)),
root_subject_fns=_suba_root_subject_fns)
fullgraph = graphmaker.full_graph()
self.assert_equal_with_printing(dedent("""
{
root_subject_types: (SubA,)
root_rules: (Exactly(A), (), noop) of SubA
(Exactly(A), (), noop) of SubA => (,)
}""").strip(), fullgraph)
示例15: test_select_projection_simple
def test_select_projection_simple(self):
rules = [
(Exactly(A), (SelectProjection(B, D, ('some',), SubA),), noop),
(B, (Select(D),), noop),
]
graphmaker = GraphMaker(RuleIndex.create(rules, tuple()),
root_subject_fns=_suba_root_subject_fns)
subgraph = graphmaker.generate_subgraph(SubA(), requested_product=A)
self.assert_equal_with_printing(dedent("""
{
root_subject_types: (SubA,)
root_rules:
Select(A) for SubA => ((Exactly(A), (SelectProjection(B, D, (u'some',), SubA),), noop) of SubA,)
all_rules:
(B, (Select(D),), noop) of D => (SubjectIsProduct(D),)
(Exactly(A), (SelectProjection(B, D, (u'some',), SubA),), noop) of SubA => (SubjectIsProduct(SubA), (B, (Select(D),), noop) of D,)
}""").strip(),
subgraph)