예제 #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")))