Fix code smells

This commit is contained in:
Luke Tainton 2022-07-10 17:21:23 +01:00
parent 843b8d9fe1
commit 03092e16ee
No known key found for this signature in database
GPG Key ID: ABEE10849773E353
9 changed files with 16 additions and 9 deletions

View File

@ -18,7 +18,7 @@ jobs:
run: pip install -r requirements.txt && pip install -r requirements-dev.txt run: pip install -r requirements.txt && pip install -r requirements-dev.txt
- name: Run test suite - name: Run test suite
run: | run: |
coverage run -m py.test -v coverage run -m py.test -v --junitxml=testresults.xml
coverage xml coverage xml
- uses: sonarsource/sonarqube-scan-action@master - uses: sonarsource/sonarqube-scan-action@master
env: env:

View File

@ -23,10 +23,10 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: pip install -r requirements.txt && pip install -r requirements-dev.txt run: pip install -r requirements.txt && pip install -r requirements-dev.txt
- name: Lint - name: Lint
run: pylint --recursive=yes . run: pylint --recursive=yes --output-format=parseable --output=lintreport.txt .
- name: Run test suite - name: Run test suite
run: | run: |
coverage run -m py.test -v coverage run -m py.test -v --junitxml=testresults.xml
coverage xml coverage xml
- uses: sonarsource/sonarqube-scan-action@master - uses: sonarsource/sonarqube-scan-action@master
env: env:

2
.gitignore vendored
View File

@ -38,6 +38,8 @@ pip-log.txt
pip-delete-this-directory.txt pip-delete-this-directory.txt
# Unit test / coverage reports # Unit test / coverage reports
lintreport.txt
testresults.xml
htmlcov/ htmlcov/
.tox/ .tox/
.nox/ .nox/

View File

@ -1,4 +1,4 @@
# iPilot [![CI](https://github.com/luketainton/pypilot/actions/workflows/ci-branch-main.yml/badge.svg)](https://github.com/luketainton/pypilot/actions/workflows/ci-branch-main.yml) [![DeepSource](https://deepsource.io/gh/luketainton/pypilot.svg/?label=active+issues&show_trend=true&token=8utkyLrh7RPelvS-BNX1O8hZ)](https://deepsource.io/gh/luketainton/pypilot/?ref=repository-badge) # iPilot [![CI](https://github.com/luketainton/pypilot/actions/workflows/ci-branch-main.yml/badge.svg)](https://github.com/luketainton/pypilot/actions/workflows/ci-branch-main.yml) [![Quality Gate Status](https://sonarqube.tainton.uk/api/project_badges/measure?project=luketainton_pypilot_AYHo1eOKSbMjdyWLhHhP&metric=alert_status&token=squ_7c59ea8a624979cf8d8305ca4bbf18048df8145b)](https://sonarqube.tainton.uk/dashboard?id=luketainton_pypilot_AYHo1eOKSbMjdyWLhHhP)
## Description ## Description
IP Information Lookup Tool IP Information Lookup Tool

View File

@ -2,4 +2,4 @@
"""MODULE: Specifies app version.""" """MODULE: Specifies app version."""
VERSION = "1.2" VERSION = "1.2" # pragma: no cover

View File

@ -7,7 +7,7 @@ import argparse
from app.query_normalisation import get_public_ip from app.query_normalisation import get_public_ip
def parse_args() -> argparse.Namespace: def parse_args() -> argparse.Namespace: # pragma: no cover
"""Get arguments from user via the command line.""" """Get arguments from user via the command line."""
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Query information about an IP address or domain name." description="Query information about an IP address or domain name."

View File

@ -2,6 +2,8 @@
"""MODULE: Provides functions to call various APIs to retrieve IP/prefix information.""" """MODULE: Provides functions to call various APIs to retrieve IP/prefix information."""
from typing import Union
import ipaddress import ipaddress
import requests import requests
@ -24,7 +26,7 @@ def get_autonomous_system_number(as_info: str) -> str:
return as_number return as_number
def get_prefix_information(autonomous_system: int) -> list: def get_prefix_information(autonomous_system: int) -> Union[list, None]:
"""Retrieves prefix information about a given autonomous system.""" """Retrieves prefix information about a given autonomous system."""
api_endpoint = f"https://api.hackertarget.com/aslookup/?q={str(autonomous_system)}" api_endpoint = f"https://api.hackertarget.com/aslookup/?q={str(autonomous_system)}"
try: try:

View File

@ -2,10 +2,11 @@
"""MODULE: Provides functions for preparing, then printing, retrieved data.""" """MODULE: Provides functions for preparing, then printing, retrieved data."""
from typing import Union
from tabulate import tabulate from tabulate import tabulate
def generate_prefix_string(prefixes: list) -> str: def generate_prefix_string(prefixes: list) -> Union[str, None]:
"""Generate a string that spilts prefixes into rows of 4.""" """Generate a string that spilts prefixes into rows of 4."""
num_per_row = 4 num_per_row = 4
try: try:

View File

@ -1,6 +1,8 @@
sonar.projectKey=luketainton_pypilot_AYHo1eOKSbMjdyWLhHhP sonar.projectKey=luketainton_pypilot_AYHo1eOKSbMjdyWLhHhP
sonar.python.version=3.10 sonar.python.version=3.10
sonar.python.coverage.reportPaths=coverage.xml sonar.python.coverage.reportPaths=coverage.xml
sonar.python.pylint.reportPaths=lintreport.txt
sonar.python.xunit.reportPath=testresults.xml
sonar.sources=app sonar.sources=app
sonar.tests=tests sonar.tests=tests
sonar.exclusions=,.github/**,.gitignore,CODEOWNERS,CHANGELOG.md,LICENSE.md,README.md,renovate.json,requirements-dev.txt,requirements.txt sonar.exclusions=,.github/**,.gitignore,CODEOWNERS,CHANGELOG.md,LICENSE.md,README.md,renovate.json,requirements-dev.txt,requirements.txt