add sync kwarg, reformat tests.

tests reformatted, add sync to tests.

add sync kwarg to vbancmd. Set for apply_profile.
This commit is contained in:
onyx-and-iris 2022-04-08 21:16:37 +01:00
parent b7b62ea2fe
commit 1c0ebfa1d1
4 changed files with 93 additions and 57 deletions

View File

@ -1,22 +1,22 @@
import vbancmd import vbancmd
from vbancmd import kinds from vbancmd import kinds
from vbancmd.channel import Modes
import socket
from threading import Thread
_kind = 'potato' _kind = "potato"
opts = { opts = {
'ip': 'ws.local', "ip": "ws.local",
'streamname': 'testing', "streamname": "testing",
'port': 6990, "port": 6990,
'bps': 0, "bps": 0,
"sync": True,
} }
vbanrs = {kind.id: vbancmd.connect(_kind, **opts) for kind in kinds.all} vbanrs = {kind.id: vbancmd.connect(_kind, **opts) for kind in kinds.all}
tests = vbanrs[_kind] tests = vbanrs[_kind]
def setup_package(): def setup_package():
tests.login() tests.login()
def teardown_package(): def teardown_package():
tests.logout() tests.logout()

View File

@ -4,15 +4,20 @@ from parameterized import parameterized, parameterized_class
import unittest import unittest
from tests import tests from tests import tests
#@nottest # @nottest
@parameterized_class([ @parameterized_class([{"val": False}, {"val": True}])
{ "val": False }, { "val": True }
])
class TestSetAndGetBoolHigher(unittest.TestCase): class TestSetAndGetBoolHigher(unittest.TestCase):
""" strip tests, physical and virtual """ """strip tests, physical and virtual"""
@parameterized.expand([
(0, 'mute'), (2, 'mono'), (3, 'A1'), (6, 'B3'), (6, 'mute'), @parameterized.expand(
]) [
(0, "mute"),
(2, "mono"),
(3, "A1"),
(6, "B3"),
(6, "mute"),
]
)
def test_it_sets_and_gets_strip_bool_params(self, index, param): def test_it_sets_and_gets_strip_bool_params(self, index, param):
setattr(tests.strip[index], param, self.val) setattr(tests.strip[index], param, self.val)
retval = getattr(tests.strip[index], param) retval = getattr(tests.strip[index], param)
@ -20,9 +25,10 @@ class TestSetAndGetBoolHigher(unittest.TestCase):
assert_equal(retval, self.val) assert_equal(retval, self.val)
""" bus tests, physical and virtual """ """ bus tests, physical and virtual """
@parameterized.expand([
(0, 'mute'), (2, 'mono'), (6, 'mute'), (2, 'eq'), (7, 'eq_ab') @parameterized.expand(
]) [(0, "mute"), (2, "mono"), (6, "mute"), (2, "eq"), (7, "eq_ab")]
)
def test_it_sets_and_gets_bus_bool_params(self, index, param): def test_it_sets_and_gets_bus_bool_params(self, index, param):
setattr(tests.bus[index], param, self.val) setattr(tests.bus[index], param, self.val)
retval = getattr(tests.bus[index], param) retval = getattr(tests.bus[index], param)
@ -30,10 +36,19 @@ class TestSetAndGetBoolHigher(unittest.TestCase):
assert_equal(retval, self.val) assert_equal(retval, self.val)
""" bus mode tests, physical and virtual """ """ bus mode tests, physical and virtual """
@parameterized.expand([
(0, 'amix'), (0, 'tvmix'), (2, 'composite'), (2, 'upmix41'), @parameterized.expand(
(7, 'upmix21'), (7, 'rearonly'), (6, 'lfeonly'), (6, 'repeat') [
]) (0, "amix"),
(0, "tvmix"),
(2, "composite"),
(2, "upmix41"),
(7, "upmix21"),
(7, "rearonly"),
(6, "lfeonly"),
(6, "repeat"),
]
)
def test_it_sets_and_gets_bus_mode_bool_params(self, index, param): def test_it_sets_and_gets_bus_mode_bool_params(self, index, param):
setattr(tests.bus[index].mode, param, self.val) setattr(tests.bus[index].mode, param, self.val)
retval = getattr(tests.bus[index].mode, param) retval = getattr(tests.bus[index].mode, param)
@ -41,43 +56,39 @@ class TestSetAndGetBoolHigher(unittest.TestCase):
assert_equal(retval, self.val) assert_equal(retval, self.val)
#@nottest # @nottest
@parameterized_class([ @parameterized_class([{"val": "test0"}, {"val": "test1"}, {"val": ""}])
{ "val": "test0" }, { "val": "test1" }
])
class TestSetAndGetStringHigher(unittest.TestCase): class TestSetAndGetStringHigher(unittest.TestCase):
""" strip tests, physical and virtual """ """strip tests, physical and virtual"""
@parameterized.expand([
(2, 'label'), (6, 'label') @parameterized.expand([(2, "label"), (6, "label")])
])
def test_it_sets_and_gets_strip_string_params(self, index, param): def test_it_sets_and_gets_strip_string_params(self, index, param):
setattr(tests.strip[index], param, self.val) setattr(tests.strip[index], param, self.val)
assert_equal(getattr(tests.strip[index], param), self.val) assert_equal(getattr(tests.strip[index], param), self.val)
""" bus tests, physical and virtual """ """ bus tests, physical and virtual """
@parameterized.expand([
(0, 'label'), (7, 'label') @parameterized.expand([(0, "label"), (7, "label")])
])
def test_it_sets_and_gets_bus_string_params(self, index, param): def test_it_sets_and_gets_bus_string_params(self, index, param):
setattr(tests.bus[index], param, self.val) setattr(tests.bus[index], param, self.val)
assert_equal(getattr(tests.bus[index], param), self.val) assert_equal(getattr(tests.bus[index], param), self.val)
#@nottest # @nottest
class TestSetAndGetFloatHigher(unittest.TestCase): class TestSetAndGetFloatHigher(unittest.TestCase):
""" strip tests, physical and virtual """ """strip tests, physical and virtual"""
@parameterized.expand([
(0, 1, 'gain', -6.3), (7, 4, 'gain', -12.5), (3, 3, 'gain', 3.3) @parameterized.expand(
]) [(0, 1, "gain", -6.3), (7, 4, "gain", -12.5), (3, 3, "gain", 3.3)]
)
def test_it_sets_and_gets_strip_float_params(self, index, j, param, val): def test_it_sets_and_gets_strip_float_params(self, index, j, param, val):
setattr(tests.strip[index].gainlayer[j], param, val) setattr(tests.strip[index].gainlayer[j], param, val)
retval = getattr(tests.strip[index].gainlayer[j], param) retval = getattr(tests.strip[index].gainlayer[j], param)
assert_equal(retval, val) assert_equal(retval, val)
""" bus tests, physical and virtual """ """ bus tests, physical and virtual """
@parameterized.expand([
(0, 'gain', -6.3), (7, 'gain', -12.5), (3, 'gain', 3.3) @parameterized.expand([(0, "gain", -6.3), (7, "gain", -12.5), (3, "gain", 3.3)])
])
def test_it_sets_and_gets_bus_float_params(self, index, param, val): def test_it_sets_and_gets_bus_float_params(self, index, param, val):
setattr(tests.bus[index], param, val) setattr(tests.bus[index], param, val)
retval = getattr(tests.bus[index], param) retval = getattr(tests.bus[index], param)

