Ejemplo n.º 1
0
 def __init__(self, input_count, output_count, preset_controller=None):
     self.INPUT_COUNT = input_count
     self.OUTPUT_COUNT = output_count
     if preset_controller is None:
         self.PRESET_CONTROLLER = VirtualPresetController()
     else:
         self.PRESET_CONTROLLER = preset_controller
Ejemplo n.º 2
0
def test_delete_all_presets():
    """Ensure all presets are deleted"""
    vpc = VirtualPresetController()
    p1 = [1, 4, 4]
    p2 = [2, 2, 2]
    vpc._presets = {'p1': p1, 'p2': p2}
    vpc.delete_all_presets()
    assert vpc._presets == {}
Ejemplo n.º 3
0
def test_get_preset_not_exist():
    """Test getting a preset that exists"""
    vpc = VirtualPresetController()
    p1 = [1, 4, 4]
    p2 = [2, 2, 2]
    p3 = [2, 3, 1]
    vpc._presets = {'p1': p1, 'p2': p2, 'p3': p3}
    assert vpc.get_preset('p4') is None
Ejemplo n.º 4
0
def test_delete_preset():
    """Delete a singe preset and verify others remain"""
    vpc = VirtualPresetController()
    p1 = [1, 4, 4]
    p2 = [2, 2, 2]
    vpc._presets = {'p1': p1, 'p2': p2}
    vpc.delete_preset('p1')
    assert vpc._presets == {'p2': p2}
Ejemplo n.º 5
0
def test_set_preset():
    """Test that the preset is set, including the correct id"""
    vpc = VirtualPresetController()
    p1 = [1, 4, 4]
    p2 = [2, 2, 2]
    vpc._presets = {'p1': p1}
    vpc.set_preset('p2', p2)
    assert 'p1' in vpc._presets
    assert 'p2' in vpc._presets
    assert vpc._presets['p2'] == p2
Ejemplo n.º 6
0
def test_save_preset():
    """Test that the preset is saved and the assigned id returned"""
    vpc = VirtualPresetController()
    p1 = [1, 4, 4]
    p2 = [2, 2, 2]
    vpc._presets = {'p1': p1}
    p2_id = vpc.save_preset(p2)
    assert 'p1' in vpc._presets
    assert p2_id in vpc._presets
    assert vpc._presets[p2_id] == p2
Ejemplo n.º 7
0
def test_list_presets():
    """Test listing all presets"""
    vpc = VirtualPresetController()
    p1 = [1, 4, 4]
    p2 = [2, 2, 2]
    p3 = [2, 3, 1]
    vpc._presets = {'p1': p1, 'p2': p2, 'p3': p3}
    response = vpc.list_presets()
    assert 'p1' in response
    assert 'p2' in response
    assert 'p3' in response
Ejemplo n.º 8
0
def test_get_all_presets():
    """Test getting all presets"""
    vpc = VirtualPresetController()
    p1 = [1, 4, 4]
    p2 = [2, 2, 2]
    p3 = [2, 3, 1]
    vpc._presets = {'p1': p1, 'p2': p2, 'p3': p3}
    response = vpc.get_all_presets()
    assert ('p1', p1) in response
    assert ('p2', p2) in response
    assert ('p3', p3) in response
Ejemplo n.º 9
0
def test_move_preset():
    """Test renaming a preset"""
    vpc = VirtualPresetController()
    p1 = [1, 4, 4]
    p2 = [2, 2, 2]
    p3 = [2, 3, 1]
    vpc._presets = {'p1': p1, 'p2': p2, 'p3': p3}
    vpc.move_preset('p1', 'p3')
    assert 'p1' not in vpc._presets
    assert 'p2' in vpc._presets
    assert 'p3' in vpc._presets
    assert vpc._presets['p3'] == p1
