Пример #1
0
def f():
    def callback(message, *args):
        print(message.command)
        print(message.content)

    conn = Connection()
    conn.connect(passwd='Swordfish')
    listener = EventListener(conn)
    listener.start()
    listener.subscribe('foregroundColorChanged', callback)
    conn.send_sync('app.foregroundColor.rgb.red=0')
    conn.send_sync('app.foregroundColor.rgb.red=10')
    conn.send_sync('app.foregroundColor.rgb.red=20')
    conn.send_sync('app.foregroundColor.rgb.red=30')
    time.sleep(2)
    print('done')
Пример #2
0
def test_foo():
    conn = Connection()
    conn.connect(passwd='Swordfish')
    #conn.send('alert("Hello");', True)

    print conn.send_sync('$.version;')

    def callback(message, *args):
        print message.command
        print message.content

    def callback2(message, *args):
        print message.command
        print message.content
        print args

    listener = EventListener(conn)
    listener.start()
    listener.subscribe('foregroundColorChanged', callback)
    listener.subscribe('documentChanged', callback2, (True, 'xxx'))

    conn.send_sync('app.documents.add(100, 100)')

    print 'test_foo'
    time.sleep(3)
    listener.stop()
Пример #3
0
def test_script():
    c = Connection()
    c.connect('Swordfish')

    res = c.send_sync('$.version;')
    assert res.command == six.b('4.5.8')

    res = c.send_sync('$.os')
    assert res.command == six.b('Windows')

    res = c.send_sync('alert(x);')
    assert res.command == six.b('')

    c.close()
Пример #4
0
def test_foo():
    conn = Connection()
    conn.connect(passwd='Swordfish')
    # list(conn.send('alert("Hello");'))

    print(conn.send_sync('$.version;'))

    def callback(message, *args):
        print(message.command)
        print(message.content)

    def callback2(message, *args):
        print(message.command)
        print(message.content)
        print(args)

    listener = EventListener(conn)
    listener.start()
    listener.subscribe('foregroundColorChanged', callback)
    listener.subscribe('documentChanged', callback2, (True, 'xxx'))

    conn.send_sync('app.documents.add(100, 100)')

    print('test_foo')
    time.sleep(3)
    listener.stop()
Пример #5
0
def f():
    def callback(message, *args):
        print(message.command)
        print(message.content)

    conn = Connection()
    conn.connect(passwd='Swordfish')
    listener = EventListener(conn)
    listener.start()
    listener.subscribe('foregroundColorChanged', callback)
    conn.send_sync('app.foregroundColor.rgb.red=0')
    conn.send_sync('app.foregroundColor.rgb.red=10')
    conn.send_sync('app.foregroundColor.rgb.red=20')
    conn.send_sync('app.foregroundColor.rgb.red=30')
    time.sleep(2)
    print('done')
Пример #6
0
def test_script():
    c = Connection()
    c.connect('Swordfish')

    res = c.send_sync('$.version;')
    assert res.command == six.b('4.5.8')

    res = c.send_sync('$.os')
    assert res.command == six.b('Windows')

    res = c.send_sync('alert(x);')
    assert res.command == six.b('')

    c.close()
Пример #7
0
    def test_script(self):
        c = Connection()
        c.connect('Swordfish')

        res = c.send_sync('$.version;')
        self.assertEqual(res.command, '4.5.6')
        self.assertEqual(repr(res), '<4.5.6:>')

        res = c.send_sync('$.os')
        self.assertEqual(res.command, 'Windows 7/64 6.3  ')

        res = c.send_sync('alert(x);')
        self.assertEqual(res.command, '')

        c.close()
Пример #8
0
def test_listener():
    c = Connection()
    c.connect('Swordfish')
    c.send_sync('app.foregroundColor.rgb.red=255')

    e = EventListener.connect('Swordfish', interval=0.2)
    e.start()
    e.subscribe('foregroundColorChanged', callback)
    e.subscribe('backgroundColorChanged', callback2)
    time.sleep(1)
    
    c.send_sync('app.foregroundColor.rgb.red=0')
    c.send_sync('app.foregroundColor.rgb.red=10')
    c.send_sync('app.foregroundColor.rgb.red=20')
    c.send_sync('app.foregroundColor.rgb.red=30')
    
    c.send_sync('app.backgroundColor.rgb.red=0')
    c.send_sync('app.backgroundColor.rgb.red=10')
    c.send_sync('app.backgroundColor.rgb.red=20')
    c.send_sync('app.backgroundColor.rgb.red=30')

    i = 0
    while i < 2:
        time.sleep(1)
        i += 1

    e.unsubscribe('foregroundColorChanged', callback)
    e.unsubscribe('backgroundColorChanged', callback2)

    e.stop()
    c.close()
Пример #9
0
def test_connection():
    c = Connection()
    c.connect('Swordfish')
    assert c.isConnected is True
    c.close()
Пример #10
0
def test_bad_password():
    conn = Connection()
    conn.connect(passwd='Swordfish1')
    with pytest.raises(ConnectionError):
        conn.send_sync('$.version;')
Пример #11
0
 def test_connection(self):
     
     c = Connection()
     c.connect('Swordfish')
     self.assertTrue(c.isConnected)
     c.close()
Пример #12
0
def test_listener():
    c = Connection()
    c.connect('Swordfish')
    c.send_sync('app.foregroundColor.rgb.red=255')

    e = EventListener.connect('Swordfish', interval=0.2)
    e.start()
    e.subscribe('foregroundColorChanged', callback)
    e.subscribe('backgroundColorChanged', callback2)
    time.sleep(1)

    c.send_sync('app.foregroundColor.rgb.red=0')
    c.send_sync('app.foregroundColor.rgb.red=10')
    c.send_sync('app.foregroundColor.rgb.red=20')
    c.send_sync('app.foregroundColor.rgb.red=30')

    c.send_sync('app.backgroundColor.rgb.red=0')
    c.send_sync('app.backgroundColor.rgb.red=10')
    c.send_sync('app.backgroundColor.rgb.red=20')
    c.send_sync('app.backgroundColor.rgb.red=30')

    i = 0
    while i < 2:
        time.sleep(1)
        i += 1

    e.unsubscribe('foregroundColorChanged', callback)
    e.unsubscribe('backgroundColorChanged', callback2)

    e.stop()
    c.close()
Пример #13
0
def test_connection():
    c = Connection()
    c.connect('Swordfish')
    assert c.isConnected is True
    c.close()
Пример #14
0
def test_bad_password():
    conn = Connection()
    conn.connect(passwd='Swordfish1')
    with pytest.raises(ConnectionError):
        conn.send_sync('$.version;')