Skip to content

Commit

Permalink
Enable flake8 on the UT code (#241)
Browse files Browse the repository at this point in the history
Enable flake8 on the test/unit folder
Add it to github workflow for PR
Change flake8 requirements to avoid issue in Python 3.12 due to
PyCQA/flake8#1845
Fix some warnings in the test code.
  • Loading branch information
mpagot authored Jun 13, 2024
1 parent c48019e commit aad7551
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/gluescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ jobs:
run: tox -e flake8
env:
PLATFORM: ${{ matrix.platform }}
- name: flake8 test code with tox
working-directory: scripts/qesap/
run: |
tox -e flake8_test
env:
PLATFORM: ${{ matrix.platform }}
- name: UT tox
working-directory: scripts/qesap/
run: tox
Expand Down
2 changes: 1 addition & 1 deletion scripts/qesap/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
flake8==6.0.*
flake8>=6.0.*
flake8-bugbear==23.5.*
hypothesis==6.*
pylint==3.1.*
Expand Down
26 changes: 18 additions & 8 deletions scripts/qesap/test/unit/test_qesap_lib_cmd_ansible.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from unittest import mock
import logging
import os

Expand All @@ -9,18 +8,29 @@


def test_export_ansible_output():
'''
"""
Utility function that get the ansible command line and the command output.
Function calculate the log name by extracting the ansible playbook name from the command line.
Function take the content of out and write it to a file in the current directory
'''
"""

test_dir = os.getcwd()
test_file = os.path.join(test_dir, 'ansible.testAll.log.txt')
command_to_sent = {'test1':'test_value1', 'test2':'test_value2', 'test3':'test_value3', 'test4':'test_value4',
'cmd':['/tmp/exec_venv/bin/ansible', '-vvvv', '-i', '/root/qe-sap-deployment/terraform/aws/inventory.yaml',
'/some/immaginary/path/testAll.yaml', '-a', '--ssh-extra-args="-l cloudadmin -o UpdateHostKeys=yes -o StrictHostKeyChecking=accept-new"']}
test_file = os.path.join(test_dir, "ansible.testAll.log.txt")
command_to_sent = {
"test1": "test_value1",
"test2": "test_value2",
"test3": "test_value3",
"test4": "test_value4",
"cmd": [
"/tmp/exec_venv/bin/ansible",
"-vvvv",
"-i",
"/root/qe-sap-deployment/terraform/aws/inventory.yaml",
"/some/immaginary/path/testAll.yaml",
"-a",
'--ssh-extra-args="-l cloudadmin -o UpdateHostKeys=yes -o StrictHostKeyChecking=accept-new"',
],
}
ansible_output = """DEBUG OUTPUT: ansible [core 2.13.5]
DEBUG OUTPUT: config file = None
DEBUG OUTPUT: configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
Expand Down
2 changes: 1 addition & 1 deletion scripts/qesap/test/unit/test_qesap_lib_cmd_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ def test_cmd_terraform(subprocess_run, tmpdir):

assert ret == 0

subprocess_run.assert_has_calls(calls)
subprocess_run.assert_has_calls(calls)
8 changes: 5 additions & 3 deletions scripts/qesap/tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py39,py310,py311,flake8,pylint
envlist = py{39,310,311,312},flake8,pylint
skipsdist = True

[gh-actions]
Expand All @@ -11,11 +11,13 @@ python =

[testenv:flake8]
deps = -r{toxinidir}/requirements-dev.txt
commands = flake8 qesap.py lib/
commands = flake8 --version
flake8 qesap.py lib/

[testenv:flake8_test]
deps = -r{toxinidir}/requirements-dev.txt
commands = flake8 test/
commands = flake8 --version
flake8 test/

[testenv:pylint]
deps = -r{toxinidir}/requirements-dev.txt
Expand Down

0 comments on commit aad7551

Please sign in to comment.