From 3eed64b272912eaccfc9b5f167ebe56ecfa3af42 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Thu, 27 Feb 2025 14:57:33 +0100 Subject: [PATCH] Fixed tests --- standardize_test_format/__init__.py | 4 ++-- standardize_test_format/__main__.py | 1 + test/test_standardize.py | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/standardize_test_format/__init__.py b/standardize_test_format/__init__.py index 41e49db..4936dfd 100644 --- a/standardize_test_format/__init__.py +++ b/standardize_test_format/__init__.py @@ -6,7 +6,7 @@ Tool for standardizing Java tests. import re TEST_PATTERN: re.Pattern = re.compile( - r'(?:/\*\*(?P.*)\*/)\s*' + r'(?:/\*\*(?P.*)\*/)?\s*' + r'@(?PTest|BeforeEach|ParameterizedTest)\s*' + r'(?:@DisplayName\("(?P.*)"\)\s*)?' + r'(?Ppublic\s+|private\s+)?void\s+(?P\w+)\(', re.IGNORECASE) @@ -47,7 +47,7 @@ def from_camel_case(name: str) -> str: return name def replace_test_pattern(match: re.Match) -> str: - comment = match.group('comment').strip() + comment = (match.group('comment') or '').strip() annotation = match.group('annotation').strip() visibility = (match.group('visibility') or '').strip() name = match.group('name').strip() diff --git a/standardize_test_format/__main__.py b/standardize_test_format/__main__.py index 973e974..b5f2e62 100644 --- a/standardize_test_format/__main__.py +++ b/standardize_test_format/__main__.py @@ -15,6 +15,7 @@ def standardize_in_file(path: pathlib.Path): if False: with open(path, 'w') as f: f.write(text) + def main(): argparser = argparse.ArgumentParser() argparser .add_argument('repo', type=pathlib.Path) diff --git a/test/test_standardize.py b/test/test_standardize.py index 93478f3..90db156 100644 --- a/test/test_standardize.py +++ b/test/test_standardize.py @@ -11,7 +11,7 @@ public void selectInvocationWithoutPermission() { } OUTPUT_1 = """ @Test @DisplayName("Invocations fail with callers without required permissions") -public void selectInvocationWithoutPermission() { } +public void invocationsFailWithCallersWithoutRequiredPermissions() { } """ INPUT_2 = """ @@ -23,13 +23,13 @@ public void selectInvocationWithoutPermission() { } OUTPUT_2 = """ @Test @DisplayName("Invocations fail with callers without required permissions") -public void selectInvocationWithoutPermission() { } +public void invocationsFailWithCallersWithoutRequiredPermissions() { } """ def test_1(): - assert standardize_java_text(INPUT_1) == OUTPUT_1 + assert standardize_java_text(INPUT_1.strip()) == OUTPUT_1.strip() def test_2(): - assert standardize_java_text(INPUT_2) == OUTPUT_2 + assert standardize_java_text(INPUT_2.strip()) == OUTPUT_2.strip()