def roots(): for subject in subjects: for product in products: if type(subject) is Address: yield SelectNode(subject, product, None, None) elif type(subject) in [SingleAddress, SiblingAddresses, DescendantAddresses]: yield DependenciesNode(subject, product, None, Addresses, None) elif type(subject) is PathGlobs: yield DependenciesNode(subject, product, None, subject.ftype, None) else: raise ValueError('Unsupported root subject type: {}'.format(subject))
def test_sibling_specs(self): """Test that sibling Addresses are parsed in the 3rdparty/jvm directory.""" spec = self.spec_parser.parse_spec('3rdparty/jvm:') build_request = self.request_specs(['list'], spec) walk = self.build_and_walk(build_request) # Validate the root. root, root_state = walk[0] root_value = root_state.value self.assertEqual( DependenciesNode(spec, Address, None, Addresses, None), root) self.assertEqual(list, type(root_value)) # Confirm that an expected address is in the list. self.assertIn(self.guava, root_value) # And that an subdirectory address is not. self.assertNotIn(self.managed_guava, root_value)
def test_descendant_specs(self): """Test that Addresses are produced via recursive globs of the 3rdparty/jvm directory.""" spec = self.spec_parser.parse_spec('3rdparty/jvm::') build_request = self.request_specs(['list'], spec) walk = self.build_and_walk(build_request) # Validate the root. root, root_state = walk[0] root_value = root_state.value self.assertEqual( DependenciesNode(spec, Address, None, Addresses, None), root) self.assertEqual(list, type(root_value)) # Confirm that a few expected addresses are in the list. self.assertIn(self.guava, root_value) self.assertIn(self.managed_guava, root_value) self.assertIn(self.managed_resolve_latest, root_value)
def select_node(self, selector, subject, variants): """Constructs a Node for the given Selector and the given Subject/Variants. This method is decoupled from Selector classes in order to allow the `selector` package to not need a dependency on the `nodes` package. """ selector_type = type(selector) if selector_type is Select: return SelectNode(subject, selector.product, variants, None) elif selector_type is SelectVariant: return SelectNode(subject, selector.product, variants, selector.variant_key) elif selector_type is SelectDependencies: return DependenciesNode(subject, selector.product, variants, selector.deps_product, selector.field) elif selector_type is SelectProjection: return ProjectionNode(subject, selector.product, variants, selector.projected_subject, selector.fields, selector.input_product) elif selector_type is SelectLiteral: # NB: Intentionally ignores subject parameter to provide a literal subject. return SelectNode(selector.subject, selector.product, variants, None) else: raise ValueError('Unrecognized Selector type "{}" for: {}'.format(selector_type, selector))