]> Nutra Git (v2) - nutratech/cli.git/commitdiff
pragma cover, and fall through non 200 errors
authorShane Jaroch <chown_tee@proton.me>
Mon, 26 Feb 2024 03:36:18 +0000 (22:36 -0500)
committerShane Jaroch <chown_tee@proton.me>
Mon, 26 Feb 2024 03:36:18 +0000 (22:36 -0500)
ntclient/core/nnr2.py
ntclient/persistence/__init__.py
ntclient/persistence/sql/nt/__init__.py
ntclient/services/api/__init__.py
ntclient/services/bugs.py
tests/test_cli.py

index bfe769ec010599294ba5dc623595d025c85f1c34..3e405d926859b3a1c030a1c49dc506a6e3ce66bb 100644 (file)
@@ -3,7 +3,7 @@
 Created on Fri Jul 31 21:23:51 2020
 
 @author: shane
-"""
 
-# NOTE: based on
-#   <https://en.wikipedia.org/wiki/Nutritional_rating_systems#Naturally_Nutrient_Rich>
+NOTE: based on:
+      <https://en.wikipedia.org/wiki/Nutritional_rating_systems#Naturally_Nutrient_Rich>
+"""
index 167bf1342f2de9536bf05769fcd036e9afb8f18f..0110958e69098f6fef99f7e88e79e740a39611e1 100644 (file)
@@ -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:
index 9bb069d67cdafd3551eb6ead431452e604730c2c..a920991c2f08b50456ddf7a31f1bcbdb66676d0d 100644 (file)
@@ -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)
index 0e3916ff319725862bc09df6e96b31ecc9cf6491..c80e15b0134461dc9a4337e57bad4bc10b9c8c0f 100644 (file)
@@ -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
index e7d31141e7451e524699598ee5b104b1d3acdc77..b91b2f754af8074afac85ce53bfd10771efaddd1 100644 (file)
@@ -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
index 5064c451bc4684e1571865095bcc98ffa253612c..2d687c8900892b85e2b132d05247d61192b07d5b 100644 (file)
@@ -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,
         )