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)
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)
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)
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)
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)
def test_parse_unknown(): with pytest.raises(ValueError): list(Parser(io.StringIO("foo")))
def test_parse_ignored(): with warnings.catch_warnings(): warnings.simplefilter('error') with pytest.raises(UnsupportedCommand): list(Parser(io.StringIO("p 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)
def test_context_parser(): with mock.patch("io.open") as open: with Parser("foo.obj") as parser: assert isinstance(parser, Parser)
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()
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")
def test_parse_material_bad(): with pytest.raises(ValueError): list(Parser(io.StringIO("usemtl")))
def test_parse_material(): result = list(Parser(io.StringIO("usemtl brick"))) assert len(result) == 1 assert isinstance(result[0], Material) assert result[0] == "brick"
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"}
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"}
def test_parse_face_indexes_bad2(): with pytest.raises(ValueError): list(Parser(io.StringIO("f 1")))