Ejemplo n.º 10
0
def test_set_presets():
    """Test that the presets are set, including the correct ids"""
    vpc = VirtualPresetController()
    p1 = [1, 4, 4]
    p2 = [2, 2, 2]
    p3 = [2, 3, 1]
    vpc._presets = {'p1': p1}
    vpc.set_presets([('p2', p2), ('p3', p3)])
    assert 'p1' in vpc._presets
    assert 'p2' in vpc._presets
    assert 'p3' in vpc._presets
    assert vpc._presets['p2'] == p2
    assert vpc._presets['p3'] == p3
Ejemplo n.º 11
0
class Matrix(ABC):
    """
    Generic video matrix interface.

    Some functions are included to reduce complex instructions to common simple
    ones - if the complex instructions are supported in hardware, implement them!
    """
    def __init__(self, input_count, output_count, preset_controller=None):
        self.INPUT_COUNT = input_count
        self.OUTPUT_COUNT = output_count
        if preset_controller is None:
            self.PRESET_CONTROLLER = VirtualPresetController()
        else:
            self.PRESET_CONTROLLER = preset_controller

    def get_input_count(self):
        """Return the number of inputs on the matrix."""
        return self.INPUT_COUNT

    def get_output_count(self):
        """Return the number of inputs on the matrix."""
        return self.OUTPUT_COUNT

    @abstractmethod
    def patch(self, input_, output):
        """Patch the given input to the given output"""
        raise NotImplementedError

    def patch_pairs(self, patch_pairs):
        """
        A list of patch instructions, each given as a tuple {input, output}.
        """
        if not isinstance(patch_pairs, list):
            # Convert to a single-element list
            patch_pairs = [patch_pairs]
        for input_, output in patch_pairs:
            self.patch(input_, output)

    def patch_list(self, patch):
        """
        An ordered list of inputs, to be applied to outputs in order.
        I.e. [1, 1, 2, 3] implies in 1 -> out 1, in 1 -> out 2, etc
        """
        output = 1
        for input_ in patch:
            self.patch(input_, output)
            output += 1

    def patch_one_to_all(self, input_):
        """Patch the given input to every output"""
        for output in range(1, self.OUTPUT_COUNT + 1):
            self.patch(input_, output)

    def patch_one_to_one(self):
        """
        Patch in 1 -> out 1, in 2 -> out 2, etc.
        If more outputs than inputs, wrap and start counting from 1 again.
        """
        for i in range(0, self.OUTPUT_COUNT):
            self.patch((i % self.INPUT_COUNT) + 1, i + 1)

    @abstractmethod
    def get_patch(self):
        """
        Return the current routing table as an ordered list of inputs
        I.e. [1, 4, 7] implies [(in 1 -> out 1), (in 4 -> out 2), etc]
        """
        raise NotImplementedError

    @abstractmethod
    def blackout(self, outputs):
        """Black out the given outputs."""
        if not isinstance(outputs, list):
            # Convert to a single-element list
            outputs = [outputs]
        for output in outputs:
            raise NotImplementedError

    @abstractmethod
    def unblackout(self, outputs):
        """Restore the given outputs from blackout."""
        if not isinstance(outputs, list):
            # Convert to a single-element list
            outputs = [outputs]
        for output in outputs:
            raise NotImplementedError

    def blackout_all(self):
        """Black out every output."""
        for output in range(1, self.OUTPUT_COUNT + 1):
            self.blackout(output)

    def unblackout_all(self):
        """Restore every output from blackout."""
        for output in range(1, self.OUTPUT_COUNT + 1):
            self.unblackout(output)

    def apply_preset(self, preset_no):
        """Apply a numbered preset patch from the preset controller"""
        self.patch_list(self.PRESET_CONTROLLER.get(preset_no)[1])
Ejemplo n.º 12
0
def test_preset_id_in_use_not_exists():
    """Test checking if a preset id is in use with an id not in use"""
    vpc = VirtualPresetController()
    p1 = [1, 4, 4]
    vpc._presets = {'p1': p1}
    assert not vpc.preset_id_in_use('p2')
Ejemplo n.º 13
0
def test_random_string():
    """Test that a string of the specified length is generated"""
    str_ = VirtualPresetController.random_string(length=10)
    assert len(str_) == 10
    assert isinstance(str_, str)