Skip to content

Commit

Permalink
Run tests with -O and -OO.
Browse files Browse the repository at this point in the history
  • Loading branch information
aebrahim committed Oct 28, 2023
1 parent 99e9f4a commit 7aa50b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
cache: pip
- run: pip install pytest
- run: pytest . --junitxml=junit/test_py${{ matrix.python-version }}_on_${{ matrix.os }}.xml
- run: python -O once_test.py
- run: python -OO once_test.py
- name: Upload pytest test results
uses: actions/upload-artifact@v3
if: success() || failure()
Expand Down
16 changes: 11 additions & 5 deletions once_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,16 +526,22 @@ def closure():
self.assertIsNone(ephemeral_ref())

def test_function_signature_preserved(self):
@once.once
def type_annotated_fn(arg: float) -> int:
"""Very descriptive docstring."""
del arg
return 1

sig = inspect.signature(type_annotated_fn)
self.assertIs(sig.parameters["arg"].annotation, float)
self.assertIs(sig.return_annotation, int)
self.assertEqual(type_annotated_fn.__doc__, "Very descriptive docstring.")
decorated_function = once.once(type_annotated_fn)
original_sig = inspect.signature(type_annotated_fn)
decorated_sig = inspect.signature(decorated_function)
self.assertIs(original_sig.parameters["arg"].annotation, float)
self.assertIs(decorated_sig.parameters["arg"].annotation, float)
self.assertIs(original_sig.return_annotation, int)
self.assertIs(decorated_sig.return_annotation, int)
self.assertEqual(inspect.getdoc(type_annotated_fn), inspect.getdoc(decorated_function))
if sys.flags.optimize >= 2:
self.skipTest("docstrings get stripped with -OO")
self.assertEqual(inspect.getdoc(type_annotated_fn), "Very descriptive docstring.")

def test_once_per_class(self):
class _CallOnceClass(Counter):
Expand Down

0 comments on commit 7aa50b1

Please sign in to comment.