]> Nutra Git (v1) - nutratech/cli.git/commitdiff
test bug
authorShane Jaroch <chown_tee@proton.me>
Sun, 25 Feb 2024 21:35:00 +0000 (16:35 -0500)
committerShane Jaroch <chown_tee@proton.me>
Sun, 25 Feb 2024 21:35:00 +0000 (16:35 -0500)
ntclient/argparser/__init__.py
ntclient/argparser/funcs.py
ntclient/services/bugs.py
tests/services/test_bug.py [new file with mode: 0644]
tests/test_cli.py

index 92060413c560b0da57b548127750bfaaa4107b63..87240d9e1ad73c066afc4123437dd678fe319ec0 100644 (file)
@@ -332,6 +332,14 @@ def build_subcommand_bug(subparsers: argparse._SubParsersAction) -> None:
     )
     bug_parser.set_defaults(func=parser_funcs.bugs_list)
 
+    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    # Simulate (bug)
+    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    bug_simulate_parser = bug_subparser.add_parser(
+        "simulate", help="simulate a bug (for testing purposes)"
+    )
+    bug_simulate_parser.set_defaults(func=parser_funcs.bug_simulate)
+
     # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     # Report (bug)
     # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
index abd0b70470c53c4e13d4aa956a8d8fe52283c2b1..782cb879d5292a6bb56e374c05d207104efa61f5 100644 (file)
@@ -338,8 +338,15 @@ def calc_lbm_limits(args: argparse.Namespace) -> tuple:
     return 0, result
 
 
+# pylint: disable=unused-argument
+def bug_simulate(args: argparse.Namespace) -> tuple:
+    """Simulate a bug report"""
+    ntclient.services.bugs.simulate_bug()
+    return 0, None
+
+
 def bugs_list(args: argparse.Namespace) -> tuple:
-    """List bug reports that have een saved"""
+    """List bug reports that have been saved"""
     _bugs_list = ntclient.services.bugs.list_bugs()
     n_bugs_total = len(_bugs_list)
     n_bugs_unsubmitted = len([x for x in _bugs_list if not bool(x[-1])])
index 9315b94a40f0b4db91fe567000bee29054cea149..63e2bfa9e69658232c277244bd2addaec209bbd4 100644 (file)
@@ -51,6 +51,11 @@ def list_bugs() -> list:
     return sql_bugs
 
 
+def simulate_bug() -> None:
+    """Simulate bug"""
+    raise NotImplementedError("This service intentionally raises an error, for testing")
+
+
 def submit_bugs() -> int:
     """Submit bug reports to developer, return n_submitted."""
 
diff --git a/tests/services/test_bug.py b/tests/services/test_bug.py
new file mode 100644 (file)
index 0000000..6f258c1
--- /dev/null
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Sun Feb 25 16:18:08 2024
+
+@author: shane
+"""
+import unittest
+
+import pytest
+
+from ntclient.__main__ import main
+from ntclient.services import bugs
+
+
+class TestBug(unittest.TestCase):
+    """Tests the bug service"""
+
+    def test_bug_simulate(self) -> None:
+        """Tests the functions for simulating a bug"""
+        with pytest.raises(NotImplementedError):
+            main(args=["--debug", "bug", "simulate"])
+
+    def test_bug_list(self) -> None:
+        """Tests the functions for listing bugs"""
+        bugs.list_bugs()
+
+    @unittest.expectedFailure
+    @pytest.mark.xfail(reason="Work in progress, need to get mocks working")
+    def test_bug_report(self) -> None:
+        """Tests the functions for submitting bugs"""
+        bugs.submit_bugs()
index e12fb5dc537f4d4014cd40c3a25ae08a3e3680eb..b07d017991dd11e76a1bb2477e68840eb743518e 100644 (file)
@@ -29,7 +29,7 @@ from ntclient.persistence.sql.nt.funcs import sql_nt_next_index
 from ntclient.persistence.sql.usda import funcs as usda_funcs
 from ntclient.persistence.sql.usda import sql as _usda_sql
 from ntclient.persistence.sql.usda import usda_ver
-from ntclient.services import bugs, init, usda
+from ntclient.services import init, usda
 from ntclient.services.recipe import RECIPE_HOME
 from ntclient.utils import CLI_CONFIG
 from ntclient.utils.exceptions import SqlInvalidVersionError
@@ -447,11 +447,3 @@ class TestCli(unittest.TestCase):
             _food_amts={1001: 100}, _food_analyses=analysis, _nutrients=nutrients
         )
         assert output
-
-    @unittest.expectedFailure
-    @pytest.mark.xfail(reason="Work in progress, need to get mocks working")
-    def test_1000_bugs(self):
-        """Tests the functions for listing and submitting bugs"""
-        bugs.list_bugs()
-        # TODO: this should be mocked
-        bugs.submit_bugs()