View File

@ -2,28 +2,48 @@ from nose.tools import assert_equal, nottest
from parameterized import parameterized, parameterized_class from parameterized import parameterized, parameterized_class
import unittest import unittest
from vbancmd.channel import Modes
from tests import tests from tests import tests
#@nottest # @nottest
@parameterized_class([ @parameterized_class(
{ "val": 0 }, { "val": 1 }, [
]) {"val": 0},
{"val": 1},
]
)
class TestSetAndGetParamsLower(unittest.TestCase): class TestSetAndGetParamsLower(unittest.TestCase):
def setUp(self) -> None:
tests._modes = Modes()
""" get_rt, set_rt test """ """ get_rt, set_rt test """
@parameterized.expand([
(0, 'mute'), (4, 'mute'), @parameterized.expand(
]) [
(0, "mute"),
(4, "mute"),
]
)
def test_it_sets_and_gets_strip_bool_params(self, index, param): def test_it_sets_and_gets_strip_bool_params(self, index, param):
tests.set_rt(f'Strip[{index}]', param, self.val) tests.set_rt(f"Strip[{index}]", param, self.val)
retval = tests._get_rt() retval = tests._get_rt()
retval = not int.from_bytes(retval.stripstate[index], 'little') & tests._modes._mute == 0 retval = (
not int.from_bytes(retval.stripstate[index], "little") & tests._modes._mute
== 0
)
assert_equal(retval, self.val) assert_equal(retval, self.val)
@parameterized.expand([ @parameterized.expand(
(0, 'mono'), (5, 'mono'), [
]) (0, "mono"),
(5, "mono"),
]
)
def test_it_sets_and_gets_strip_bool_params(self, index, param): def test_it_sets_and_gets_strip_bool_params(self, index, param):
tests.set_rt(f'Strip[{index}]', param, self.val) tests.set_rt(f"Strip[{index}]", param, self.val)
retval = tests._get_rt() retval = tests._get_rt()
retval = not int.from_bytes(retval.stripstate[index], 'little') & tests._modes._mono == 0 retval = (
not int.from_bytes(retval.stripstate[index], "little") & tests._modes._mono
== 0
)
assert_equal(retval, self.val) assert_equal(retval, self.val)

