From 81e69c43c913f9024dd9144eee725855da43b105 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sat, 16 Apr 2022 23:39:52 +0200 Subject: [PATCH 1/2] TST: Run with -OO Flags --- .github/workflows/github-ci.yaml | 7 ++++++- .gitignore | 1 + PyPDF2/pdf.py | 6 ++++-- Tests/test_workflows.py | 3 ++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/github-ci.yaml b/.github/workflows/github-ci.yaml index 19ca30144..5d9ff7705 100644 --- a/.github/workflows/github-ci.yaml +++ b/.github/workflows/github-ci.yaml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10"] + python-version: ["2.7", "3.6", "3.7", "3.7.4", "3.8", "3.9", "3.10"] steps: - name: Checkout Code @@ -45,6 +45,11 @@ jobs: - name: Test with pytest run: | python -m coverage run --parallel-mode -m pytest Tests -vv + if: matrix.python-version != '3.7.4' + - name: Test with pytest + run: | + python -OO -m coverage run --parallel-mode -m pytest Tests -vv + if: matrix.python-version == '3.7.4' - name: Upload coverage data uses: actions/upload-artifact@v3 with: diff --git a/.gitignore b/.gitignore index 4a9c9ab80..e11314331 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ build .idea/* *.egg-info/ dist/* +__pycache__/ # .mutmut-cache diff --git a/PyPDF2/pdf.py b/PyPDF2/pdf.py index 29bedc28d..81da4a644 100644 --- a/PyPDF2/pdf.py +++ b/PyPDF2/pdf.py @@ -2261,7 +2261,8 @@ def rotateClockwise(self, angle): :param int angle: Angle to rotate the page. Must be an increment of 90 deg. """ - assert angle % 90 == 0 + if angle % 90 != 0: + raise ValueError("Rotation angle must be a multiple of 90") self._rotate(angle) return self @@ -2272,7 +2273,8 @@ def rotateCounterClockwise(self, angle): :param int angle: Angle to rotate the page. Must be an increment of 90 deg. """ - assert angle % 90 == 0 + if angle % 90 != 0: + raise ValueError("Rotation angle must be a multiple of 90") self._rotate(-angle) return self diff --git a/Tests/test_workflows.py b/Tests/test_workflows.py index 300430657..eb313fa8c 100644 --- a/Tests/test_workflows.py +++ b/Tests/test_workflows.py @@ -96,5 +96,6 @@ def test_rotate_45(): with open(os.path.join(RESOURCE_ROOT, "crazyones.pdf"), "rb") as inputfile: reader = PdfFileReader(inputfile) page = reader.getPage(0) - with pytest.raises(AssertionError): + with pytest.raises(ValueError) as exc: page.rotateCounterClockwise(45) + assert exc.value.args[0] == "Rotation angle must be a multiple of 90" From cc9b8146462dc1e22660f2edfccc62c4dbf19c70 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sat, 16 Apr 2022 23:41:48 +0200 Subject: [PATCH 2/2] Fix --- .github/workflows/github-ci.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/github-ci.yaml b/.github/workflows/github-ci.yaml index 5d9ff7705..6fe34071a 100644 --- a/.github/workflows/github-ci.yaml +++ b/.github/workflows/github-ci.yaml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["2.7", "3.6", "3.7", "3.7.4", "3.8", "3.9", "3.10"] + python-version: ["2.7", "3.6", "3.7", "3.10.1", "3.8", "3.9", "3.10"] steps: - name: Checkout Code @@ -45,11 +45,11 @@ jobs: - name: Test with pytest run: | python -m coverage run --parallel-mode -m pytest Tests -vv - if: matrix.python-version != '3.7.4' + if: matrix.python-version != '3.10.1' - name: Test with pytest run: | python -OO -m coverage run --parallel-mode -m pytest Tests -vv - if: matrix.python-version == '3.7.4' + if: matrix.python-version == '3.10.1' - name: Upload coverage data uses: actions/upload-artifact@v3 with: