Add automated CI for analyzers

This commit is contained in:
Jason Ertel
2022-03-29 13:10:04 -04:00
parent c23b87965f
commit 0a8d24a225
6 changed files with 63 additions and 7 deletions

37
.github/workflows/pythontest.yml vendored Normal file
View File

@@ -0,0 +1,37 @@
name: python-test
on:
push:
branches: [ $default-branch ]
pull_request:
branches: [ $default-branch ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest

6
.gitignore vendored
View File

@@ -56,4 +56,8 @@ $RECYCLE.BIN/
# Windows shortcuts # Windows shortcuts
*.lnk *.lnk
# End of https://www.gitignore.io/api/macos,windows # End of https://www.gitignore.io/api/macos,windows
# Pytest output
__pycache__
.coverage

View File

@@ -0,0 +1,8 @@
[pytest]
python_files = *_test.py
python_classes = Test
python_functions = test_*
[report]
exclude_lines =
if __name__ == .__main__.:

View File

@@ -1,5 +0,0 @@
def main():
print '{"foo":"bar","summary":"something here"}'
if __name__ == "__main__":
main()

View File

@@ -1,5 +1,5 @@
def main(): def main():
print '{"result":{ "requestId": "something-generated-by-whois", "someother_field": "more data" }, "summary": "botsrv.btc-goblin.ru"}' print('{"result":{ "requestId": "something-generated-by-whois", "someother_field": "more data" }, "summary": "botsrv.btc-goblin.ru"}')
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@@ -0,0 +1,12 @@
from io import StringIO
from unittest.mock import patch
from whois import whois
import unittest
class TestWhoisMethods(unittest.TestCase):
def test_main(self):
with patch('sys.stdout', new = StringIO()) as mock_stdout:
whois.main()
expected = '{"result":{ "requestId": "something-generated-by-whois", "someother_field": "more data" }, "summary": "botsrv.btc-goblin.ru"}\n'
self.assertEqual(mock_stdout.getvalue(), expected)