コード例 #1
0
def test_depth_image(user, snapshot):
    data = create_stream(user, [snapshot]).read()
    result = run_parser('depth_image', data)
    timestamp = dt.datetime.fromtimestamp(snapshot.datetime / 1000)
    out_path = Context.work_path + f'/depth_image-{str(timestamp)}.jpg'
    expected = {'snapshot_id': snapshot.datetime, 'path': out_path}
    assert json.loads(result) == expected
コード例 #2
0
ファイル: test_proto.py プロジェクト: shlomow/bubbles
def test_proto_reader(user, snapshot):
    stream = create_stream(user, [snapshot])

    reader = ProtoReader(stream)
    assert reader.user == user

    snapshots_iter = iter(reader)
    assert next(snapshots_iter) == snapshot
    with pytest.raises(StopIteration):
        next(snapshots_iter)
コード例 #3
0
def test_feelings(user, snapshot):
    data = create_stream(user, [snapshot]).read()
    result = run_parser('snapshot_meta', data)
    timestamp = snapshot.datetime / 1000
    expected = {
        'snapshot_id': snapshot.datetime,
        'user_id': user.user_id,
        'datetime': str(dt.datetime.fromtimestamp(timestamp))
    }
    assert json.loads(result) == expected
コード例 #4
0
def test_feelings(user, snapshot):
    data = create_stream(user, [snapshot]).read()
    result = run_parser('feelings', data)
    expected = {
        'snapshot_id': snapshot.datetime,
        'hunger': snapshot.feelings.hunger,
        'thirst': snapshot.feelings.thirst,
        'exhaustion': snapshot.feelings.exhaustion,
        'happiness': snapshot.feelings.happiness
    }
    assert json.loads(result) == expected
コード例 #5
0
ファイル: test_reader.py プロジェクト: shlomow/bubbles
def test_reader_gzip(tmp_path, user, snapshot):
    stream = create_stream(user, [snapshot])

    path = tmp_path / 'snapshot.data.gz'
    path.write_bytes(gzip.compress(stream.read()))

    reader = Reader(str(path), 'protobuf')
    assert reader.user == user

    snapshots_iter = iter(reader)
    assert next(snapshots_iter) == snapshot
    with pytest.raises(StopIteration):
        next(snapshots_iter)
コード例 #6
0
def test_client_cli(server_pipe, tmp_path, user, snapshot):
    data = create_stream(user, [snapshot]).read()
    path = tmp_path / 'snapshot.raw'
    path.write_bytes(data)

    process = subprocess.Popen(
        ['python', '-m', 'bubbles.client', 'upload-sample',
         '-h', _HOST, '-p', str(_PORT), str(path)]
    )

    process.communicate()

    assert server_pipe.recv() == data
コード例 #7
0
ファイル: test_parse_pose.py プロジェクト: shlomow/bubbles
def test_pose(user, snapshot):
    data = create_stream(user, [snapshot]).read()
    result = run_parser('pose', data)
    expected = {
        'snapshot_id': snapshot.datetime,
        'translation': [snapshot.pose.translation.x,
                        snapshot.pose.translation.y,
                        snapshot.pose.translation.z],
        'rotation': [snapshot.pose.rotation.x,
                     snapshot.pose.rotation.y,
                     snapshot.pose.rotation.z,
                     snapshot.pose.rotation.w]
    }
    assert json.loads(result) == expected
コード例 #8
0
def test_depth_image_cli(tmp_path, user, snapshot):
    data = create_stream(user, [snapshot]).read()
    path = tmp_path / 'snapshot.raw'
    path.write_bytes(data)

    process = subprocess.Popen(
        ['python', '-m', 'bubbles.parsers', 'parse', 'depth_image',
         str(path)],
        stdout=subprocess.PIPE,
    )

    stdout, _ = process.communicate()

    timestamp = dt.datetime.fromtimestamp(snapshot.datetime / 1000)
    out_path = Context.work_path + f'/depth_image-{str(timestamp)}.jpg'
    expected = {'snapshot_id': snapshot.datetime, 'path': out_path}

    assert json.loads(stdout) == expected
コード例 #9
0
def test_feelings_cli(tmp_path, user, snapshot):
    data = create_stream(user, [snapshot]).read()
    path = tmp_path / 'snapshot.raw'
    path.write_bytes(data)

    process = subprocess.Popen(
        ['python', '-m', 'bubbles.parsers',
         'parse', 'snapshot_meta', str(path)],
        stdout=subprocess.PIPE,
    )

    stdout, _ = process.communicate()

    timestamp = snapshot.datetime / 1000
    expected = {
        'snapshot_id': snapshot.datetime,
        'user_id': user.user_id,
        'datetime': str(dt.datetime.fromtimestamp(timestamp))
    }

    assert json.loads(stdout) == expected
コード例 #10
0
def test_feelings_cli(tmp_path, user, snapshot):
    data = create_stream(user, [snapshot]).read()
    path = tmp_path / 'snapshot.raw'
    path.write_bytes(data)

    process = subprocess.Popen(
        ['python', '-m', 'bubbles.parsers', 'parse', 'feelings',
         str(path)],
        stdout=subprocess.PIPE,
    )

    stdout, _ = process.communicate()

    expected = {
        'snapshot_id': snapshot.datetime,
        'hunger': snapshot.feelings.hunger,
        'thirst': snapshot.feelings.thirst,
        'exhaustion': snapshot.feelings.exhaustion,
        'happiness': snapshot.feelings.happiness
    }

    assert json.loads(stdout) == expected
コード例 #11
0
ファイル: test_parse_pose.py プロジェクト: shlomow/bubbles
def test_pose_cli(tmp_path, user, snapshot):
    data = create_stream(user, [snapshot]).read()
    path = tmp_path / 'snapshot.raw'
    path.write_bytes(data)

    process = subprocess.Popen(
        ['python', '-m', 'bubbles.parsers', 'parse', 'pose', str(path)],
        stdout=subprocess.PIPE,
    )

    stdout, _ = process.communicate()

    expected = {
        'snapshot_id': snapshot.datetime,
        'translation': [snapshot.pose.translation.x,
                        snapshot.pose.translation.y,
                        snapshot.pose.translation.z],
        'rotation': [snapshot.pose.rotation.x,
                     snapshot.pose.rotation.y,
                     snapshot.pose.rotation.z,
                     snapshot.pose.rotation.w]
    }

    assert json.loads(stdout) == expected
コード例 #12
0
def test_run_error(user, snapshot):
    data = create_stream(user, [snapshot]).read()
    with pytest.raises(ValueError):
        run_parser('blabla', data)
コード例 #13
0
def test_upload_sample(server_pipe, tmp_path, user, snapshot):
    data = create_stream(user, [snapshot]).read()
    path = tmp_path / 'snapshot.raw'
    path.write_bytes(data)
    upload_sample(_HOST, _PORT, str(path))
    assert server_pipe.recv() == data