From a7f0b43accc282105e0a7d7d51da9ffef50ea35a Mon Sep 17 00:00:00 2001 From: Jono Yang Date: Wed, 9 Sep 2020 11:15:06 -0700 Subject: [PATCH] Encode POM string to utf-8 before use * Add new test to ensure Pom objects can be created with strings Signed-off-by: Jono Yang --- pymaven/pom.py | 3 ++- tests/test_pom.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pymaven/pom.py b/pymaven/pom.py index 2cace70..679c678 100644 --- a/pymaven/pom.py +++ b/pymaven/pom.py @@ -420,7 +420,8 @@ def pom_data(self): creation time, use that client to fetch the POM artifact data remotely. """ if self._client is None: - return etree.fromstring(EMPTY_POM.format(self), parser=POM_PARSER) + _pom_data = EMPTY_POM.format(self) + return etree.fromstring(_pom_data.encode('utf-8'), parser=POM_PARSER) contents = self._client.get_artifact(self.coordinate).contents with contents as fh: diff --git a/tests/test_pom.py b/tests/test_pom.py index 83b37e9..67b5997 100644 --- a/tests/test_pom.py +++ b/tests/test_pom.py @@ -47,6 +47,25 @@ def _mock_client(self, *args): client.get_artifact.side_effect = side_effect return client + def test_fromstring_without_client(self): + """Test that a POM object can be created from a string without a client""" + pom = Pom.fromstring("foo:bar:1", FOO_BAR_1_POM) + assert pom.parent.group_id == "foo" + assert pom.parent.artifact_id == "parent" + assert pom.parent.version == "1" + assert pom.parent.properties["groupId"] == "foo" + assert pom.parent.properties["artifactId"] == "parent" + assert pom.parent.properties["version"] == "1" + assert pom.parent.properties["project.groupId"] == "foo" + assert pom.parent.properties["project.artifactId"] == "parent" + assert pom.parent.properties["project.version"] == "1" + assert pom.parent.properties["pom.groupId"] == "foo" + assert pom.parent.properties["pom.artifactId"] == "parent" + assert pom.parent.properties["pom.version"] == "1" + assert pom.properties["parent.groupId"] == "foo" + assert pom.properties["parent.artifactId"] == "parent" + assert pom.properties["parent.version"] == "1" + def test_parent(self): """Test pom parent processing""" client = self._mock_client(FOO_PARENT_1_POM)