Skip to content

v2.0.x Chore - tests/test_usage.py #202

Closed
@reactive-firewall

Description

@reactive-firewall
tests/test_usage.py (4)

Line range hint 434-454: Consider enhancing test assertions for stdin functionality.

While the test successfully verifies basic execution, it could be more thorough by:

  1. Asserting the actual output matches the input
  2. Testing edge cases (empty input, very large input)
  3. Verifying the message was actually sent
 def test_say_works_WHEN_using_stdin(self):
     """Tests the basic send with streamed input test case."""
     theResult = False
     fail_fixture = str("""STDIN --> SAY == error""")
     _fixture_port_num = self._the_test_port
     try:
         say = multicast.send.McastSAY()
         self.assertIsNotNone(say)
         self.assertIsNotNone(_fixture_port_num)
         test_input = "Test message from stdin"
         self.assertIsNotNone(test_input)
         with patch('sys.stdin', io.StringIO(test_input)):
-            self.assertIsNotNone(say.doStep(data=['-'], group='224.0.0.1', port=_fixture_port_num))
+            result = say.doStep(data=['-'], group='224.0.0.1', port=_fixture_port_num)
+            self.assertIsNotNone(result)
+            # Verify the message was actually sent
+            self.assertTrue(result.success)  # Assuming there's a success indicator
+            self.assertEqual(result.sent_message, test_input)  # Verify message content
         theResult = True

217-218: Remove duplicate assertion.

The assertion self.assertNotEqual(int(tst_err_rslt_d), int(1)) is duplicated on consecutive lines.

-            self.assertNotEqual(int(tst_err_rslt_d), int(1))
-            self.assertNotEqual(int(tst_err_rslt_d), int(1))
+            self.assertNotEqual(int(tst_err_rslt_d), int(1))

706-774: Consider refactoring for improved maintainability.

The test method could benefit from:

  1. Extracting the command execution logic into a helper method
  2. Using constants for repeated strings
  3. Simplifying the string formatting
+    def _check_help_output(self, python_path, module_suffix, test_case):
+        """Helper method to check help output for a specific command combination."""
+        args = [
+            str(python_path),
+            "-m",
+            f"multicast{module_suffix}",
+            test_case.mode.format(test_case.command),
+            "--help"
+        ]
+        output = context.checkPythonCommand(args, stderr=subprocess.STDOUT)
+        if isinstance(output, bytes):
+            output = output.decode('utf8')
+        self.assertIsNotNone(output)
+        self.assertIn("usage:", output)
+        return "usage:" in output

     def test_Usage_Error_WHEN_the_help_sub_command_is_called(self):
         """Test case for validating help output of multicast sub-commands."""
         theResult = False
         fail_fixture = str("""multicast [HEAR|RECV] --help == not helpful""")
         try:
             TestCase = namedtuple("TestCase", ["mode", "command"])
             inner_fixtures = [
                 TestCase(mode="--daemon {}", command="HEAR"),
                 TestCase(mode="{}", command="HEAR"),
                 TestCase(mode="--daemon {}", command="RECV"),
                 TestCase(mode="{}", command="RECV"),
                 TestCase(mode="{}", command="SAY"),
                 TestCase(mode="{}", command="NOOP")
             ]
             if self._thepython is not None:
                 theResult = True
                 for module_suffix in [".__main__", ""]:
                     for test_case in inner_fixtures:
-                        self.assertIsInstance(test_case_i, TestCase)
-                        args = [
-                            str(self._thepython),
-                            str("-m"),
-                            str("multicast{}").format(str(test_case_o)),
-                            str(test_case_i.mode).format(str(test_case_i.command)),
-                            str("--help")
-                        ]
-                        theOutputtxt = context.checkPythonCommand(args, stderr=subprocess.STDOUT)
-                        # ... rest of the implementation
+                        theResult = self._check_help_output(
+                            self._thepython,
+                            module_suffix,
+                            test_case
+                        ) and theResult

Line range hint 840-862: Enhance test cases for invalid input testing.

Consider improving the test cases by:

  1. Using more diverse invalid inputs
  2. Removing the redundant integer test case
  3. Adding edge cases
-                for test_case in ["BAdInPut", int(1), "exit"]:
+                for test_case in [
+                    "BAdInPut",
+                    "exit",
+                    "@#$%",
+                    " ",
+                    "a" * 1000  # Very long input
+                ]:

Metadata

Metadata

Labels

ChoreMiscellaneous chores to maintain the projectMulticastAny main project file changesTestingSomething can be verifiedenhancementNew feature or request

Type

No type

Projects

Status

Archive Backlog

Relationships

None yet

Development

No branches or pull requests

Issue actions