Пример #1
0
def test_update_check_update_not_available(caplog, tmpdir):
    caplog.set_level(logging.DEBUG)
    logging.debug("UPDATE TEST")
    f = mock.Mock()
    version._test_version = "0.0.0"
    tmpDirPath = os.path.join(tmpdir, "pyu-data", "deploy")
    # tmpDirPath = os.getcwd()  # Enable for testing after creating release or release-dev
    # Write test files
    if not os.path.exists(tmpDirPath):
        os.makedirs(tmpDirPath)

    opts = midi_full.MidiProjectControllerOptions()
    opts.update_paths = [os.path.join(tmpDirPath, "pyu-data", "deploy")]
    # opts.client_config = TConfig()
    ctrl = midi_full.MidiProjectController(callback=f, options=opts)
    # Update message
    testMsg = mido.Message('sysex')
    testMsg.data = [0x00, 0x11]
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, None)
    if f.call_count > 0:
        retMsg = f.call_args[0][0]
        assert retMsg.data[0] == 0x00
        assert retMsg.data[1] == 0x1F
Пример #2
0
def test_get_enabled_controllers():
    # Setup
    f = mock.Mock()
    ctrl = midi_full.MidiProjectController(callback=f)
    # Get active project metadata
    testMsg = mido.Message('sysex')
    testMsg.data = [0x01, 0x30]
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    proj = cfg.getActiveProjectOrDefault()
    proj.activate()  # Needs to be activated
    proj.stopProcessing()
    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, proj)
    assert f.call_count == 1
    retMsg = f.call_args[0][0]
    # Check response message ID
    assert retMsg.data[0] == 0x01
    assert retMsg.data[1] == 0x30
    # Decode data
    dec = sysex_data.decode(retMsg.data[2:])
    metadata = json.loads(bytes(dec))
    assert metadata is not None
    assert len(metadata.keys()) == len(modulation.allController)
    for k, v in metadata.items():
        assert not v
Пример #3
0
def test_get_projects():
    # Setup
    f = mock.Mock()
    ctrl = midi_full.MidiProjectController(callback=f)
    # Get active project metadata
    testMsg = mido.Message('sysex')
    testMsg.data = [0x00, 0x30]
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    proj = cfg.getActiveProjectOrDefault()
    cfg.initDefaultProject()
    proj.stopProcessing()
    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, None)
    assert f.call_count == 1
    retMsg = f.call_args[0][0]
    # Check response message ID
    assert retMsg.data[0] == 0x00
    assert retMsg.data[1] == 0x30
    # Decode data
    dec = sysex_data.decode(retMsg.data[2:])
    assert dec is not None
    metadata = json.loads(bytes(dec))
    assert metadata is not None
    # TODO: Adjust check
    assert len(metadata.keys()) == 2
Пример #4
0
def test_delete_project():
    # Setup
    f = mock.Mock()
    ctrl = midi_full.MidiProjectController(callback=f)
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    proj = cfg.getActiveProjectOrDefault()
    proj.stopProcessing()
    # Get active project metadata
    testMsg = mido.Message('sysex')
    testMsg.data = [0x00, 0x70] + sysex_data.encode(proj.id)
    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, proj)
    assert f.call_count == 1
    retMsg = f.call_args[0][0]
    # Check response message ID
    assert retMsg.data[0] == 0x00
    assert retMsg.data[1] == 0x70
Пример #5
0
def test_activate_project_successful():
    # Setup
    f = mock.Mock()
    ctrl = midi_full.MidiProjectController(callback=f)
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    proj = cfg.getActiveProjectOrDefault()  # type: project.Project
    proj.stopProcessing()
    # Activate project
    testMsg = mido.Message('sysex')
    testMsg.data = [0x00, 0x40] + sysex_data.encode(
        bytes(proj.id, encoding='utf8'))

    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, proj)
    assert f.call_count == 1
    retMsg = f.call_args[0][0]
    # Check response message ID
    assert retMsg.data[0] == 0x00
    assert retMsg.data[1] == 0x40
Пример #6
0
def test_import_project_error():
    # Setup
    f = mock.Mock()
    ctrl = midi_full.MidiProjectController(callback=f)
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    proj = cfg.getActiveProjectOrDefault()  # type: project.Project
    proj.stopProcessing()
    # Activate project
    testMsg = mido.Message('sysex')
    invalidJson = jsonpickle.encode(testMsg)
    gzip = zlib.compress(bytes(invalidJson, encoding='utf8'))
    testMsg.data = [0x00, 0x50] + sysex_data.encode(bytes(gzip))

    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, proj)
    assert f.call_count == 1
    retMsg = f.call_args[0][0]
    # Check response message ID
    assert retMsg.data[0] == 0x00
    assert retMsg.data[1] == 0x5F
