2022-06-30 10:14:07 +08:00
|
|
|
import json
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2024-05-21 21:14:59 +08:00
|
|
|
from glsl_builders import RAWHeaderStruct, RDHeaderStruct, build_raw_header, build_rd_header
|
2022-06-30 10:14:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
[
|
|
|
|
"shader_files",
|
|
|
|
"builder",
|
|
|
|
"header_struct",
|
|
|
|
],
|
|
|
|
[
|
|
|
|
("glsl/vertex_fragment", build_raw_header, RAWHeaderStruct),
|
|
|
|
("glsl/compute", build_raw_header, RAWHeaderStruct),
|
|
|
|
("rd_glsl/vertex_fragment", build_rd_header, RDHeaderStruct),
|
|
|
|
("rd_glsl/compute", build_rd_header, RDHeaderStruct),
|
|
|
|
],
|
|
|
|
indirect=["shader_files"],
|
|
|
|
)
|
|
|
|
def test_glsl_builder(shader_files, builder, header_struct):
|
|
|
|
header = header_struct()
|
|
|
|
builder(shader_files["path_input"], header_data=header)
|
|
|
|
|
2024-03-25 01:02:56 +08:00
|
|
|
with open(shader_files["path_expected_parts"], "r", encoding="utf-8") as f:
|
2022-06-30 10:14:07 +08:00
|
|
|
expected_parts = json.load(f)
|
|
|
|
assert expected_parts == header.__dict__
|
|
|
|
|
2024-03-25 01:02:56 +08:00
|
|
|
with open(shader_files["path_output"], "r", encoding="utf-8") as f:
|
2022-06-30 10:14:07 +08:00
|
|
|
actual_output = f.read()
|
|
|
|
assert actual_output
|
|
|
|
|
2024-03-25 01:02:56 +08:00
|
|
|
with open(shader_files["path_expected_full"], "r", encoding="utf-8") as f:
|
2022-06-30 10:14:07 +08:00
|
|
|
expected_output = f.read()
|
|
|
|
|
|
|
|
assert actual_output == expected_output
|