Ejemplo n.º 1
0
def test_events_poll_idle():
    conn = mock.MagicMock()
    conn.transact.return_value = ''
    events = picraft.events.Events(conn)
    events.include_idle = True
    result = events.poll()
    assert len(result) == 1
    assert isinstance(result[0], IdleEvent)
Ejemplo n.º 2
0
def test_events_poll_idle():
    conn = mock.MagicMock()
    conn.transact.return_value = ''
    events = picraft.events.Events(conn)
    events.include_idle = True
    result = events.poll()
    assert len(result) == 1
    assert isinstance(result[0], IdleEvent)
Ejemplo n.º 3
0
def test_events_poll_one_hit():
    conn = mock.MagicMock()
    conn.transact.return_value = '1,2,3,4,5'
    events = picraft.events.Events(conn)
    result = events.poll()
    assert len(result) == 1
    assert result[0].pos == Vector(1, 2, 3)
    assert result[0].face == 'x-'
    assert result[0].player.player_id == 5
    conn.transact.assert_called_once_with('events.block.hits()')
Ejemplo n.º 4
0
def test_events_poll_one_hit():
    conn = mock.MagicMock()
    conn.transact.return_value = "1,2,3,4,5"
    events = picraft.events.Events(conn)
    result = events.poll()
    assert len(result) == 1
    assert result[0].pos == Vector(1, 2, 3)
    assert result[0].face == "x-"
    assert result[0].player.player_id == 5
    conn.transact.assert_called_once_with("events.block.hits()")
Ejemplo n.º 5
0
def test_events_post_message():
    conn = mock.MagicMock()
    conn.server_version = 'raspberry-juice'
    conn.transact.side_effect = ['', '1,Hello world!']
    events = picraft.events.Events(conn)
    result = events.poll()
    assert len(result) == 1
    assert result[0].message == 'Hello world!'
    assert result[0].player.player_id == 1
    conn.transact.assert_any_call('events.block.hits()')
    conn.transact.assert_any_call('events.chat.posts()')
Ejemplo n.º 6
0
def test_events_poll_one_hit():
    conn = mock.MagicMock()
    conn.transact.return_value = '1,2,3,4,5'
    events = picraft.events.Events(conn)
    result = events.poll()
    assert len(result) == 1
    assert isinstance(result[0], BlockHitEvent)
    assert result[0].pos == Vector(1, 2, 3)
    assert result[0].face == 'x-'
    assert result[0].player.player_id == 5
    conn.transact.assert_called_once_with('events.block.hits()')
Ejemplo n.º 7
0
def test_events_post_message():
    conn = mock.MagicMock()
    conn.server_version = 'raspberry-juice'
    conn.transact.side_effect = ['', '1,Hello world!']
    events = picraft.events.Events(conn)
    result = events.poll()
    assert len(result) == 1
    assert result[0].message == 'Hello world!'
    assert result[0].player.player_id == 1
    conn.transact.assert_any_call('events.block.hits()')
    conn.transact.assert_any_call('events.chat.posts()')
Ejemplo n.º 8
0
def test_events_poll_multi_hits():
    conn = mock.MagicMock()
    conn.transact.return_value = '1,2,3,4,5|-1,0,0,0,1'
    events = picraft.events.Events(conn)
    result = events.poll()
    assert len(result) == 2
    assert result[0].pos == Vector(1, 2, 3)
    assert result[0].face == 'x-'
    assert result[0].player.player_id == 5
    assert result[1].pos == Vector(-1, 0, 0)
    assert result[1].face == 'y-'
    assert result[1].player.player_id == 1
    conn.transact.assert_called_once_with('events.block.hits()')
Ejemplo n.º 9
0
def test_events_poll_one_move():
    conn = mock.MagicMock()
    conn.transact.side_effect = ['1.0,1.0,1.0', '1.1,1.0,1.0', '']
    events = picraft.events.Events(conn)
    events.track_players = {1}
    result = events.poll()
    assert len(result) == 1
    assert isinstance(result[0], PlayerPosEvent)
    assert result[0].old_pos == Vector(1.0, 1.0, 1.0)
    assert result[0].new_pos == Vector(1.1, 1.0, 1.0)
    assert result[0].player.player_id == 1
    conn.transact.assert_has_calls([
        mock.call('entity.getPos(1)'),
        mock.call('entity.getPos(1)'),
        mock.call('events.block.hits()'),
    ])
Ejemplo n.º 10
0
def test_events_poll_one_move():
    conn = mock.MagicMock()
    conn.transact.side_effect = ['1.0,1.0,1.0', '1.1,1.0,1.0', '']
    events = picraft.events.Events(conn)
    events.track_players = {1}
    result = events.poll()
    assert len(result) == 1
    assert isinstance(result[0], PlayerPosEvent)
    assert result[0].old_pos == Vector(1.0, 1.0, 1.0)
    assert result[0].new_pos == Vector(1.1, 1.0, 1.0)
    assert result[0].player.player_id == 1
    conn.transact.assert_has_calls([
        mock.call('entity.getPos(1)'),
        mock.call('entity.getPos(1)'),
        mock.call('events.block.hits()'),
        ])
Ejemplo n.º 11
0
def test_events_poll_empty():
    conn = mock.MagicMock()
    conn.transact.return_value = ''
    events = picraft.events.Events(conn)
    assert events.poll() == []
    conn.transact.assert_called_once_with('events.block.hits()')
Ejemplo n.º 12
0
def test_events_poll_empty():
    conn = mock.MagicMock()
    conn.transact.return_value = ""
    events = picraft.events.Events(conn)
    assert events.poll() == []
    conn.transact.assert_called_once_with("events.block.hits()")