def test_aux_reload_html_different(loop):
    aux_app = AuxiliaryApplication()
    ws = MagicMock()
    aux_app.update(websockets=[(ws, '/foo/bar')],
                   static_url='/static/',
                   static_path='/path/to/static_files/')
    assert aux_app.src_reload('/path/to/static_files/foo/bar.html') == 0
    assert ws.send_str.call_count == 0
def test_aux_reload_runtime_error(loop, caplog):
    aux_app = AuxiliaryApplication()
    ws = MagicMock()
    ws.send_str = MagicMock(side_effect=RuntimeError('foobar'))
    aux_app.update(websockets=[(ws, '/foo/bar')],
                   static_url='/static/',
                   static_path='/path/to/static_files/')
    assert aux_app.src_reload() == 0
    assert ws.send_str.call_count == 1
    assert 'adev.server.aux ERROR: Error broadcasting change to /foo/bar, RuntimeError: foobar\n' == caplog
def test_aux_reload_no_path(loop):
    aux_app = AuxiliaryApplication()
    ws = MagicMock()
    aux_app.update(websockets=[(ws, '/foo/bar')],
                   static_url='/static/',
                   static_path='/path/to/static_files/')
    assert aux_app.src_reload() == 1
    assert ws.send_str.call_count == 1
    send_obj = json.loads(ws.send_str.call_args[0][0])
    assert send_obj == {
        'command': 'reload',
        'path': '/foo/bar',
        'liveCSS': True,
        'liveImg': True,
    }
def test_aux_reload(loop, caplog):
    aux_app = AuxiliaryApplication()
    ws = MagicMock()
    aux_app.update(websockets=[(ws, '/foo/bar')],
                   static_url='/static/',
                   static_path='/path/to/static_files/')
    assert aux_app.src_reload('/path/to/static_files/the_file.js') == 1
    assert ws.send_str.call_count == 1
    send_obj = json.loads(ws.send_str.call_args[0][0])
    assert send_obj == {
        'command': 'reload',
        'path': '/static/the_file.js',
        'liveCSS': True,
        'liveImg': True,
    }
    assert 'adev.server.aux INFO: prompted reload of /static/the_file.js on 1 client\n' == caplog