Skip to content

Commit

Permalink
[TESTS] refactor a bit of the testing names
Browse files Browse the repository at this point in the history
  • Loading branch information
reactive-firewall committed Feb 21, 2022
1 parent b7fae81 commit 71a909c
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 61 deletions.
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

__module__ = """tests"""

__name__ = """tests"""

__doc__ = """Multicast Testing Module.
Expand Down
59 changes: 46 additions & 13 deletions tests/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
>>> from context import os as os
>>>
>>> from context import unittest as unittest
>>> from context import unittest as _unittest
>>>
>>> from context import subprocess as subprocess
>>> from context import subprocess as _subprocess
>>>
>>> from context import multicast as multicast
>>> from context import multicast as _multicast
>>>
>>> from context import profiling as profiling
>>> from context import profiling as _profiling
>>>
"""
Expand Down Expand Up @@ -101,6 +101,32 @@
raise ImportError("[CWE-440] profiling Failed to import.")


__BLANK = str("""""")
"""
A literaly named variable to improve readability of code when using a blank string.
Meta Testing:
First setup test fixtures by importing test context.
>>> import tests.context as _context
>>>
Testcase 1: __BLANK should be a blank string.
>>> import tests.context as _context
>>> _context.__BLANK is None
False
>>> isinstance(_context.__BLANK, type(str()))
True
>>> len(_context.__BLANK) == int(0)
True
>>>
"""


def getCoverageCommand():
"""
Function for backend coverage command.
Expand Down Expand Up @@ -131,9 +157,9 @@ def getCoverageCommand():
thecov = str("coverage")
elif str("/coverage3") in str(checkPythonCommand(["command", "-v", "coverage3"])):
thecov = str("coverage3")
else:
else: # pragma: no branch
thecov = "exit 1 ; #"
except Exception:
except Exception: # pragma: no branch
thecov = "exit 1 ; #"
return str(thecov)

Expand Down Expand Up @@ -172,7 +198,7 @@ def __check_cov_before_py():
thecov = getCoverageCommand()
if (str("coverage") in str(thecov)) and (sys.version_info >= (3, 7)):
thepython = str("{} run -p").format(str(thecov))
else:
else: # pragma: no branch
try:
import coverage as coverage
if coverage.__name__ is not None:
Expand Down Expand Up @@ -205,7 +231,7 @@ def getPythonCommand():
thepython = "python"
try:
thepython = __check_cov_before_py()
except Exception:
except Exception: # pragma: no branch
thepython = "exit 1 ; #"
try:
thepython = str(sys.executable)
Expand All @@ -216,16 +242,16 @@ def getPythonCommand():

def checkCovCommand(args=[None]):
"""Utility Function."""
if sys.__name__ is None:
if sys.__name__ is None: # pragma: no branch
raise ImportError("[CWE-758] Failed to import system. WTF?!!")
if str("coverage") in args[0]:
i = 0
if str("{} -m coverage").format(str(sys.executable)) in str(args[0]):
if str("{} -m coverage").format(str(sys.executable)) in str(args[0]): # pragma: no branch
args[0] = str(sys.executable)
args.insert(1, str("-m"))
args.insert(2, str("coverage"))
i = 2
else:
else: # pragma: no branch
args[0] = str(getCoverageCommand())
args.insert(i + 1, str("run"))
args.insert(i + 2, str("-p"))
Expand All @@ -248,13 +274,13 @@ def checkPythonCommand(args=[None], stderr=None):
"""function for backend subprocess check_output command"""
theOutput = None
try:
if args is None or args is [None]:
if args is None or args is [None]: # pragma: no branch
theOutput = subprocess.check_output(["exit 1 ; #"])
else:
if str("coverage") in args[0]:
args = checkCovCommand(args)
theOutput = subprocess.check_output(args, stderr=stderr)
except Exception as err:
except Exception as err: # pragma: no branch
theOutput = None
try:
if err.output is not None:
Expand Down Expand Up @@ -498,6 +524,13 @@ def test_absolute_truth_and_meaning(self):
assert True
self.assertTrue(True, "Insanitty Test Failed")

def test_finds_python_WHEN_testing(self):
"""Test case 0: Class Test-Fixture Meta Test."""
self.test_absolute_truth_and_meaning()
if (self._thepython is None) and (len(self._thepython) <= 0):
self.fail(str("""No python cmd to test with!"""))
self.test_absolute_truth_and_meaning()

@classmethod
def tearDownClass(cls):
"""Overides unittest.TestCase.tearDownClass(cls) to clean up thepython test fixture."""
Expand Down
4 changes: 2 additions & 2 deletions tests/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def profiled_func(*args, **kwargs):
return profiled_func
return inner

except ImportError:
except ImportError: # pragma: no branch
def do_profile(follow=None):
"Helpful if you accidentally leave in production!"
if follow is None:
Expand All @@ -178,7 +178,7 @@ def main(argv=None):
raise NotImplementedError("CRITICAL - test profiling main() not implemented. yet?")


if __name__ in '__main__':
if __name__ in '__main__': # pragma: no branch
exitcode = 3
try:
exitcode = main(sys.argv[1:])
Expand Down
24 changes: 13 additions & 11 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
raise ImportError("[CWE-758] Failed to import context")
else:
from context import unittest as unittest
except Exception:
except Exception: # pragma: no branch
raise ImportError("[CWE-758] Failed to import test context")


Expand All @@ -54,13 +54,15 @@ def test_absolute_truth_and_meaning(self):
"""Insanitty Test 1: Because it only matters if we're not mad as hatters."""
assert True

def test_meta_test(self):
def test_Does_Pass_WHEN_Meta_Test(self):
"""Insanity Test 2: for unittests assertion."""
self.assertTrue(True)
self.assertFalse(False)
self.assertIsNone(None)
self.test_absolute_truth_and_meaning()
self.test_None_WHEN_Nothing()

def test_syntax(self):
def test_Does_Pass_WHEN_Using_Import_From_Syntax(self):
"""Test case 0: importing multicast."""
theResult = False
try:
Expand All @@ -73,10 +75,10 @@ def test_syntax(self):
print(str(type(impErr)))
print(str(impErr))
theResult = False
assert theResult
self.assertTrue(theResult)

def test_the_help_command(self):
"""Test case 1: import for backend library."""
def test_Error_WHEN_the_help_command_is_called(self):
"""Test case 1: the --help options should error when called."""
theResult = False
try:
from .context import multicast
Expand All @@ -90,9 +92,9 @@ def test_the_help_command(self):
theResult = True
except Exception:
theResult = False
assert theResult
self.assertTrue(theResult)

def test_corner_case_example(self):
def test_IsNone_WHEN_given_corner_case_input(self):
"""Example Test case for bad input directly into function."""
theResult = False
try:
Expand All @@ -105,15 +107,15 @@ def test_corner_case_example(self):
theResult = True
except Exception:
theResult = False
assert theResult
self.assertTrue(theResult)

def test_new_tests(self):
def test_None_WHEN_Nothing(self):
"""Try adding new tests."""
self.assertIsNone(None)
# define new tests below

@unittest.skipUnless(sys.platform.startswith("linux"), "This test example requires linux")
def test_this_linux_only(self):
def test_Skip_UNLESS_linux_only(self):
"""Linux is the test."""
self.assertTrue(sys.platform.startswith("linux"))

Expand Down
Loading

0 comments on commit 71a909c

Please sign in to comment.