diff --git a/setup.py b/setup.py index facca01..70db8d8 100644 --- a/setup.py +++ b/setup.py @@ -10,9 +10,8 @@ setup( ], extras_require={ 'development': [ - 'nose', - 'randomize', - 'parameterized' + "pytest", + "pytest-randomly", ] } -) \ No newline at end of file +) diff --git a/tests/__init__.py b/tests/__init__.py index 730e4fd..b3d3340 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,22 +1,47 @@ +from dataclasses import dataclass import vbancmd from vbancmd import kinds +import random + +# let's keep things random +# kind_id = random.choice(("basic", "banana", "potato")) +kind_id = "banana" -_kind = "potato" opts = { - "ip": "ws.local", + "ip": "codey.local", "streamname": "testing", "port": 6990, "bps": 0, "sync": True, } -vbanrs = {kind.id: vbancmd.connect(_kind, **opts) for kind in kinds.all} -tests = vbanrs[_kind] +vbans = {kind.id: vbancmd.connect(kind_id, **opts) for kind in kinds.all} +tests = vbans[kind_id] +kind = kinds.get(kind_id) -def setup_package(): +@dataclass +class Data: + """bounds data to map tests to a kind""" + + name: str = kind.id + phys_in: int = kind.ins[0] - 1 + virt_in: int = kind.ins[0] + kind.ins[1] - 1 + phys_out: int = kind.outs[0] - 1 + virt_out: int = kind.outs[0] + kind.outs[1] - 1 + vban_in: int = kind.vban[0] - 1 + vban_out: int = kind.vban[1] - 1 + button_lower: int = 0 + button_upper: int = 79 + + +data = Data() + + +def setup_module(): tests.login() + tests.apply_profile("blank") -def teardown_package(): +def teardown_module(): tests.logout() diff --git a/tests/runmany.ps1 b/tests/runmany.ps1 deleted file mode 100644 index 56ff34a..0000000 --- a/tests/runmany.ps1 +++ /dev/null @@ -1,103 +0,0 @@ -param( - [parameter(Mandatory=$false)] - [Int] $num = 1, - [switch]$cycle, - [switch]$Log - ) - -$global:failures = 0 - -Function RunTests { - param([int]$cycle_num) - if ($cycle_num) { - $num = $cycle_num - } - - $logfile = "nosetest.log" - $failures = $global:failures - $firstrun = $false - - if ($cycle_num -eq 20) { $firstrun = $true } - - 1..$num | ForEach-Object { ` - if ($Log) { "Running test $_ of ${num} runs" | Tee-Object -FilePath $logfile -Append } - else { Write-Host "Running test $_ of ${num} runs" } - - ForEach ($line in $(Invoke-Expression "nosetests --randomize -s tests 2>&1")) { - if ($Log) { - if ($line -NotMatch '^(System)') { - "${line}" | Tee-Object -FilePath $logfile -Append - } - } else { - if ($line -NotMatch '^(System)') { Write-Host "${line}" } - } - - $m = [regex]::Match($line, '^(FAILED)\s\([errors=\d+,\s]?failures=(\d+)\)') - if ($m.captures.groups.count -gt 1) { - $failures += $m.captures.groups[2].value - } - } - } - - if ($Log) { - $log_backup = LogRotate -logfile $logfile - $log_backupfile = Split-Path $log_backup -leaf - - $summary_file = "summary.log" - if ($firstrun -eq $true) { - "===========================================================`n" + ` - "NOTES:" | Tee-Object -FilePath $summary_file -Append - } - "===========================================================`n" + ` - "${num} test run`n" + ` - "Total failures: ${failures}`n" + ` - "Logfile for this test run: ${log_backupfile}`n" + ` - "===========================================================" | ` - Tee-Object -FilePath $summary_file -Append - } else { - "===========================================================", - "${num} test run", - "Total failures: ${failures}", - "===========================================================" | Write-Host - } - $global:failures = $failures -} - -Function LogRotate { - param([string]$logfile) - Get-ChildItem ./ -recurse ` - | Where-Object {$_.basename -ne 'summary' -and $_.extension -eq ".log" } ` - | ForEach-Object { - $i = 1 - $StopLoop = $false - - do { - try { - $savefile = "$($_.Fullname)_$i.backup" - Rename-Item -Path $_.FullName ` - -NewName $savefile -ErrorAction "Stop" - - $StopLoop = $true - } - catch { - Start-Sleep -m 100 - $i++ - } - } until ($StopLoop -eq $true) - } - $savefile -} - -if ($MyInvocation.InvocationName -ne ".") -{ - & '..\venv_vban_cmd\Scripts\activate.ps1' - - if ($cycle) { - @(20, 50, 100, 200, 500, 1000) | ForEach-Object { - RunTests -cycle_num $_ - if ($global:failures -gt 0) { break } - } - } else { RunTests } - - & 'deactivate' -} \ No newline at end of file diff --git a/tests/test_higher.py b/tests/test_higher.py new file mode 100644 index 0000000..2d7c121 --- /dev/null +++ b/tests/test_higher.py @@ -0,0 +1,184 @@ +import pytest +from tests import tests, data + + +@pytest.mark.parametrize("value", [False, True]) +class TestSetAndGetBoolHigher: + __test__ = True + + """strip tests, physical and virtual""" + + @pytest.mark.parametrize( + "index,param", + [ + (data.phys_in, "mute"), + (data.phys_in, "mono"), + (data.virt_in, "mc"), + (data.virt_in, "mono"), + ], + ) + def test_it_sets_and_gets_strip_bool_params(self, index, param, value): + setattr(tests.strip[index], param, value) + assert getattr(tests.strip[index], param) == value + + """ bus tests, physical and virtual """ + + @pytest.mark.parametrize( + "index,param", + [ + (data.phys_out, "eq"), + (data.phys_out, "mute"), + (data.virt_out, "eq_ab"), + (data.virt_out, "sel"), + ], + ) + def test_it_sets_and_gets_bus_bool_params(self, index, param, value): + setattr(tests.bus[index], param, value) + assert getattr(tests.bus[index], param) == value + + """ bus modes tests, physical and virtual """ + + @pytest.mark.parametrize( + "index,param", + [ + (data.phys_out, "normal"), + (data.phys_out, "amix"), + (data.phys_out, "rearonly"), + (data.virt_out, "normal"), + (data.virt_out, "upmix41"), + (data.virt_out, "composite"), + ], + ) + def test_it_sets_and_gets_bus_bool_params(self, index, param, value): + # here it only makes sense to set/get bus modes as True + if not value: + value = True + setattr(tests.bus[index].mode, param, value) + assert getattr(tests.bus[index].mode, param) == value + + """ command tests """ + + @pytest.mark.parametrize( + "param", + [("lock")], + ) + def test_it_sets_command_bool_params(self, param, value): + setattr(tests.command, param, value) + + +class TestSetAndGetIntHigher: + # note, currently no int parameters supported by rt packet service + # ie they can be set but not get + __test__ = False + + """strip tests, physical and virtual""" + + @pytest.mark.parametrize( + "index,param,value", + [ + (data.virt_in, "k", 0), + (data.virt_in, "k", 4), + ], + ) + def test_it_sets_and_gets_strip_bool_params(self, index, param, value): + setattr(tests.strip[index], param, value) + assert getattr(tests.strip[index], param) == value + + +class TestSetAndGetFloatHigher: + __test__ = True + + """strip tests, physical and virtual""" + + @pytest.mark.parametrize( + "index,param,value", + [ + (data.phys_in, "gain", -3.6), + (data.phys_in, "gain", 3.6), + (data.virt_in, "gain", -5.8), + (data.virt_in, "gain", 5.8), + ], + ) + def test_it_sets_and_gets_strip_float_params(self, index, param, value): + setattr(tests.strip[index], param, value) + assert getattr(tests.strip[index], param) == value + + @pytest.mark.parametrize( + "index,value", + [(data.phys_in, 2), (data.phys_in, 2), (data.virt_in, 8), (data.virt_in, 8)], + ) + def test_it_gets_prefader_levels_and_compares_length_of_array(self, index, value): + assert len(tests.strip[index].levels.prefader) == value + + @pytest.mark.skipif( + data.name != "potato", + reason="Only test if logged into Potato version", + ) + @pytest.mark.parametrize( + "index, j, value", + [ + (data.phys_in, 0, -20.7), + (data.virt_in, 3, -60), + (data.virt_in, 4, 3.6), + (data.phys_in, 4, -12.7), + ], + ) + def test_it_sets_and_gets_strip_gainlayer_values(self, index, j, value): + tests.strip[index].gainlayer[j].gain = value + assert tests.strip[index].gainlayer[j].gain == value + + """ strip tests, virtual """ + + @pytest.mark.parametrize( + "index, param, value", + [ + (data.virt_in, "treble", -1.6), + (data.virt_in, "mid", 5.8), + (data.virt_in, "bass", -8.1), + ], + ) + def test_it_sets_and_gets_strip_eq_params(self, index, param, value): + setattr(tests.strip[index], param, value) + assert getattr(tests.strip[index], param) == value + + """ bus tests, physical and virtual """ + + @pytest.mark.parametrize( + "index, param, value", + [(data.phys_out, "gain", -3.6), (data.virt_out, "gain", 5.8)], + ) + def test_it_sets_and_gets_bus_float_params(self, index, param, value): + setattr(tests.bus[index], param, value) + assert getattr(tests.bus[index], param) == value + + @pytest.mark.parametrize( + "index,value", + [(data.phys_out, 8), (data.virt_out, 8)], + ) + def test_it_gets_prefader_levels_and_compares_length_of_array(self, index, value): + assert len(tests.bus[index].levels.all) == value + + +@pytest.mark.parametrize("value", ["test0", "test1"]) +class TestSetAndGetStringHigher: + __test__ = True + + """strip tests, physical and virtual""" + + @pytest.mark.parametrize( + "index, param", + [(data.phys_in, "label"), (data.virt_in, "label")], + ) + def test_it_sets_and_gets_strip_string_params(self, index, param, value): + setattr(tests.strip[index], param, value) + assert getattr(tests.strip[index], param) == value + + """ bus tests, physical and virtual """ + + @pytest.mark.parametrize( + "index, param", + [(data.phys_out, "label"), (data.virt_out, "label")], + ) + def test_it_sets_and_gets_bus_string_params(self, index, param, value): + setattr(tests.bus[index], param, value) + assert getattr(tests.bus[index], param) == value diff --git a/tests/test_lower.py b/tests/test_lower.py new file mode 100644 index 0000000..40e54d9 --- /dev/null +++ b/tests/test_lower.py @@ -0,0 +1,79 @@ +import pytest +from tests import tests, data + + +class TestSetAndGetFloatLower: + __test__ = False + + """VBVMR_SetParameterFloat, VBVMR_GetParameterFloat""" + + @pytest.mark.parametrize( + "param,value", + [ + (f"Strip[{data.phys_in}].Mute", 1), + (f"Bus[{data.virt_out}].Eq.on", 1), + (f"Strip[{data.phys_in}].Mute", 0), + (f"Bus[{data.virt_out}].Eq.on", 0), + ], + ) + def test_it_sets_and_gets_mute_eq_float_params(self, param, value): + tests.set(param, value) + assert (round(tests.get(param))) == value + + @pytest.mark.parametrize( + "param,value", + [ + (f"Strip[{data.phys_in}].Comp", 5.3), + (f"Strip[{data.virt_in}].Gain", -37.5), + (f"Bus[{data.virt_out}].Gain", -22.7), + ], + ) + def test_it_sets_and_gets_comp_gain_float_params(self, param, value): + tests.set(param, value) + assert (round(tests.get(param), 1)) == value + + +@pytest.mark.parametrize("value", ["test0", "test1"]) +class TestSetAndGetStringLower: + __test__ = False + + """VBVMR_SetParameterStringW, VBVMR_GetParameterStringW""" + + @pytest.mark.parametrize( + "param", + [(f"Strip[{data.phys_out}].label"), (f"Bus[{data.virt_out}].label")], + ) + def test_it_sets_and_gets_string_params(self, param, value): + tests.set(param, value) + assert tests.get(param, string=True) == value + + +@pytest.mark.parametrize("value", [0, 1]) +class TestMacroButtonsLower: + __test__ = False + + """VBVMR_MacroButton_SetStatus, VBVMR_MacroButton_GetStatus""" + + @pytest.mark.parametrize( + "index, mode", + [(33, 1), (49, 1)], + ) + def test_it_sets_and_gets_macrobuttons_state(self, index, mode, value): + tests.set_buttonstatus(index, value, mode) + assert tests.get_buttonstatus(index, mode) == value + + @pytest.mark.parametrize( + "index, mode", + [(14, 2), (12, 2)], + ) + def test_it_sets_and_gets_macrobuttons_stateonly(self, index, mode, value): + tests.set_buttonstatus(index, value, mode) + assert tests.get_buttonstatus(index, mode) == value + + @pytest.mark.parametrize( + "index, mode", + [(50, 3), (65, 3)], + ) + def test_it_sets_and_gets_macrobuttons_trigger(self, index, mode, value): + tests.set_buttonstatus(index, value, mode) + assert tests.get_buttonstatus(index, mode) == value diff --git a/tests/tests_higher.py b/tests/tests_higher.py deleted file mode 100644 index 6d1bed8..0000000 --- a/tests/tests_higher.py +++ /dev/null @@ -1,95 +0,0 @@ -from nose.tools import assert_equal, nottest -from parameterized import parameterized, parameterized_class - -import unittest -from tests import tests - -# @nottest -@parameterized_class([{"val": False}, {"val": True}]) -class TestSetAndGetBoolHigher(unittest.TestCase): - """strip tests, physical and virtual""" - - @parameterized.expand( - [ - (0, "mute"), - (2, "mono"), - (3, "A1"), - (6, "B3"), - (6, "mute"), - ] - ) - def test_it_sets_and_gets_strip_bool_params(self, index, param): - setattr(tests.strip[index], param, self.val) - retval = getattr(tests.strip[index], param) - self.assertTrue(isinstance(retval, bool)) - assert_equal(retval, self.val) - - """ bus tests, physical and virtual """ - - @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): - setattr(tests.bus[index], param, self.val) - retval = getattr(tests.bus[index], param) - self.assertTrue(isinstance(retval, bool)) - assert_equal(retval, self.val) - - """ bus mode tests, physical and virtual """ - - @parameterized.expand( - [ - (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): - setattr(tests.bus[index].mode, param, self.val) - retval = getattr(tests.bus[index].mode, param) - self.assertTrue(isinstance(retval, bool)) - assert_equal(retval, self.val) - - -# @nottest -@parameterized_class([{"val": "test0"}, {"val": "test1"}, {"val": ""}]) -class TestSetAndGetStringHigher(unittest.TestCase): - """strip tests, physical and virtual""" - - @parameterized.expand([(2, "label"), (6, "label")]) - def test_it_sets_and_gets_strip_string_params(self, index, param): - setattr(tests.strip[index], param, self.val) - assert_equal(getattr(tests.strip[index], param), self.val) - - """ bus tests, physical and virtual """ - - @parameterized.expand([(0, "label"), (7, "label")]) - def test_it_sets_and_gets_bus_string_params(self, index, param): - setattr(tests.bus[index], param, self.val) - assert_equal(getattr(tests.bus[index], param), self.val) - - -# @nottest -class TestSetAndGetFloatHigher(unittest.TestCase): - """strip tests, physical and virtual""" - - @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): - setattr(tests.strip[index].gainlayer[j], param, val) - retval = getattr(tests.strip[index].gainlayer[j], param) - assert_equal(retval, val) - - """ bus tests, physical and virtual """ - - @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): - setattr(tests.bus[index], param, val) - retval = getattr(tests.bus[index], param) - assert_equal(retval, val) diff --git a/tests/tests_lower.py b/tests/tests_lower.py deleted file mode 100644 index 642961e..0000000 --- a/tests/tests_lower.py +++ /dev/null @@ -1,49 +0,0 @@ -from nose.tools import assert_equal, nottest -from parameterized import parameterized, parameterized_class - -import unittest -from vbancmd.channel import Modes -from tests import tests - -# @nottest -@parameterized_class( - [ - {"val": 0}, - {"val": 1}, - ] -) -class TestSetAndGetParamsLower(unittest.TestCase): - def setUp(self) -> None: - tests._modes = Modes() - - """ get_rt, set_rt test """ - - @parameterized.expand( - [ - (0, "mute"), - (4, "mute"), - ] - ) - def test_it_sets_and_gets_strip_bool_params(self, index, param): - tests.set_rt(f"Strip[{index}]", param, self.val) - retval = tests._get_rt() - retval = ( - not int.from_bytes(retval.stripstate[index], "little") & tests._modes._mute - == 0 - ) - assert_equal(retval, self.val) - - @parameterized.expand( - [ - (0, "mono"), - (5, "mono"), - ] - ) - def test_it_sets_and_gets_strip_bool_params(self, index, param): - tests.set_rt(f"Strip[{index}]", param, self.val) - retval = tests._get_rt() - retval = ( - not int.from_bytes(retval.stripstate[index], "little") & tests._modes._mono - == 0 - ) - assert_equal(retval, self.val)