diff --git a/.github/workflows/pythontest.yml b/.github/workflows/pythontest.yml index 4ea6d6ed0..b60db54ea 100644 --- a/.github/workflows/pythontest.yml +++ b/.github/workflows/pythontest.yml @@ -1,10 +1,6 @@ name: python-test -on: - push: - branches: [ $default-branch ] - pull_request: - branches: [ $default-branch ] +on: [push, pull_request] jobs: build: @@ -13,7 +9,8 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.10"] + python-code-path: ["salt/sensoroni/files/analyzers"] steps: - uses: actions/checkout@v3 @@ -24,14 +21,11 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install flake8 pytest + python -m pip install flake8 pytest pytest-cov 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 + flake8 ${{ matrix.python-code-path }} --count --select=E9,E501,F63,F7,F82,W191,W292 --show-source --max-complexity=10 --max-line-length=200 --statistics --doctests - name: Test with pytest run: | - pytest \ No newline at end of file + pytest ${{ matrix.python-code-path }} --cov=${{ matrix.python-code-path }} --doctest-modules --cov-report=term --cov-fail-under=90 --cov-config=${{ matrix.python-code-path }}/pytest.ini diff --git a/salt/sensoroni/files/analyzers/whois/whois.py b/salt/sensoroni/files/analyzers/whois/whois.py index c35e2f75b..dc739c8ba 100644 --- a/salt/sensoroni/files/analyzers/whois/whois.py +++ b/salt/sensoroni/files/analyzers/whois/whois.py @@ -1,5 +1,6 @@ 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__": - main() \ No newline at end of file + main() diff --git a/salt/sensoroni/files/analyzers/whois/whois_test.py b/salt/sensoroni/files/analyzers/whois/whois_test.py index aa27c5b95..d76962392 100644 --- a/salt/sensoroni/files/analyzers/whois/whois_test.py +++ b/salt/sensoroni/files/analyzers/whois/whois_test.py @@ -3,10 +3,11 @@ 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: + 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)