diff --git a/tests/__init__.py b/tests/__init__.py index 1aaf48a..ee32c42 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -23,7 +23,10 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. + import logging +import time +from sys import version_info from os import mkdir try: @@ -32,6 +35,16 @@ pass fmt = logging.Formatter("[%(module)s] || %(asctime)s - %(levelname)s : %(module)s.%(funcName)s || %(message)s") + + +class ExceptionFilter(logging.Filter): + def filter(self, record: logging.LogRecord): + if record.msg.__repr__().__contains__("_AssertRaisesContext"): + return False + else: + return True + + ch = logging.StreamHandler() ch.setLevel(logging.CRITICAL) @@ -49,7 +62,12 @@ ch.setFormatter(logging.Formatter("%(message)s")) fh.setFormatter(logging.Formatter("%(message)s")) -logger.info("\033[1mTESTING STARTED\033[0m") - +logger.info( + "\033[1mTESTING STARTED -- Python Version: {pver.major}.{pver.minor}.{pver.micro} -- Time: {time}\033[0m".format( + pver = version_info, + time = time.asctime() + )) fh.setFormatter(fmt) -ch.setFormatter(fmt) \ No newline at end of file +ch.setFormatter(fmt) +fh.addFilter(ExceptionFilter()) +ch.addFilter(ExceptionFilter()) diff --git a/tests/test_events.py b/tests/test_events.py index 76a19c9..2945ea9 100644 --- a/tests/test_events.py +++ b/tests/test_events.py @@ -30,6 +30,8 @@ logger = logging.getLogger(__name__) +logger.info("test_events tests started") + class TestNoteOn(TestCase): def test_validate(self): @@ -41,8 +43,9 @@ def test_validate(self): "Generic MIDI NoteOn message shouldn't have validated, but did. Value was 0x{:x}".format( test_val) ) - + logger.info("NoteOn .valid test passed") def test_constructor(self): + logger.info("Starting NoteOn constructor tests") # Test constructor of generic version test_val = NoteOn(0x900000) match_val = { @@ -55,23 +58,46 @@ def test_constructor(self): self.assertEqual(vars(test_val), match_val, "MIDI NoteOn constructed from value 0x{:X} is incorrect".format(0x900000) ) + # --- Exception Testing --- # + logger.info("Starting NoteOn constructor exception tests") # Test Length Exceptions with self.assertRaises(LengthError, msg="NoteOn did not raise LengthError when given value 0x123001929391923919" ) as exc: NoteOn(0x123001929391923919) - + logger.exception(exc) with self.assertRaises(LengthError, msg="NoteOn did not raise LengthError when given value 0x1" ) as exc: NoteOn(0x1) - + logger.exception(exc) # Test validation exceptions with self.assertRaises(ValueError, msg="NoteOn given invalid data did not raise ValueError. Value was 0x290011" ) as exc: NoteOn(0x290011) + logger.exception(exc) + with self.assertRaises(ValueError, + msg="NoteOn given invalid data but did not raise ValueError. Value was 0x999999" + ) as exc: + NoteOn(0x899999) + logger.exception(exc) + # --- Parsing Testing --- # + logger.info("Starting NoteOn constructor parsing test") + for channel in range(0, 9): + channel_num = 0x900000 + (channel << 16) + logger.debug("Testing constructor with value {:x}".format(channel_num)) + obj = NoteOn(channel_num) + match_val = { + 'channel_number': channel, + 'note_name': 'C', + 'note_number': 0, + 'note_velocity': 0, + 'raw_data': channel_num + } + self.assertEqual(vars(obj), match_val, "When testing constructor of NoteOn with channel value: {}, " + "parsing failed".format(channel >> 16)) if __name__ == "__main__": nose2.main() diff --git a/tox.ini b/tox.ini index 3c8d982..4ab18b0 100644 --- a/tox.ini +++ b/tox.ini @@ -3,8 +3,6 @@ envlist = py30, py31, py33, py34, py35, py36, py37 [testenv] -depends = - nose2 -usedevelop=True -command = +deps = nose2 +commands = nose2 \ No newline at end of file