From 1522361a1b0a4b92eb7d3e5bd15152710d5ef3b1 Mon Sep 17 00:00:00 2001 From: Daniel Young Date: Tue, 23 Jul 2024 09:42:34 -0700 Subject: [PATCH 1/5] Added github actions for automatic linting and unit test running. Added dummy unit test --- .github/workflow/sdk.yml | 29 +++++++++++++++++ .pylintrc | 47 ++++++++++++++++++++++++++++ src/prsdk/dummy.py | 8 ++++- tests/{dummy_test.py => __init__.py} | 0 tests/test_dummy.py | 19 +++++++++++ 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 .github/workflow/sdk.yml create mode 100644 .pylintrc rename tests/{dummy_test.py => __init__.py} (100%) create mode 100644 tests/test_dummy.py diff --git a/.github/workflow/sdk.yml b/.github/workflow/sdk.yml new file mode 100644 index 0000000..1aa8e99 --- /dev/null +++ b/.github/workflow/sdk.yml @@ -0,0 +1,29 @@ +# This runs the unit tests for the ELUC use case + +name: SDK Workflow + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pylint + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with PyLint + run: pylint ./src/prsdk + - name: Run unit tests + run: python -m unittest + diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..cc0c717 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,47 @@ +# Note: +# This is a minimal subset of the options available for Pylint. +# To generate an exhaustive configuration file based on current settings and defaults, run the following command +# in the project directory: +# +# pylint --generate-rcfile > ~/.pylintrc + +[MASTER] + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=.git + +# Directories from top level that should be ignored. +ignore-paths=backend/grpc/generated,serving/adapter/grpc_gen/generated + +# Add files or directories matching the regex patterns to the blacklist. The +# regex matches against base names, not paths. +ignore-patterns= + +# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the +# number of processors available to use. +jobs=0 + +# Set reasonable line length +max-line-length=120 + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages. +suggestion-mode=yes + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once).You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use"--disable=all --enable=classes +# --disable=W" + +disable= + duplicate-code, + missing-module-docstring, + +# Default set of "always good" names +good-names=_ \ No newline at end of file diff --git a/src/prsdk/dummy.py b/src/prsdk/dummy.py index 6c6352c..a0a80d0 100644 --- a/src/prsdk/dummy.py +++ b/src/prsdk/dummy.py @@ -1,2 +1,8 @@ +""" +A dummy module to test the package. +""" def compute_percent_change(x: int) -> float: - return x / 100 \ No newline at end of file + """ + A function that divides an integer by 100 and returns a float. + """ + return x / 100 diff --git a/tests/dummy_test.py b/tests/__init__.py similarity index 100% rename from tests/dummy_test.py rename to tests/__init__.py diff --git a/tests/test_dummy.py b/tests/test_dummy.py new file mode 100644 index 0000000..a0d8065 --- /dev/null +++ b/tests/test_dummy.py @@ -0,0 +1,19 @@ +""" +Dummy test for the dummy module. +""" +import unittest + +from src.prsdk.dummy import compute_percent_change + +class TestDummy(unittest.TestCase): + """ + Tests for the dummy module. + """ + def test_pct_change(self): + """ + Tests the compute_percent_change function. + It should return the input divided by 100. + """ + self.assertEqual(compute_percent_change(100), 1.0) + self.assertEqual(compute_percent_change(50), 0.5) + self.assertEqual(compute_percent_change(0), 0.0) From 39fdda2cc87002b0e9348551d626750688e8d78b Mon Sep 17 00:00:00 2001 From: Daniel Young Date: Tue, 23 Jul 2024 09:45:19 -0700 Subject: [PATCH 2/5] Removed unnecessary pylint details --- .pylintrc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.pylintrc b/.pylintrc index cc0c717..b85288b 100644 --- a/.pylintrc +++ b/.pylintrc @@ -9,10 +9,10 @@ # Add files or directories to the blacklist. They should be base names, not # paths. -ignore=.git +ignore= # Directories from top level that should be ignored. -ignore-paths=backend/grpc/generated,serving/adapter/grpc_gen/generated +ignore-paths= # Add files or directories matching the regex patterns to the blacklist. The # regex matches against base names, not paths. @@ -40,8 +40,6 @@ suggestion-mode=yes # --disable=W" disable= - duplicate-code, - missing-module-docstring, # Default set of "always good" names good-names=_ \ No newline at end of file From a6d657cd2e7f152b68ca47cd6fbe6ef013a56043 Mon Sep 17 00:00:00 2001 From: Daniel Young Date: Tue, 23 Jul 2024 10:23:52 -0700 Subject: [PATCH 3/5] Added flake8 and updated files to match it --- .flake8 | 2 ++ src/prsdk/dummy.py | 2 ++ tests/test_dummy.py | 1 + 3 files changed, 5 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..79a16af --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 120 \ No newline at end of file diff --git a/src/prsdk/dummy.py b/src/prsdk/dummy.py index a0a80d0..f25aa72 100644 --- a/src/prsdk/dummy.py +++ b/src/prsdk/dummy.py @@ -1,6 +1,8 @@ """ A dummy module to test the package. """ + + def compute_percent_change(x: int) -> float: """ A function that divides an integer by 100 and returns a float. diff --git a/tests/test_dummy.py b/tests/test_dummy.py index a0d8065..a373282 100644 --- a/tests/test_dummy.py +++ b/tests/test_dummy.py @@ -5,6 +5,7 @@ from src.prsdk.dummy import compute_percent_change + class TestDummy(unittest.TestCase): """ Tests for the dummy module. From ab80492861dc1e16a1cd434635cd6e6686fe71f3 Mon Sep 17 00:00:00 2001 From: Daniel Young Date: Tue, 23 Jul 2024 10:33:38 -0700 Subject: [PATCH 4/5] Created requirements and added flake8 to the workflow --- .github/workflow/sdk.yml | 2 ++ requirements.txt | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 requirements.txt diff --git a/.github/workflow/sdk.yml b/.github/workflow/sdk.yml index 1aa8e99..3fcc407 100644 --- a/.github/workflow/sdk.yml +++ b/.github/workflow/sdk.yml @@ -24,6 +24,8 @@ jobs: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with PyLint run: pylint ./src/prsdk + - name: Lint with Flake8 + run: flake8 ./src/prsdk - name: Run unit tests run: python -m unittest diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c168880 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,40 @@ +astroid==3.2.4 +backports.tarfile==1.2.0 +build==1.2.1 +certifi==2024.7.4 +charset-normalizer==3.3.2 +dill==0.3.8 +docutils==0.21.2 +flake8==7.1.0 +idna==3.7 +importlib_metadata==8.0.0 +isort==5.13.2 +jaraco.classes==3.4.0 +jaraco.context==5.3.0 +jaraco.functools==4.0.1 +keyring==25.2.1 +markdown-it-py==3.0.0 +mccabe==0.7.0 +mdurl==0.1.2 +more-itertools==10.3.0 +nh3==0.2.18 +packaging==24.1 +pkginfo==1.10.0 +platformdirs==4.2.2 +prsdk==0.0.1 +pycodestyle==2.12.0 +pyflakes==3.2.0 +Pygments==2.18.0 +pylint==3.2.6 +pyproject_hooks==1.1.0 +readme_renderer==44.0 +requests==2.32.3 +requests-toolbelt==1.0.0 +rfc3986==2.0.0 +rich==13.7.1 +tomli==2.0.1 +tomlkit==0.13.0 +twine==5.1.1 +typing_extensions==4.12.2 +urllib3==2.2.2 +zipp==3.19.2 From 45357339fec8bc4936e90c6b1b90df7dc2fb21ff Mon Sep 17 00:00:00 2001 From: Daniel Young Date: Tue, 23 Jul 2024 14:15:45 -0700 Subject: [PATCH 5/5] Trimmed requirements --- requirements.txt | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/requirements.txt b/requirements.txt index c168880..afc149b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,40 +1,2 @@ -astroid==3.2.4 -backports.tarfile==1.2.0 -build==1.2.1 -certifi==2024.7.4 -charset-normalizer==3.3.2 -dill==0.3.8 -docutils==0.21.2 flake8==7.1.0 -idna==3.7 -importlib_metadata==8.0.0 -isort==5.13.2 -jaraco.classes==3.4.0 -jaraco.context==5.3.0 -jaraco.functools==4.0.1 -keyring==25.2.1 -markdown-it-py==3.0.0 -mccabe==0.7.0 -mdurl==0.1.2 -more-itertools==10.3.0 -nh3==0.2.18 -packaging==24.1 -pkginfo==1.10.0 -platformdirs==4.2.2 -prsdk==0.0.1 -pycodestyle==2.12.0 -pyflakes==3.2.0 -Pygments==2.18.0 -pylint==3.2.6 -pyproject_hooks==1.1.0 -readme_renderer==44.0 -requests==2.32.3 -requests-toolbelt==1.0.0 -rfc3986==2.0.0 -rich==13.7.1 -tomli==2.0.1 -tomlkit==0.13.0 -twine==5.1.1 -typing_extensions==4.12.2 -urllib3==2.2.2 -zipp==3.19.2 +pylint==3.2.6 \ No newline at end of file