From 2bb3facd1095bc4d11ebf8bc69e3f6d89101c69e Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Thu, 7 Sep 2023 23:31:28 +0100 Subject: [PATCH 01/15] Added package flake8 to requirements.txt --- requirements.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/requirements.txt b/requirements.txt index 1b946d5..8f6605a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,15 @@ annotated-types==0.5.0 anyio==3.7.1 fastapi==0.101.1 +flake8==6.1.0 idna==3.4 +mccabe==0.7.0 numpy==1.25.2 pandas==2.0.3 +pycodestyle==2.11.0 pydantic==2.3.0 pydantic_core==2.6.3 +pyflakes==3.1.0 python-dateutil==2.8.2 pytz==2023.3 six==1.16.0 From 0554129370718fceca2733034648f626226686d4 Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Fri, 8 Sep 2023 00:22:04 +0100 Subject: [PATCH 02/15] Added function-to-be-test and the corresponding unit test --- funcs/func.py | 7 ++++++- tests/test_func.py | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/funcs/func.py b/funcs/func.py index 46d0d23..a49f0e4 100644 --- a/funcs/func.py +++ b/funcs/func.py @@ -1,2 +1,7 @@ def sum(x: float, y: float) -> float: - return x + y \ No newline at end of file + return x + y + +def misformatted_func( +var1, var2, var3 +): + print(var1, var2, var3) diff --git a/tests/test_func.py b/tests/test_func.py index 2d37034..6989460 100644 --- a/tests/test_func.py +++ b/tests/test_func.py @@ -1,4 +1,5 @@ import unittest +from unittest.mock import patch from funcs import func class Test(unittest.TestCase): @@ -6,5 +7,10 @@ class Test(unittest.TestCase): def test_sum(self): self.assertEqual(func.sum(2,3), 5) + @patch('funcs.func.misformatted_func') + def test_misformatted_func(self, mock_misformatted_func): + func.misformatted_func("one", "two", "three") + mock_misformatted_func.assert_called_with("one", "two", "three") + if __name__ == "__main__": unittest.main() \ No newline at end of file From fc188a75f2a65369abc094810c06cabf4df95265 Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Fri, 8 Sep 2023 00:23:05 +0100 Subject: [PATCH 03/15] Added check format step in github workflow --- .github/workflows/unit-test.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/unit-test.yaml b/.github/workflows/unit-test.yaml index e846e84..2b7f910 100644 --- a/.github/workflows/unit-test.yaml +++ b/.github/workflows/unit-test.yaml @@ -33,6 +33,10 @@ jobs: - name: Check if installed packages confirm with requirements.txt run: | pip freeze -r requirements.txt + + - name: Check format without making corrections + run: | + flake8 funcs/*.py - name: Run tests run: | From bd8c6e733267122fc2a0cea5e75393c9b1a2227e Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Fri, 8 Sep 2023 19:10:12 +0100 Subject: [PATCH 04/15] Updated GitHub CI workflow to only run on pull request. --- .github/workflows/unit-test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-test.yaml b/.github/workflows/unit-test.yaml index 2b7f910..f1c9bc9 100644 --- a/.github/workflows/unit-test.yaml +++ b/.github/workflows/unit-test.yaml @@ -1,8 +1,8 @@ name: Unit Test Linux on: - push: - # pull_request: + # push: + pull_request: jobs: run-tests: From ee222b257cd90a0f75b513d4a7dfbd4770785155 Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Mon, 18 Sep 2023 22:16:51 +0100 Subject: [PATCH 05/15] Backed up misformatted py file as .txt as example --- funcs/func_misformatted.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 funcs/func_misformatted.txt diff --git a/funcs/func_misformatted.txt b/funcs/func_misformatted.txt new file mode 100644 index 0000000..a49f0e4 --- /dev/null +++ b/funcs/func_misformatted.txt @@ -0,0 +1,7 @@ +def sum(x: float, y: float) -> float: + return x + y + +def misformatted_func( +var1, var2, var3 +): + print(var1, var2, var3) From a9ced0b49c7e2a82659ffa99215b836307600874 Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Mon, 18 Sep 2023 22:17:44 +0100 Subject: [PATCH 06/15] Updated py files formats according to flake8 --- funcs/__init__.py | 3 ++- funcs/func.py | 11 ++++++++--- tests/__init__.py | 3 ++- tests/test_func.py | 14 ++++++++++---- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/funcs/__init__.py b/funcs/__init__.py index 2b8e6eb..a9b1dd8 100644 --- a/funcs/__init__.py +++ b/funcs/__init__.py @@ -1 +1,2 @@ -# placeholder file to modularize (to package) .py files under the directory "funcs", making the files importable. \ No newline at end of file +# placeholder file to modularize (to package) .py files +# under the directory "funcs", making the files importable. diff --git a/funcs/func.py b/funcs/func.py index a49f0e4..436a0fd 100644 --- a/funcs/func.py +++ b/funcs/func.py @@ -1,7 +1,12 @@ def sum(x: float, y: float) -> float: return x + y -def misformatted_func( -var1, var2, var3 -): + +# def misformatted_func( +# var1, var2, var3 +# ): +# print(var1, var2, var3) + + +def corr_formatted_func(var1, var2, var3): print(var1, var2, var3) diff --git a/tests/__init__.py b/tests/__init__.py index 61d14e5..d35b63a 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1,2 @@ -# placeholder file to modularize (to package) .py files under the directory "tests", making the files importable. \ No newline at end of file +# placeholder file to modularize (to package) .py files +# under the directory "tests", making the files importable. diff --git a/tests/test_func.py b/tests/test_func.py index 6989460..f1f0123 100644 --- a/tests/test_func.py +++ b/tests/test_func.py @@ -7,10 +7,16 @@ class Test(unittest.TestCase): def test_sum(self): self.assertEqual(func.sum(2,3), 5) - @patch('funcs.func.misformatted_func') - def test_misformatted_func(self, mock_misformatted_func): - func.misformatted_func("one", "two", "three") - mock_misformatted_func.assert_called_with("one", "two", "three") + # Any misformatted functions would not pass flake8 format checks. All related tests would not be executed. + # @patch('funcs.func.misformatted_func') + # def test_misformatted_func(self, mock_misformatted_func): + # func.misformatted_func("one", "two", "three") + # mock_misformatted_func.assert_called_with("one", "two", "three") + + @patch('funcs.func.corr_formatted_func') + def test_corr_formatted_func(self, mock_corr_formatted_func): + func.corr_formatted_func("one", "two", "three") + mock_corr_formatted_func.assert_called_with("one", "two", "three") if __name__ == "__main__": unittest.main() \ No newline at end of file From 112fbc06af532a14dc7d9a156329c6bc51009261 Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Thu, 21 Sep 2023 20:05:50 +0100 Subject: [PATCH 07/15] Removed function and test for testing flake8 --- funcs/func.py | 6 ------ funcs/func_misformatted.txt | 7 ------- tests/test_func.py | 14 ++------------ 3 files changed, 2 insertions(+), 25 deletions(-) delete mode 100644 funcs/func_misformatted.txt diff --git a/funcs/func.py b/funcs/func.py index 436a0fd..2262e0a 100644 --- a/funcs/func.py +++ b/funcs/func.py @@ -2,11 +2,5 @@ def sum(x: float, y: float) -> float: return x + y -# def misformatted_func( -# var1, var2, var3 -# ): -# print(var1, var2, var3) - - def corr_formatted_func(var1, var2, var3): print(var1, var2, var3) diff --git a/funcs/func_misformatted.txt b/funcs/func_misformatted.txt deleted file mode 100644 index a49f0e4..0000000 --- a/funcs/func_misformatted.txt +++ /dev/null @@ -1,7 +0,0 @@ -def sum(x: float, y: float) -> float: - return x + y - -def misformatted_func( -var1, var2, var3 -): - print(var1, var2, var3) diff --git a/tests/test_func.py b/tests/test_func.py index f1f0123..0db8e65 100644 --- a/tests/test_func.py +++ b/tests/test_func.py @@ -7,16 +7,6 @@ class Test(unittest.TestCase): def test_sum(self): self.assertEqual(func.sum(2,3), 5) - # Any misformatted functions would not pass flake8 format checks. All related tests would not be executed. - # @patch('funcs.func.misformatted_func') - # def test_misformatted_func(self, mock_misformatted_func): - # func.misformatted_func("one", "two", "three") - # mock_misformatted_func.assert_called_with("one", "two", "three") - - @patch('funcs.func.corr_formatted_func') - def test_corr_formatted_func(self, mock_corr_formatted_func): - func.corr_formatted_func("one", "two", "three") - mock_corr_formatted_func.assert_called_with("one", "two", "three") - if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() + \ No newline at end of file From fd5a47c9145a45ae6f63c0e098ed1f43b9e7b3da Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Thu, 21 Sep 2023 20:14:28 +0100 Subject: [PATCH 08/15] Removed function and test for testing flake8 --- funcs/func.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/funcs/func.py b/funcs/func.py index 2262e0a..8d531d0 100644 --- a/funcs/func.py +++ b/funcs/func.py @@ -1,6 +1,2 @@ def sum(x: float, y: float) -> float: return x + y - - -def corr_formatted_func(var1, var2, var3): - print(var1, var2, var3) From 4b922de92cac9b0a8d0ef8c5526ae4ced75c5be1 Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Thu, 21 Sep 2023 20:18:32 +0100 Subject: [PATCH 09/15] Removed test packages in requirements.txt --- requirements.txt | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8f6605a..9fcfdc1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,19 +1,4 @@ -annotated-types==0.5.0 -anyio==3.7.1 -fastapi==0.101.1 -flake8==6.1.0 -idna==3.4 -mccabe==0.7.0 -numpy==1.25.2 -pandas==2.0.3 -pycodestyle==2.11.0 -pydantic==2.3.0 -pydantic_core==2.6.3 -pyflakes==3.1.0 -python-dateutil==2.8.2 -pytz==2023.3 -six==1.16.0 -sniffio==1.3.0 -starlette==0.27.0 -typing_extensions==4.7.1 -tzdata==2023.3 +distlib==0.3.6 +filelock==3.12.2 +platformdirs==3.8.0 +virtualenv==20.23.1 From 493c713272ff20f18db6588b70d5943d514a58fa Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Thu, 21 Sep 2023 20:30:34 +0100 Subject: [PATCH 10/15] Removed test packages in requirements.txt --- funcs/__init__.py | 3 +-- tests/__init__.py | 3 +-- tests/test_func.py | 6 +++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/funcs/__init__.py b/funcs/__init__.py index a9b1dd8..5a86c79 100644 --- a/funcs/__init__.py +++ b/funcs/__init__.py @@ -1,2 +1 @@ -# placeholder file to modularize (to package) .py files -# under the directory "funcs", making the files importable. +# placeholder file to modularize (to package) .py files under the directory "tests", making the files importable. diff --git a/tests/__init__.py b/tests/__init__.py index d35b63a..5a86c79 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,2 +1 @@ -# placeholder file to modularize (to package) .py files -# under the directory "tests", making the files importable. +# placeholder file to modularize (to package) .py files under the directory "tests", making the files importable. diff --git a/tests/test_func.py b/tests/test_func.py index 0db8e65..8618217 100644 --- a/tests/test_func.py +++ b/tests/test_func.py @@ -1,12 +1,12 @@ import unittest -from unittest.mock import patch from funcs import func + class Test(unittest.TestCase): def test_sum(self): - self.assertEqual(func.sum(2,3), 5) + self.assertEqual(func.sum(2, 3), 5) + if __name__ == "__main__": unittest.main() - \ No newline at end of file From 959be8840e12f16f3a1a9692bcc881a19a889eb8 Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Thu, 21 Sep 2023 20:54:03 +0100 Subject: [PATCH 11/15] Split workflows to different .yaml files, configured unit-test to be run only when linting return with success status, added setup.cfg for flake8 configuration --- .github/workflows/linting.yaml | 35 ++++++++++++++++++++++++++++++++ .github/workflows/unit-test.yaml | 13 +++++------- setup.cfg | 4 ++++ 3 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/linting.yaml create mode 100644 setup.cfg diff --git a/.github/workflows/linting.yaml b/.github/workflows/linting.yaml new file mode 100644 index 0000000..ed1bdac --- /dev/null +++ b/.github/workflows/linting.yaml @@ -0,0 +1,35 @@ +name: Linting Linux + +on: + # push: + pull_request: + +jobs: + run-tests: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + python-version: + - "3.11" + + name: linting + runs-on: ${{ matrix.os }} + # runs-on: python:alpine + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version : ${{ matrix.python-version }} + + - name: Install flake8 + run: | + python -m pip install flake8 + + - name: Check format without making corrections + run: | + flake8 diff --git a/.github/workflows/unit-test.yaml b/.github/workflows/unit-test.yaml index f1c9bc9..b3b688d 100644 --- a/.github/workflows/unit-test.yaml +++ b/.github/workflows/unit-test.yaml @@ -1,8 +1,10 @@ name: Unit Test Linux on: - # push: - pull_request: + workflow_run: + workflows: [Linting Linux] + types: + - completed jobs: run-tests: @@ -15,7 +17,7 @@ jobs: name: unit-test runs-on: ${{ matrix.os }} - # runs-on: python:alpine + if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: Checkout code @@ -33,12 +35,7 @@ jobs: - name: Check if installed packages confirm with requirements.txt run: | pip freeze -r requirements.txt - - - name: Check format without making corrections - run: | - flake8 funcs/*.py - name: Run tests run: | python -m unittest discover -v - diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..2aa0064 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[flake8] +max-line-length = 120 +exclude = + ./venv/ From 6e440a4d25c9604c6255c03f2e305b984356b7d7 Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Fri, 22 Sep 2023 14:50:50 +0100 Subject: [PATCH 12/15] Removed commented code --- .github/workflows/linting.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/linting.yaml b/.github/workflows/linting.yaml index ed1bdac..e6e48b8 100644 --- a/.github/workflows/linting.yaml +++ b/.github/workflows/linting.yaml @@ -1,7 +1,6 @@ name: Linting Linux on: - # push: pull_request: jobs: @@ -15,7 +14,6 @@ jobs: name: linting runs-on: ${{ matrix.os }} - # runs-on: python:alpine steps: - name: Checkout code From 17549da8b4c1816ba61e66f61f4594c6b2e043e4 Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Fri, 22 Sep 2023 15:11:32 +0100 Subject: [PATCH 13/15] Removed exclude= section in setup.cfg --- setup.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 2aa0064..6deafc2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,2 @@ [flake8] max-line-length = 120 -exclude = - ./venv/ From c6feadeeacac5c93be325f030be9323d1f4b5877 Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Sat, 23 Sep 2023 20:37:44 +0100 Subject: [PATCH 14/15] Excluded unnecessary directory in setup.cfg and added flake8 package in reqirements.txt for locally testing --- requirements.txt | 8 ++++---- setup.cfg | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 9fcfdc1..51a2c28 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -distlib==0.3.6 -filelock==3.12.2 -platformdirs==3.8.0 -virtualenv==20.23.1 +flake8==6.1.0 +mccabe==0.7.0 +pycodestyle==2.11.0 +pyflakes==3.1.0 diff --git a/setup.cfg b/setup.cfg index 6deafc2..66da313 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,10 @@ [flake8] max-line-length = 120 +exclude = + .git, + __pycache__, + docs/source/conf.py, + old, + build, + dist, + venv From 2041c5105bcfa2476f9a79141aafd08c6a171bde Mon Sep 17 00:00:00 2001 From: Ronald Fung Date: Sat, 23 Sep 2023 20:39:16 +0100 Subject: [PATCH 15/15] Updated workflow files --- .github/workflows/linting.yaml | 2 +- .github/workflows/unit-test.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linting.yaml b/.github/workflows/linting.yaml index e6e48b8..947de61 100644 --- a/.github/workflows/linting.yaml +++ b/.github/workflows/linting.yaml @@ -4,7 +4,7 @@ on: pull_request: jobs: - run-tests: + linting: strategy: fail-fast: false matrix: diff --git a/.github/workflows/unit-test.yaml b/.github/workflows/unit-test.yaml index b3b688d..4b7dbf2 100644 --- a/.github/workflows/unit-test.yaml +++ b/.github/workflows/unit-test.yaml @@ -7,7 +7,7 @@ on: - completed jobs: - run-tests: + unit-test: strategy: fail-fast: false matrix: