示例#1
0
def test_parse_vertex_texture():
    result = list(Parser(io.StringIO("vt 0\nvt 1 2 3")))
    assert len(result) == 2
    assert isinstance(result[0], VertexTexture)
    assert result[0] == (0.0, 0.0, 0.0)
    assert isinstance(result[1], VertexTexture)
    assert result[1] == (1.0, 2.0, 3.0)
示例#2
0
def test_parse_vertex():
    result = list(Parser(io.StringIO("v 0 0 0\nv 1 2 3 4")))
    assert len(result) == 2
    assert isinstance(result[0], Vertex)
    assert result[0] == (0.0, 0.0, 0.0, 1.0)
    assert isinstance(result[1], Vertex)
    assert result[1] == (1.0, 2.0, 3.0, 4.0)
示例#3
0
def test_parse_face_indexes():
    result = list(Parser(io.StringIO("f 1/0/0 2 3 -1")))
    assert len(result) == 1
    assert isinstance(result[0], FaceIndexes)
    assert len(result[0]) == 4
    assert result[0][0] == (1, 0, 0)
    assert result[0][1] == (2, None, None)
    assert result[0][2] == (3, None, None)
    assert result[0][3] == (-1, None, None)
示例#4
0
def test_parse_vertex_normal():
    result = list(Parser(io.StringIO("vn 0 0 0")))
    assert len(result) == 1
    assert isinstance(result[0], VertexNormal)
    assert result[0] == (0.0, 0.0, 0.0)
示例#5
0
def test_parse_vertex_param():
    result = list(Parser(io.StringIO("vp 0 0 0")))
    assert len(result) == 1
    assert isinstance(result[0], VertexParameter)
    assert result[0] == (0.0, 0.0, 0.0)
示例#6
0
def test_parse_unknown():
    with pytest.raises(ValueError):
        list(Parser(io.StringIO("foo")))
示例#7
0
def test_parse_ignored():
    with warnings.catch_warnings():
        warnings.simplefilter('error')
        with pytest.raises(UnsupportedCommand):
            list(Parser(io.StringIO("p 0")))
示例#8
0
def test_parse_continuation():
    result = list(Parser(io.StringIO("v 0\\\n0 0")))
    assert len(result) == 1
    assert isinstance(result[0], Vertex)
    assert result[0] == (0.0, 0.0, 0.0, 1.0)
示例#9
0
def test_context_parser():
    with mock.patch("io.open") as open:
        with Parser("foo.obj") as parser:
            assert isinstance(parser, Parser)
示例#10
0
def test_close_parser():
    with mock.patch("io.open") as open:
        open.return_value = mock.MagicMock()
        Parser("foo.obj").close()
        open.return_value.close.assert_called_once_with()
示例#11
0
def test_parse_file():
    with mock.patch("io.open") as open:
        Parser("foo.obj")
        open.assert_called_with("foo.obj", "r", encoding="ascii")
        Parser(b"foo.obj")
        open.assert_called_with("foo.obj", "r", encoding="ascii")
示例#12
0
def test_parse_material_bad():
    with pytest.raises(ValueError):
        list(Parser(io.StringIO("usemtl")))
示例#13
0
def test_parse_material():
    result = list(Parser(io.StringIO("usemtl brick")))
    assert len(result) == 1
    assert isinstance(result[0], Material)
    assert result[0] == "brick"
示例#14
0
def test_parse_group_empty():
    result = list(Parser(io.StringIO("g")))
    assert len(result) == 1
    assert isinstance(result[0], Group)
    assert result[0].names == {"default"}
示例#15
0
def test_parse_group():
    result = list(Parser(io.StringIO("g group1 group2")))
    assert len(result) == 1
    assert isinstance(result[0], Group)
    assert result[0].names == {"group1", "group2"}
示例#16
0
def test_parse_face_indexes_bad2():
    with pytest.raises(ValueError):
        list(Parser(io.StringIO("f 1")))