Пример #7
0
def test_get_server_config():
    # Setup
    f = mock.Mock()
    ctrl = midi_full.MidiProjectController(callback=f)
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    # Get active project metadata
    testMsg = mido.Message('sysex')
    testMsg.data = [0x02, 0x00]
    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, None)
    assert f.call_count == 1
    retMsg = f.call_args[0][0]
    # Check response message ID
    assert retMsg.data[0] == 0x02
    assert retMsg.data[1] == 0x00
    # Decode data
    dec = sysex_data.decode(retMsg.data[2:])
    dec = zlib.decompress(bytes(dec))
    j_dict = json.loads(dec)
    assert j_dict is not None
    print(j_dict)
    assert not j_dict["advertise_bluetooth"]
Пример #8
0
def test_update_server_config():
    # Setup
    f = mock.Mock()
    ctrl = midi_full.MidiProjectController(callback=f)
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    assert not cfg.getConfiguration(
        serverconfiguration.CONFIG_ADVERTISE_BLUETOOTH)
    # Get active project metadata
    j_dict = json.dumps({"advertise_bluetooth": True})
    gzip = zlib.compress(bytes(j_dict, encoding='utf8'))

    testMsg = mido.Message('sysex')
    testMsg.data = [0x02, 0x10] + sysex_data.encode(bytes(gzip))

    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, None)
    assert f.call_count == 1
    retMsg = f.call_args[0][0]
    # Check response message ID
    assert retMsg.data[0] == 0x02
    assert retMsg.data[1] == 0x10

    assert cfg.getConfiguration(serverconfiguration.CONFIG_ADVERTISE_BLUETOOTH)
Пример #9
0
def test_export_project():
    # Setup
    f = mock.Mock()
    ctrl = midi_full.MidiProjectController(callback=f)
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    proj = cfg.getActiveProjectOrDefault()
    proj.stopProcessing()
    # Get active project metadata
    testMsg = mido.Message('sysex')
    testMsg.data = [0x00, 0x60] + sysex_data.encode(proj.id)
    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, proj)
    assert f.call_count == 1
    retMsg = f.call_args[0][0]
    # Check response message ID
    assert retMsg.data[0] == 0x00
    assert retMsg.data[1] == 0x60
    # Decode data
    dec = sysex_data.decode(retMsg.data[2:])
    dec = zlib.decompress(bytes(dec))
    restoredProj = jsonpickle.loads(dec)  # type project.Project
    assert restoredProj is not None
    assert restoredProj.id == proj.id
Пример #10
0
def test_import_project_successful():
    # Setup
    f = mock.Mock()
    ctrl = midi_full.MidiProjectController(callback=f)
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    proj = cfg.getActiveProjectOrDefault()
    proj.stopProcessing()
    assert len(cfg.getProjectsMetadata().keys()) == 1
    proj.id = "testproj"
    projJson = jsonpickle.dumps(proj)
    print(projJson)
    projGzip = zlib.compress(bytes(projJson, encoding='utf8'))
    # Get active project metadata
    testMsg = mido.Message('sysex')
    testMsg.data = [0x00, 0x50] + sysex_data.encode(bytes(projGzip))
    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, proj)
    assert f.call_count == 1
    retMsg = f.call_args[0][0]
    # Check response message ID
    assert retMsg.data[0] == 0x00
    assert retMsg.data[1] == 0x50
    assert len(cfg.getProjectsMetadata().keys()) == 2
                        help="Perform strand test at start of server.")

    # print audio information
    print("The following audio devices are available:")
    audio.print_audio_devices()

    args = parser.parse_args()
    config_location = None
    if args.config_location is None:
        config_location = os.path.join(os.path.expanduser("~"), '.ledserver')
    else:
        config_location = os.path.join(args.config_location, '.ledserver')

    if args.no_conf:
        print("Using in-memory configuration")
        serverconfig = serverconfiguration.ServerConfiguration()
    else:
        print("Using configuration from {}".format(config_location))
        serverconfig = serverconfiguration.PersistentConfiguration(
            config_location, args.no_store)

    print("Applying arguments")

    # Update num pixels
    if args.num_pixels is not None:
        num_pixels = args.num_pixels
        serverconfig.setConfiguration(serverconfiguration.CONFIG_NUM_PIXELS,
                                      num_pixels)

    # Update num rows
    if args.num_rows is not None: