def test_property_discovery_no_properties(self): """Make sure we deal with no properties correctly.""" pom_path = get_test_path('java/junit-2.pom.xml') root = parse_xml_file(pom_path) properties = _get_pom_properties(root) assert len(properties) == 0
def test_parse_xml_file_no_namespace(self): """Make sure POMs with no namespaces parse correctly.""" path = get_test_path('java/junit-no-ns.pom.xml') root = parse_xml_file(path) assert root is not None assert root.tag() == 'project' assert root.namespace() == ''
def test_parse_pom_file_with_namespace(self): """Make sure POMs with namespaces parse correctly.""" pom_path = get_test_path('java/junit.pom.xml') root = parse_xml_file(pom_path) assert root is not None assert root.tag() == 'project' assert root.namespace() == '{http://maven.apache.org/POM/4.0.0}'
def test_find_existing_with_namespace(self): """Make sure we can find the first child with a particular tag and that they are properly wrapped.""" pom_path = get_test_path('java/junit.pom.xml') root = parse_xml_file(pom_path) version = root.find('modelVersion') assert version is not None assert isinstance(version, XmlElement) assert version.tag() == 'modelVersion'
def test_findall_with_namespace(self): """Make sure we can find all children and that they are properly wrapped.""" pom_path = get_test_path('java/junit.pom.xml') root = parse_xml_file(pom_path) properties = root.findall('properties') assert len(properties) == 1 assert isinstance(properties[0], XmlElement) assert properties[0].tag() == 'properties'
def test_element_subscripting(self): """Make sure we can subscript an element with children and that they are properly wrapped.""" pom_path = get_test_path('java/junit.pom.xml') root = parse_xml_file(pom_path) dependencies = root.find('dependencies') assert isinstance(dependencies, XmlElement) assert len(dependencies.children()) == 2 assert isinstance(dependencies[0], XmlElement) assert isinstance(dependencies[1], XmlElement)
def __init__(self, path: Path, context: DependencyContext): """ A function to create instances of the ``POMFile`` class. :param path: the path to the POM file. :param context: the dependency context to add dependencies to. """ self._root = parse_xml_file(path) self._properties = _get_pom_properties(self._root) self._imported = self._get_imported_dependencies(context) self._parent = self._get_parent(context) self._group_id = self._get_element_text(self._root.find('groupId')) self._version = self._get_element_text(self._root.find('version')) resolved_group_id = self.group_id resolved_version = self.version if resolved_group_id: self._properties['project.groupId'] = resolved_group_id if resolved_version: self._properties['project.version'] = resolved_version
def test_property_discovery_with_namespace(self): """Make sure we find properties in a POM with a namespace.""" pom_path = get_test_path('java/junit.pom.xml') root = parse_xml_file(pom_path) self._validate_properties(_get_pom_properties(root))
def test_find_missing_with_namespace(self): """Make sure we get None looking for a tag no child has, with namespace.""" pom_path = get_test_path('java/junit.pom.xml') root = parse_xml_file(pom_path) assert root.find('no-such-tag') is None