Skip to content

Commit

Permalink
Return tuple instead of bool for better unit test report feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
fpadula committed Oct 17, 2024
1 parent 4661f47 commit 4be2436
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions test/test_ulimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,72 +29,72 @@ def setUp(self):

def _is_arg_translation_ok(self, mock_cliargs, expected):
is_ok = False
message_string = ""
try:
docker_args = self._instance.get_docker_args(
{self._instance.get_name(): [mock_cliargs]})
is_ok = docker_args == expected
print(f"DEBUG: Expected docker_args: {expected}")
print(f"DEBUG: Resulted docker_args: {docker_args}")
message_string = f"Expected: '{expected}', got: '{docker_args}'"
except ArgumentTypeError:
print("DEBUG: Incorrect argument format")
return is_ok
message_string = "Incorrect argument format"
return (is_ok, message_string)

def test_args_single_soft(self):
"""Test single soft limit argument."""
mock_cliargs = ["rtprio=99"]
expected = " --ulimit rtprio=99"
self.assertTrue(self._is_arg_translation_ok(mock_cliargs, expected))
self.assertTrue(*self._is_arg_translation_ok(mock_cliargs, expected))

def test_args_multiple_soft(self):
"""Test multiple soft limit arguments."""
mock_cliargs = ["rtprio=99", "memlock=102400"]
expected = " --ulimit rtprio=99 --ulimit memlock=102400"
self.assertTrue(self._is_arg_translation_ok(mock_cliargs, expected))
self.assertTrue(*self._is_arg_translation_ok(mock_cliargs, expected))

def test_args_single_hard(self):
"""Test single hard limit argument."""
mock_cliargs = ["nofile=1024:524288"]
expected = " --ulimit nofile=1024:524288"
self.assertTrue(self._is_arg_translation_ok(mock_cliargs, expected))
self.assertTrue(*self._is_arg_translation_ok(mock_cliargs, expected))

def test_args_multiple_hard(self):
"""Test multiple hard limit arguments."""
mock_cliargs = ["nofile=1024:524288", "rtprio=90:99"]
expected = " --ulimit nofile=1024:524288 --ulimit rtprio=90:99"
self.assertTrue(self._is_arg_translation_ok(mock_cliargs, expected))
self.assertTrue(*self._is_arg_translation_ok(mock_cliargs, expected))

def test_args_multiple_mix(self):
"""Test multiple mixed limit arguments."""
mock_cliargs = ["rtprio=99", "memlock=102400", "nofile=1024:524288"]
expected = " --ulimit rtprio=99 --ulimit memlock=102400 --ulimit nofile=1024:524288"
self.assertTrue(self._is_arg_translation_ok(mock_cliargs, expected))
self.assertTrue(*self._is_arg_translation_ok(mock_cliargs, expected))

def test_args_wrong_single_soft(self):
"""Test if single soft limit argument is wrong."""
mock_cliargs = ["rtprio99"]
expected = " --ulimit rtprio99"
self.assertFalse(self._is_arg_translation_ok(mock_cliargs, expected))
self.assertFalse(*self._is_arg_translation_ok(mock_cliargs, expected))

def test_args_wrong_multiple_soft(self):
"""Test if multiple soft limit arguments are wrong."""
mock_cliargs = ["rtprio=99", "memlock102400"]
expected = " --ulimit rtprio=99 --ulimit memlock=102400"
self.assertFalse(self._is_arg_translation_ok(mock_cliargs, expected))
self.assertFalse(*self._is_arg_translation_ok(mock_cliargs, expected))

def test_args_wrong_single_hard(self):
"""Test if single hard limit arguments are wrong."""
mock_cliargs = ["nofile=1024:524288:"]
expected = " --ulimit nofile=1024:524288"
self.assertFalse(self._is_arg_translation_ok(mock_cliargs, expected))
self.assertFalse(*self._is_arg_translation_ok(mock_cliargs, expected))

def test_args_wrong_multiple_hard(self):
"""Test if multiple hard limit arguments are wrong."""
mock_cliargs = ["nofile1024524288", "rtprio=90:99"]
expected = " --ulimit nofile=1024:524288 --ulimit rtprio=90:99"
self.assertFalse(self._is_arg_translation_ok(mock_cliargs, expected))
self.assertFalse(*self._is_arg_translation_ok(mock_cliargs, expected))

def test_args_wrong_multiple_mix(self):
"""Test if multiple mixed limit arguments are wrong."""
mock_cliargs = ["rtprio=:", "memlock102400", "nofile1024:524288:"]
expected = " --ulimit rtprio=99 --ulimit memlock=102400 --ulimit nofile=1024:524288"
self.assertFalse(self._is_arg_translation_ok(mock_cliargs, expected))
self.assertFalse(*self._is_arg_translation_ok(mock_cliargs, expected))

0 comments on commit 4be2436

Please sign in to comment.