Skip to content

Commit

Permalink
Add: Some logging for JavaCmd Class
Browse files Browse the repository at this point in the history
  • Loading branch information
y0urself committed Jul 20, 2023
1 parent 9477e95 commit 8aee258
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pontos/release/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

import logging
import subprocess
import sys
from typing import NoReturn
Expand All @@ -32,6 +33,8 @@ def main(
args=None,
) -> NoReturn:
username, token, parsed_args = parse_args(args)
logging.basicConfig(format="%(levelname)s - %(name)s - %(message)s")

if parsed_args.quiet:
term = NullTerminal()
else:
Expand Down
7 changes: 7 additions & 0 deletions pontos/version/commands/_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
import re
from pathlib import Path
from typing import Literal, Optional, Union
Expand Down Expand Up @@ -48,6 +49,7 @@ def find_file(
for file_path in search_path.glob(search_glob):
if file_path.is_file() and file_path.name == filename.name:
return file_path
logging.warning("File %s not found in %s.", filename.name, search_path)
return None


Expand All @@ -66,6 +68,11 @@ def replace_string_in_file(
file_path.write_text(
content.replace(match.group(1), replacement), encoding="utf-8"
)
logging.warning(
"Couldn't match the pattern %s in the content of %s.",
pattern,
file_path,
)


# This class is used for Java Version command(s)
Expand Down
28 changes: 25 additions & 3 deletions tests/version/commands/test_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,17 @@ def test_file_not_found(self):
filename = Path("NonExistentFile.java")
search_path = temp_dir
search_glob = "**/config/swagger/*"

result = find_file(filename, search_path, search_glob)
with self.assertLogs("root", level="WARNING") as cm:
result = find_file(filename, search_path, search_glob)
self.assertEqual(
cm.output,
[
(
f"WARNING:root:File {filename.name} not "
f"found in {search_path.resolve()}."
)
],
)

self.assertIsNone(result)

Expand Down Expand Up @@ -167,6 +176,8 @@ def test_no_valid_xml_in_pom(self):


class UpdateJavaVersionCommandTestCase(unittest.TestCase):
swagger_file = "SwaggerConfig.java"

def test_update_version_file(self):
content = """<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
Expand Down Expand Up @@ -201,9 +212,20 @@ def test_update_version_develop(self):
<artifactId>msspadminservice</artifactId><version>2023.5.3</version></project>"""

with temp_file(content, name="pom.xml", change_into=True) as temp:
swagger_search_path = Path("src").resolve()
cmd = JavaVersionCommand(PEP440VersioningScheme)
new_version = PEP440VersioningScheme.parse_version("2023.6.0.dev1")
updated = cmd.update_version(new_version)
with self.assertLogs("root", level="WARNING") as cm:
updated = cmd.update_version(new_version)
self.assertEqual(
cm.output,
[
(
f"WARNING:root:File {self.swagger_file} not "
f"found in {swagger_search_path.resolve()}."
)
],
)

self.assertEqual(
updated.previous,
Expand Down

0 comments on commit 8aee258

Please sign in to comment.