View File

@ -29,6 +29,7 @@ class VbanCmd(abc.ABC):
self._channel = kwargs["channel"] self._channel = kwargs["channel"]
self._delay = kwargs["delay"] self._delay = kwargs["delay"]
self._ratelimiter = kwargs["ratelimiter"] self._ratelimiter = kwargs["ratelimiter"]
self._sync = kwargs["sync"]
# fmt: off # fmt: off
self._bps_opts = [ self._bps_opts = [
0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 31250, 0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 31250,
@ -196,7 +197,8 @@ class VbanCmd(abc.ABC):
count = int.from_bytes(self._text_header.framecounter, "little") + 1 count = int.from_bytes(self._text_header.framecounter, "little") + 1
self._text_header.framecounter = count.to_bytes(4, "little") self._text_header.framecounter = count.to_bytes(4, "little")
self.cache[f"{id_}.{param}"] = [val, True] self.cache[f"{id_}.{param}"] = [val, True]
sleep(self._ratelimiter) if self._sync:
sleep(self._ratelimiter)
def sendtext(self, cmd): def sendtext(self, cmd):
"""Sends a multiple parameter string over a network.""" """Sends a multiple parameter string over a network."""
@ -243,6 +245,7 @@ class VbanCmd(abc.ABC):
target.apply(submapping) target.apply(submapping)
def apply_profile(self, name: str): def apply_profile(self, name: str):
self._sync = True
try: try:
profile = self.profiles[name] profile = self.profiles[name]
if "extends" in profile: if "extends" in profile:
@ -257,6 +260,7 @@ class VbanCmd(abc.ABC):
self.apply(profile) self.apply(profile)
except KeyError: except KeyError:
raise VMCMDErrors(f"Unknown profile: {self.kind.id}/{name}") raise VMCMDErrors(f"Unknown profile: {self.kind.id}/{name}")
self._sync = False
def reset(self) -> NoReturn: def reset(self) -> NoReturn:
self.apply_profile("base") self.apply_profile("base")
@ -290,6 +294,7 @@ def _make_remote(kind: NamedTuple) -> VbanCmd:
"channel": 0, "channel": 0,
"delay": 0.001, "delay": 0.001,
"ratelimiter": 0.018, "ratelimiter": 0.018,
"sync": False,
} }
kwargs = defaultkwargs | kwargs kwargs = defaultkwargs | kwargs
VbanCmd.__init__(self, **kwargs) VbanCmd.__init__(self, **kwargs)