Repository: Neoteroi/BlackSheep
Pull request #471 (2024-01-19 22:32:49)

Fix Google dialect match regexp
Update tests to verify is_match for docstring dialects

codecov-commenter: ## [Codecov](https://app.codecov.io/gh/Neoteroi/BlackSheep/pull/471?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`f034f6a`)](https://app.codecov.io/gh/Neoteroi/BlackSheep/commit/f034f6ae16e71e0d65779578d8ed66f3be6db03b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi) 96.39% compared to head [(`cf9e53f`)](https://app.codecov.io/gh/Neoteroi/BlackSheep/pull/471?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi) 96.39%.


:exclamation: Your organization needs to install the [Codecov GitHub app](https://github.com/apps/codecov/installations/select_target) to enable full functionality.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main     #471   +/-   ##
=======================================
  Coverage   96.39%   96.39%           
=======================================
  Files          69       69           
  Lines        6487     6487           
=======================================
  Hits         6253     6253           
  Misses        234      234           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/Neoteroi/BlackSheep/pull/471?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi).


Patch:
diff --git a/blacksheep/server/openapi/docstrings.py b/blacksheep/server/openapi/docstrings.py
index 3afd446..a333d68 100644
--- a/blacksheep/server/openapi/docstrings.py
+++ b/blacksheep/server/openapi/docstrings.py
@@ -409,7 +409,7 @@ class NumpydocDialect(IndentDocstringDialect):
 
 class GoogleDocDialect(IndentDocstringDialect):
     def is_match(self, docstring: str) -> bool:
-        return re.search(r"^([\s\t]*Args:?)", docstring) is not None
+        return re.search(r"^([\s\t]*Args:?)", docstring, re.M) is not None
 
     _sections = {"Args", "Returns", "Raises"}
 


Test patch:
diff --git a/tests/test_openapi_docstrings.py b/tests/test_openapi_docstrings.py
index 2dd2bab..b5a8c9d 100644
--- a/tests/test_openapi_docstrings.py
+++ b/tests/test_openapi_docstrings.py
@@ -14,7 +14,7 @@ from blacksheep.server.openapi.docstrings import (
 
 
 @pytest.mark.parametrize(
-    "docstring,expected_info",
+    "docstring,expected_info,match",
     [
         (
             """
@@ -33,6 +33,7 @@ from blacksheep.server.openapi.docstrings import (
                     "c": ParameterInfo("list of str", value_type=List[str]),
                 },
             ),
+            True,
         ),
         (
             """
@@ -54,6 +55,7 @@ from blacksheep.server.openapi.docstrings import (
                     "c": ParameterInfo("list of str", value_type=List[str]),
                 },
             ),
+            True,
         ),
         (
             """
@@ -88,6 +90,7 @@ from blacksheep.server.openapi.docstrings import (
                 return_type=float,
                 return_description="the x intercept of the line M{y=m*x+b}.",
             ),
+            True,
         ),
         (
             """
@@ -124,6 +127,7 @@ from blacksheep.server.openapi.docstrings import (
                 return_type=float,
                 return_description="the x intercept of the line M{y=m*x+b}.",
             ),
+            True,
         ),
         (
             """
@@ -141,6 +145,7 @@ from blacksheep.server.openapi.docstrings import (
                 return_type=None,
                 return_description=None,
             ),
+            True,
         ),
         (
             """
@@ -160,6 +165,7 @@ from blacksheep.server.openapi.docstrings import (
                 return_type=None,
                 return_description=None,
             ),
+            True,
         ),
         (
             """
@@ -179,6 +185,7 @@ from blacksheep.server.openapi.docstrings import (
                 return_type=None,
                 return_description=None,
             ),
+            True,
         ),
         (
             """
@@ -198,6 +205,7 @@ from blacksheep.server.openapi.docstrings import (
                 },
                 return_description="this is a description of what is returned",
             ),
+            True,
         ),
         (
             """
@@ -228,11 +236,13 @@ from blacksheep.server.openapi.docstrings import (
                 ),
                 parameters={},
             ),
+            False,
         ),
     ],
 )
-def test_epytext_dialect(docstring, expected_info):
+def test_epytext_dialect(docstring, expected_info, match):
     dialect = EpytextDialect()
+    assert dialect.is_match(docstring) is match
 
     info = dialect.parse_docstring(docstring)
     assert expected_info == info
@@ -371,13 +381,14 @@ def test_epytext_dialect(docstring, expected_info):
 )
 def test_rest_dialect(docstring, expected_info):
     dialect = ReStructuredTextDialect()
+    assert dialect.is_match(docstring)
 
     info = dialect.parse_docstring(docstring)
     assert expected_info == info
 
 
 @pytest.mark.parametrize(
-    "docstring,expected_info",
+    "docstring,expected_info,match",
     [
         (
             """
@@ -424,6 +435,7 @@ def test_rest_dialect(docstring, expected_info):
                 return_type=str,
                 return_description="a value in a string",
             ),
+            True,
         ),
         (
             """
@@ -447,6 +459,7 @@ def test_rest_dialect(docstring, expected_info):
                     "c": ParameterInfo("list of str", value_type=List[str]),
                 },
             ),
+            True,
         ),
         (
             """
@@ -492,6 +505,7 @@ def test_rest_dialect(docstring, expected_info):
                 return_type=None,
                 return_description=None,
             ),
+            True,
         ),
         (
             """
@@ -538,6 +552,7 @@ def test_rest_dialect(docstring, expected_info):
                 return_type=str,
                 return_description="a value in a string",
             ),
+            True,
         ),
         (
             """
@@ -578,6 +593,7 @@ def test_rest_dialect(docstring, expected_info):
                 return_type=str,
                 return_description="a value in a string",
             ),
+            True,
         ),
         (
             """
@@ -592,11 +608,13 @@ def test_rest_dialect(docstring, expected_info):
                 description="Lorem ipsum dolor sit amet.",
                 parameters={},
             ),
+            False,
         ),
     ],
 )
-def test_numpydoc_dialect(docstring, expected_info):
+def test_numpydoc_dialect(docstring, expected_info, match):
     dialect = NumpydocDialect()
+    assert dialect.is_match(docstring) is match
 
     info = dialect.parse_docstring(docstring)
     assert expected_info == info
@@ -777,6 +795,7 @@ def test_googledoc_dialect_warns_about_invalid_parameter():
 )
 def test_googledoc_dialect(docstring, expected_info):
     dialect = GoogleDocDialect()
+    assert dialect.is_match(docstring)
 
     info = dialect.parse_docstring(docstring)
     assert expected_info == info