From: Shane Jaroch Date: Sun, 25 Feb 2024 21:35:00 +0000 (-0500) Subject: test bug X-Git-Tag: v0.2.8.dev0~11 X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=7907280863d146c74a5e15f398c1604d87671354;p=nutratech%2Fcli.git test bug --- diff --git a/ntclient/argparser/__init__.py b/ntclient/argparser/__init__.py index 9206041..87240d9 100644 --- a/ntclient/argparser/__init__.py +++ b/ntclient/argparser/__init__.py @@ -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) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/ntclient/argparser/funcs.py b/ntclient/argparser/funcs.py index abd0b70..782cb87 100644 --- a/ntclient/argparser/funcs.py +++ b/ntclient/argparser/funcs.py @@ -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])]) diff --git a/ntclient/services/bugs.py b/ntclient/services/bugs.py index 9315b94..63e2bfa 100644 --- a/ntclient/services/bugs.py +++ b/ntclient/services/bugs.py @@ -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 index 0000000..6f258c1 --- /dev/null +++ b/tests/services/test_bug.py @@ -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() diff --git a/tests/test_cli.py b/tests/test_cli.py index e12fb5d..b07d017 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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()