From 3b208c4d325e5741df6d799f0a1edec6676662c1 Mon Sep 17 00:00:00 2001 From: Luke Tainton Date: Sun, 10 Jul 2022 18:15:04 +0100 Subject: [PATCH 1/3] Add tests for app/print_table.py --- app/print_table.py | 2 +- tests/test_print_table.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/test_print_table.py diff --git a/app/print_table.py b/app/print_table.py index a4626f9..cbb8a74 100644 --- a/app/print_table.py +++ b/app/print_table.py @@ -18,6 +18,6 @@ def generate_prefix_string(prefixes: list) -> Union[str, None]: return None -def print_table(table_data) -> None: +def print_table(table_data) -> None: # pragma: no cover """Print table generated by tabulate.""" print(tabulate(table_data)) diff --git a/tests/test_print_table.py b/tests/test_print_table.py new file mode 100644 index 0000000..7610486 --- /dev/null +++ b/tests/test_print_table.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +"""MODULE: Provides test cases for app/print_table.py.""" + +from app.print_table import generate_prefix_string # pragma: no cover + + +def test_generate_prefix_string_small() -> None: + """TEST: Verifies if a small prefix list results in one line.""" + test_query = ["abc", "def"] + result = generate_prefix_string(prefixes=test_query) + assert result == "abc, def\n" + + +def test_generate_prefix_string_large() -> None: + """TEST: Verifies if a large prefix list results in multiple lines.""" + test_query = ["abc", "def", "ghi", "jkl", "mno", "pqr"] + result = generate_prefix_string(prefixes=test_query) + assert result == "abc, def, ghi, jkl\nmno, pqr\n" -- 2.47.2 From 7babd42cb397e56fc28327416dd1667edef887a0 Mon Sep 17 00:00:00 2001 From: Luke Tainton Date: Sun, 10 Jul 2022 18:21:23 +0100 Subject: [PATCH 2/3] Exclude app/version and app/args from coverage --- sonar-project.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/sonar-project.properties b/sonar-project.properties index d470a33..6dffefb 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -6,3 +6,4 @@ sonar.python.xunit.reportPath=testresults.xml sonar.sources=app sonar.tests=tests sonar.exclusions=,.github/**,.gitignore,CODEOWNERS,CHANGELOG.md,LICENSE.md,README.md,renovate.json,requirements-dev.txt,requirements.txt +sonar.coverage.exclusions=app/_version.py,app/args.py \ No newline at end of file -- 2.47.2 From bb99b573ddfd0e05b65282c6fc808c40dcba871c Mon Sep 17 00:00:00 2001 From: Luke Tainton Date: Sun, 10 Jul 2022 18:27:04 +0100 Subject: [PATCH 3/3] Remove app/main from coverage (just uses other modules) --- app/main.py | 2 +- sonar-project.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 150ce2e..b91a625 100644 --- a/app/main.py +++ b/app/main.py @@ -7,7 +7,7 @@ import sys from app.args import parse_args from app.print_table import print_table, generate_prefix_string from app.query_normalisation import is_ip_address, resolve_domain_name -from app.ip_info import ( # pragma: no cover +from app.ip_info import ( get_ip_information, get_autonomous_system_number, get_prefix_information, diff --git a/sonar-project.properties b/sonar-project.properties index 6dffefb..4ffb8ad 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -6,4 +6,4 @@ sonar.python.xunit.reportPath=testresults.xml sonar.sources=app sonar.tests=tests sonar.exclusions=,.github/**,.gitignore,CODEOWNERS,CHANGELOG.md,LICENSE.md,README.md,renovate.json,requirements-dev.txt,requirements.txt -sonar.coverage.exclusions=app/_version.py,app/args.py \ No newline at end of file +sonar.coverage.exclusions=app/_version.py,app/args.py,app/main.py -- 2.47.2