Skip to content

Commit

Permalink
Replace testtools by unittest / add test for determination of receive…
Browse files Browse the repository at this point in the history
…r type / test with python 3.9 too
  • Loading branch information
ol-iver committed Jan 3, 2021
1 parent 0281fb3 commit 9eb0a0f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
3 changes: 1 addition & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ pytest-cov
pytest-timeout
flake8-docstrings
flake8
requests-mock
testtools
requests-mock
63 changes: 45 additions & 18 deletions tests/test_denonavr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

from urllib.parse import urlparse
import testtools
import unittest
import requests
import requests_mock
import denonavr
Expand All @@ -20,15 +20,25 @@
ZONE3 = {"Zone3": None}
ZONE2_ZONE3 = {"Zone2": None, "Zone3": None}

TESTING_RECEIVERS = {"AVR-X4100W": NO_ZONES, "AVR-2312CI": NO_ZONES,
"AVR-1912": NO_ZONES, "AVR-3311CI": NO_ZONES,
"M-RC610": NO_ZONES, "AVR-X2100W-2": NO_ZONES,
"AVR-X2000": ZONE2_ZONE3, "AVR-X2000-2": NO_ZONES,
"SR5008": NO_ZONES, "M-CR603": NO_ZONES,
"NR1604": ZONE2_ZONE3, "AVR-4810": NO_ZONES,
"AVR-3312": NO_ZONES, "NR1609": ZONE2,
"AVC-8500H": ZONE2_ZONE3, "AVR-X4300H": ZONE2_ZONE3,
"AVR-X1100W": ZONE2}
TESTING_RECEIVERS = {
"AVR-X4100W": (NO_ZONES, denonavr.denonavr.AVR_X),
"AVR-2312CI": (NO_ZONES, denonavr.denonavr.AVR),
"AVR-1912": (NO_ZONES, denonavr.denonavr.AVR),
"AVR-3311CI": (NO_ZONES, denonavr.denonavr.AVR),
"M-RC610": (NO_ZONES, denonavr.denonavr.AVR_X),
"AVR-X2100W-2": (NO_ZONES, denonavr.denonavr.AVR_X),
"AVR-X2000": (ZONE2_ZONE3, denonavr.denonavr.AVR_X),
"AVR-X2000-2": (NO_ZONES, denonavr.denonavr.AVR_X),
"SR5008": (NO_ZONES, denonavr.denonavr.AVR_X),
"M-CR603": (NO_ZONES, denonavr.denonavr.AVR),
"NR1604": (ZONE2_ZONE3, denonavr.denonavr.AVR_X),
"AVR-4810": (NO_ZONES, denonavr.denonavr.AVR),
"AVR-3312": (NO_ZONES, denonavr.denonavr.AVR),
"NR1609": (ZONE2, denonavr.denonavr.AVR_X_2016),
"AVC-8500H": (ZONE2_ZONE3, denonavr.denonavr.AVR_X_2016),
"AVR-X4300H": (ZONE2_ZONE3, denonavr.denonavr.AVR_X_2016),
"AVR-X1100W": (ZONE2, denonavr.denonavr.AVR_X)
}

APPCOMMAND_URL = "/goform/AppCommand.xml"
STATUS_URL = "/goform/formMainZone_MainZoneXmlStatus.xml"
Expand All @@ -48,7 +58,7 @@ def get_sample_content(filename):
return file.read()


class TestMainFunctions(testtools.TestCase):
class TestMainFunctions(unittest.TestCase):
"""Test case for main functions of Denon AVR."""

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -124,20 +134,37 @@ def custom_matcher(self, request):

return resp

@requests_mock.mock()
def test_receiver_type(self, mock):
"""Check that receiver type is determined correctly."""
mock.add_matcher(self.custom_matcher)
for receiver, spec in TESTING_RECEIVERS.items():
# Switch receiver and update to load new sample files
self._testing_receiver = receiver
self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=spec[0])
self.assertEqual(
self.denon.receiver_type,
spec[1].type,
"Receiver type is {} not {} for receiver {}".format(
self.denon.receiver_type, spec[1].type, receiver))
self.assertEqual(
self.denon.receiver_port,
spec[1].port,
"Receiver port is {} not {} for receiver {}".format(
self.denon.receiver_port, spec[1].port, receiver))

@requests_mock.mock()
def test_input_func_switch(self, mock):
"""Switch through all input functions of all tested receivers."""
mock.add_matcher(self.custom_matcher)
for receiver, zones in TESTING_RECEIVERS.items():
for receiver, spec in TESTING_RECEIVERS.items():
# Switch receiver and update to load new sample files
self._testing_receiver = receiver
self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=zones)
self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=spec[0])
# Switch through all functions and check if successful
for name, zone in self.denon.zones.items():
print("Receiver: {}, Zone: {}".format(receiver, name))
self.assertThat(
len(zone.input_func_list),
testtools.matchers.GreaterThan(0))
self.assertGreater(len(zone.input_func_list), 0)
for input_func in zone.input_func_list:
self.denon.zones[name].set_input_func(input_func)
self.assertEqual(
Expand All @@ -150,10 +177,10 @@ def test_input_func_switch(self, mock):
def test_attributes_not_none(self, mock):
"""Check that certain attributes are not None."""
mock.add_matcher(self.custom_matcher)
for receiver, zones in TESTING_RECEIVERS.items():
for receiver, spec in TESTING_RECEIVERS.items():
# Switch receiver and update to load new sample files
self._testing_receiver = receiver
self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=zones)
self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=spec[0])
self.assertIsNotNone(
self.denon.power,
"Power status is None for receiver {}".format(receiver))
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# content of: tox.ini , put in same dir as setup.py
[tox]
envlist = py35,py36,py37,py38,pylint,lint
envlist = py35,py36,py37,py38,py39,pylint,lint
skip_missing_interpreters = True

[testenv:pylint]
Expand Down

0 comments on commit 9eb0a0f

Please sign in to comment.