Skip to content

Commit

Permalink
Added a load of logging stuff for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroTransactionsMatterToo committed Aug 28, 2017
1 parent ee36070 commit 8fe1721
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 5 deletions.
3 changes: 1 addition & 2 deletions midisnake/structure.py
Expand Up @@ -50,7 +50,7 @@ class Header:
division = None # type: float


class Event(metaclass=ABCMeta):
class Event(metaclass=ABCMeta): # pragma: no
"""
Metaclass representing a MIDI Event. Subclasses must implement the :func:`~_process` function
Expand All @@ -75,7 +75,6 @@ def __init__(self, data: int) -> None:
err_msg = "{} given invalid data".format(type(self).__name__)
raise ValueError(err_msg)


def __repr__(self) -> str:
return "<MIDIEvent: {}>".format(self.event_name)

Expand Down
55 changes: 55 additions & 0 deletions tests/__init__.py
@@ -0,0 +1,55 @@
"""Sets up tests
Configures the logger for use
"""
# MIT License
#
# Copyright (c) 28/08/17 Ennis Massey
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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
from os import mkdir

try:
mkdir("./logs")
except FileExistsError:
pass

fmt = logging.Formatter("[%(module)s] || %(asctime)s - %(levelname)s : %(module)s.%(funcName)s || %(message)s")
ch = logging.StreamHandler()

ch.setLevel(logging.CRITICAL)

fh = logging.FileHandler("logs/{}.log".format(__package__))

fh.setLevel(logging.INFO)

logger = logging.getLogger(__package__)
logger.setLevel(logging.INFO)
logger.addHandler(ch)
logger.addHandler(fh)
logger.propagate = False

ch.setFormatter(logging.Formatter("%(message)s"))
fh.setFormatter(logging.Formatter("%(message)s"))

logger.info("\033[1mTESTING STARTED\033[0m")

fh.setFormatter(fmt)
ch.setFormatter(fmt)
16 changes: 15 additions & 1 deletion tests/test_events.py
Expand Up @@ -19,15 +19,21 @@
# 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.
from unittest import TestCase
import nose2
import logging
from unittest import TestCase, TestSuite
from unittest.mock import MagicMock, call

from midisnake.events import NoteOff, NoteOn, PolyphonicAftertouch, PitchBend
from midisnake.errors import LengthError


logger = logging.getLogger(__name__)


class TestNoteOn(TestCase):
def test_validate(self):
logger.info("Starting NoteOn .valid function tests")
test_val = NoteOn.valid(0x900000)
self.assertTrue(test_val, "Generic MIDI NoteOn message failed validation. Value was 0x{:X}".format(test_val))
test_val = NoteOn.valid(0x800000)
Expand Down Expand Up @@ -60,4 +66,12 @@ def test_constructor(self):
) as exc:
NoteOn(0x1)

# Test validation exceptions
with self.assertRaises(ValueError,
msg="NoteOn given invalid data did not raise ValueError. Value was 0x290011"
) as exc:
NoteOn(0x290011)


if __name__ == "__main__":
nose2.main()
8 changes: 8 additions & 0 deletions tests/test_intbuilder.py
Expand Up @@ -19,10 +19,14 @@
# 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 unittest
import logging
from unittest import TestCase

from midisnake.integers import IntBuilder, LengthException

logger = logging.getLogger(__name__)


class TestIntBuilder(TestCase):
def test_repr(self):
Expand Down Expand Up @@ -125,3 +129,7 @@ def test_init(self):
'original_data': bytearray(
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\r\xe0\xb6\xb3\xa7c\xff\xff')
})


if __name__ == "__main__":
unittest.main()
11 changes: 10 additions & 1 deletion tests/test_track.py
Expand Up @@ -20,11 +20,20 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import nose2
import logging
from unittest import TestCase


logger = logging.getLogger(__name__)

from midisnake.structure import Track


class TestTrack(TestCase):
def setUp(self):
self.track_inst = Track()
self.track_inst = Track()


if __name__ == "__main__":
nose2.main()
9 changes: 9 additions & 0 deletions tests/test_vlv.py
Expand Up @@ -19,13 +19,18 @@
# 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 nose2
import logging
from unittest import TestCase
from unittest.mock import MagicMock, call
from typing import Union
from io import BufferedReader

from midisnake.structure import VariableLengthValue

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


class TestVLV(TestCase):
def setUp(self):
Expand Down Expand Up @@ -57,3 +62,7 @@ def test_single_byte_vlv(self):
self.assertEqual(vlv_instance.raw_data, bytearray(b'\x3C'), "VLV Incorrect data read from single byte")
self.assertEqual(vlv_instance.length, 1, "VLV Incorrect length when reading single byte")
self.mock_file.read.assert_has_calls([call(1)], "VLV Incorrect calls when reading from single byte")


if __name__ == "__main__":
nose2.main()
3 changes: 2 additions & 1 deletion tox.ini
@@ -1,9 +1,10 @@
[tox]
envlist = py30, py31, py33, py34, py35, py36, py37


[testenv]
depends =
nose2

usedevelop=True
command =
nose2

0 comments on commit 8fe1721

Please sign in to comment.