From 194f66cd0c7b4184ace0e1dcaa63349435997de3 Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Sun, 25 Feb 2024 22:36:18 -0500 Subject: [PATCH] pragma cover, and fall through non 200 errors --- ntclient/core/nnr2.py | 6 +++--- ntclient/persistence/__init__.py | 2 +- ntclient/persistence/sql/nt/__init__.py | 2 +- ntclient/services/api/__init__.py | 6 +++--- ntclient/services/bugs.py | 5 ++++- tests/test_cli.py | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ntclient/core/nnr2.py b/ntclient/core/nnr2.py index bfe769e..3e405d9 100644 --- a/ntclient/core/nnr2.py +++ b/ntclient/core/nnr2.py @@ -3,7 +3,7 @@ Created on Fri Jul 31 21:23:51 2020 @author: shane -""" -# NOTE: based on -# +NOTE: based on: + +""" diff --git a/ntclient/persistence/__init__.py b/ntclient/persistence/__init__.py index 167bf13..0110958 100644 --- a/ntclient/persistence/__init__.py +++ b/ntclient/persistence/__init__.py @@ -19,7 +19,7 @@ PREFS_FILE = os.path.join(NUTRA_HOME, "prefs.ini") os.makedirs(NUTRA_HOME, 0o755, exist_ok=True) -if not os.path.isfile(PREFS_FILE): +if not os.path.isfile(PREFS_FILE): # pragma: no cover print("INFO: Generating prefs.ini file") config = configparser.ConfigParser() with open(PREFS_FILE, "w", encoding="utf-8") as _prefs_file: diff --git a/ntclient/persistence/sql/nt/__init__.py b/ntclient/persistence/sql/nt/__init__.py index 9bb069d..a920991 100644 --- a/ntclient/persistence/sql/nt/__init__.py +++ b/ntclient/persistence/sql/nt/__init__.py @@ -40,7 +40,7 @@ def nt_init() -> None: ) print("..DONE!") os.remove(NTSQLITE_BUILDPATH) # clean up - else: + else: # pragma: no cover # TODO: is this logic (and these error messages) the best? # what if .isdir() == True ? Fails with stacktrace? os.rename(NTSQLITE_BUILDPATH, NTSQLITE_DESTINATION) diff --git a/ntclient/services/api/__init__.py b/ntclient/services/api/__init__.py index 0e3916f..c80e15b 100644 --- a/ntclient/services/api/__init__.py +++ b/ntclient/services/api/__init__.py @@ -34,7 +34,7 @@ def cache_mirrors() -> str: # TODO: save in persistence config.ini print(f"INFO: mirror SUCCESS '{mirror}'") return mirror - except requests.exceptions.ConnectionError: + except requests.exceptions.ConnectionError: # pragma: no cover print(f"WARN: mirror FAILURE '{mirror}'") return str() @@ -45,7 +45,7 @@ class ApiClient: def __init__(self) -> None: self.host = cache_mirrors() - if not self.host: + if not self.host: # pragma: no cover raise ConnectionError("Cannot find suitable API host!") def post(self, path: str, data: dict) -> requests.Response: @@ -55,7 +55,7 @@ class ApiClient: json=data, timeout=(REQUEST_CONNECT_TIMEOUT, REQUEST_READ_TIMEOUT), ) - _res.raise_for_status() + # _res.raise_for_status() return _res # TODO: move this outside class; support with host iteration helper method diff --git a/ntclient/services/bugs.py b/ntclient/services/bugs.py index e7d3114..b91b2f7 100644 --- a/ntclient/services/bugs.py +++ b/ntclient/services/bugs.py @@ -90,10 +90,13 @@ def submit_bugs() -> int: sql_nt("UPDATE bug SET submitted = 1 WHERE id = %s", bug.id) elif _res.status_code == 204: sql_nt("UPDATE bug SET submitted = 2 WHERE id = %s", bug.id) + else: + print("WARN: unknown status [{0}]".format(_res.status_code)) + continue print(".", end="", flush=True) n_submitted += 1 - print() + print("submitted: {0} bugs".format(n_submitted)) return n_submitted diff --git a/tests/test_cli.py b/tests/test_cli.py index 5064c45..2d687c8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -383,7 +383,7 @@ class TestCli(unittest.TestCase): new_version = ".".join([major, minor, new_release]) _usda_sql( "INSERT INTO version (version, created) VALUES (?,?)", - values=(new_version,datetime.datetime.utcnow()), + values=(new_version, datetime.datetime.utcnow()), version_check=False, ) -- 2.52.0