Merge pull request #101443 from Repiteo/ci/replace-pytest

CI: Replace pytest with pre-commit hook
This commit is contained in:
Thaddeus Crews
2025-03-30 09:06:00 -05:00
20 changed files with 462 additions and 749 deletions

View File

@ -1,26 +0,0 @@
import os
import sys
from pathlib import Path
import pytest
CWD = Path(__file__).parent
ROOT = CWD.parent.parent
# append directory with build files to sys.path to import them
sys.path.append(str(ROOT))
@pytest.fixture
def shader_files(request):
shader_path = request.param
res = {
"path_input": str(CWD / "fixtures" / f"{shader_path}.glsl"),
"path_output": str(CWD / "fixtures" / f"{shader_path}.glsl.gen.h"),
"path_expected_full": str(CWD / "fixtures" / f"{shader_path}_expected_full.glsl"),
"path_expected_parts": str(CWD / "fixtures" / f"{shader_path}_expected_parts.json"),
}
yield res
if not os.getenv("PYTEST_KEEP_GENERATED_FILES"):
os.remove(res["path_output"])

View File

@ -0,0 +1,64 @@
#include "drivers/gles3/shader_gles3.h"
class VertexFragmentShaderGLES3 : public ShaderGLES3 {
public:
enum ShaderVariant {
MODE_NINEPATCH,
};
enum Specializations {
DISABLE_LIGHTING = 1,
};
_FORCE_INLINE_ bool version_bind_shader(RID p_version, ShaderVariant p_variant, uint64_t p_specialization = 0) {
return _version_bind_shader(p_version, p_variant, p_specialization);
}
protected:
virtual void _init() override {
static const char **_uniform_strings = nullptr;
static const char *_variant_defines[] = {
"#define USE_NINEPATCH",
};
static TexUnitPair *_texunit_pairs = nullptr;
static UBOPair *_ubo_pairs = nullptr;
static Specialization _spec_pairs[] = {
{ "DISABLE_LIGHTING", false },
};
static const Feedback *_feedbacks = nullptr;
static const char _vertex_code[] = {
R"<!>(
precision highp float;
precision highp int;
layout(location = 0) in highp vec3 vertex;
out highp vec4 position_interp;
void main() {
position_interp = vec4(vertex.x,1,0,1);
}
)<!>"
};
static const char _fragment_code[] = {
R"<!>(
precision highp float;
precision highp int;
in highp vec4 position_interp;
void main() {
highp float depth = ((position_interp.z / position_interp.w) + 1.0);
frag_color = vec4(depth);
}
)<!>"
};
_setup(_vertex_code, _fragment_code, "VertexFragmentShaderGLES3",
0, _uniform_strings, 0, _ubo_pairs,
0, _feedbacks, 0, _texunit_pairs,
1, _spec_pairs, 1, _variant_defines);
}
};

View File

@ -1,71 +0,0 @@
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
#pragma once
#include "drivers/gles3/shader_gles3.h"
class VertexFragmentShaderGLES3 : public ShaderGLES3 {
public:
enum ShaderVariant {
MODE_NINEPATCH,
};
enum Specializations {
DISABLE_LIGHTING=1,
};
_FORCE_INLINE_ bool version_bind_shader(RID p_version,ShaderVariant p_variant,uint64_t p_specialization=0) { return _version_bind_shader(p_version,p_variant,p_specialization); }
protected:
virtual void _init() override {
static const char **_uniform_strings=nullptr;
static const char* _variant_defines[]={
"#define USE_NINEPATCH",
};
static TexUnitPair *_texunit_pairs=nullptr;
static UBOPair *_ubo_pairs=nullptr;
static Specialization _spec_pairs[]={
{"DISABLE_LIGHTING",false},
};
static const Feedback* _feedbacks=nullptr;
static const char _vertex_code[]={
R"<!>(
precision highp float;
precision highp int;
layout(location = 0) in highp vec3 vertex;
out highp vec4 position_interp;
void main() {
position_interp = vec4(vertex.x,1,0,1);
}
)<!>"
};
static const char _fragment_code[]={
R"<!>(
precision highp float;
precision highp int;
in highp vec4 position_interp;
void main() {
highp float depth = ((position_interp.z / position_interp.w) + 1.0);
frag_color = vec4(depth);
}
)<!>"
};
_setup(_vertex_code,_fragment_code,"VertexFragmentShaderGLES3",0,_uniform_strings,0,_ubo_pairs,0,_feedbacks,0,_texunit_pairs,1,_spec_pairs,1,_variant_defines);
}
};

View File

@ -1,53 +0,0 @@
{
"vertex_lines": [
"",
"precision highp float;",
"precision highp int;",
"",
"layout(location = 0) in highp vec3 vertex;",
"",
"out highp vec4 position_interp;",
"",
"void main() {",
"\tposition_interp = vec4(vertex.x,1,0,1);",
"}",
""
],
"fragment_lines": [
"",
"precision highp float;",
"precision highp int;",
"",
"in highp vec4 position_interp;",
"",
"void main() {",
"\thighp float depth = ((position_interp.z / position_interp.w) + 1.0);",
"\tfrag_color = vec4(depth);",
"}"
],
"uniforms": [],
"fbos": [],
"texunits": [],
"texunit_names": [],
"ubos": [],
"ubo_names": [],
"feedbacks": [],
"vertex_included_files": [],
"fragment_included_files": [],
"reading": "fragment",
"line_offset": 33,
"vertex_offset": 10,
"fragment_offset": 23,
"variant_defines": [
"#define USE_NINEPATCH"
],
"variant_names": [
"MODE_NINEPATCH"
],
"specialization_names": [
"DISABLE_LIGHTING"
],
"specialization_values": [
" false\n"
]
}

View File

@ -1,6 +1,3 @@
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
#pragma once
static const char compute_shader_glsl[] = {
R"<!>(#[compute]

View File

@ -1,3 +0,0 @@
{
"code": "#[compute]\n\n#version 450\n\n#VERSION_DEFINES\n\n\n#define M_PI 3.14159265359\n\nvoid main() {\n\tvec3 static_light = vec3(0, 1, 0);\n}\n"
}

View File

@ -1,6 +1,3 @@
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
#pragma once
static const char vertex_fragment_shader_glsl[] = {
R"<!>(#[versions]

View File

@ -1,3 +0,0 @@
{
"code": "#[versions]\n\nlines = \"#define MODE_LINES\";\n\n#[vertex]\n\n#version 450\n\n#VERSION_DEFINES\n\nlayout(location = 0) out vec3 uv_interp;\n\nvoid main() {\n\n#ifdef MODE_LINES\n\tuv_interp = vec3(0,0,1);\n#endif\n}\n\n#[fragment]\n\n#version 450\n\n#VERSION_DEFINES\n\n#define M_PI 3.14159265359\n\nlayout(location = 0) out vec4 dst_color;\n\nvoid main() {\n\tdst_color = vec4(1,1,0,0);\n}\n"
}

View File

@ -1,14 +1,10 @@
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
#pragma once
#include "servers/rendering/renderer_rd/shader_rd.h"
class ComputeShaderRD : public ShaderRD {
public:
ComputeShaderRD() {
static const char *_vertex_code = nullptr;
static const char *_fragment_code = nullptr;
static const char _compute_code[] = {
R"<!>(
#version 450
@ -24,6 +20,6 @@ void main() {
}
)<!>"
};
setup(nullptr, nullptr, _compute_code, "ComputeShaderRD");
setup(_vertex_code, _fragment_code, _compute_code, "ComputeShaderRD");
}
};

View File

@ -1,28 +0,0 @@
{
"vertex_lines": [],
"fragment_lines": [],
"compute_lines": [
"",
"#version 450",
"",
"#VERSION_DEFINES",
"",
"#define BLOCK_SIZE 8",
"",
"#define M_PI 3.14159265359",
"",
"void main() {",
"\tuint t = BLOCK_SIZE + 1;",
"}"
],
"vertex_included_files": [],
"fragment_included_files": [],
"compute_included_files": [
"tests/python_build/fixtures/rd_glsl/_included.glsl"
],
"reading": "compute",
"line_offset": 13,
"vertex_offset": 0,
"fragment_offset": 0,
"compute_offset": 1
}

View File

@ -1,14 +1,8 @@
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
#pragma once
#include "servers/rendering/renderer_rd/shader_rd.h"
class VertexFragmentShaderRD : public ShaderRD {
public:
VertexFragmentShaderRD() {
static const char _vertex_code[] = {
R"<!>(
#version 450
@ -38,6 +32,7 @@ void main() {
}
)<!>"
};
setup(_vertex_code, _fragment_code, nullptr, "VertexFragmentShaderRD");
static const char *_compute_code = nullptr;
setup(_vertex_code, _fragment_code, _compute_code, "VertexFragmentShaderRD");
}
};

View File

@ -1,40 +0,0 @@
{
"vertex_lines": [
"",
"#version 450",
"",
"#VERSION_DEFINES",
"",
"#define M_PI 3.14159265359",
"",
"layout(location = 0) out vec2 uv_interp;",
"",
"void main() {",
"\tuv_interp = vec2(0, 1);",
"}",
""
],
"fragment_lines": [
"",
"#version 450",
"",
"#VERSION_DEFINES",
"",
"layout(location = 0) in vec2 uv_interp;",
"",
"void main() {",
"\tuv_interp = vec2(1, 0);",
"}"
],
"compute_lines": [],
"vertex_included_files": [
"tests/python_build/fixtures/rd_glsl/_included.glsl"
],
"fragment_included_files": [],
"compute_included_files": [],
"reading": "fragment",
"line_offset": 25,
"vertex_offset": 1,
"fragment_offset": 15,
"compute_offset": 0
}

View File

@ -1,31 +0,0 @@
import json
import pytest
from gles3_builders import GLES3HeaderStruct, build_gles3_header
@pytest.mark.parametrize(
["shader_files", "builder", "header_struct"],
[
("gles3/vertex_fragment", build_gles3_header, GLES3HeaderStruct),
],
indirect=["shader_files"],
)
def test_gles3_builder(shader_files, builder, header_struct):
header = header_struct()
builder(shader_files["path_input"], "drivers/gles3/shader_gles3.h", "GLES3", header_data=header)
with open(shader_files["path_expected_parts"], "r", encoding="utf-8") as f:
expected_parts = json.load(f)
assert expected_parts == header.__dict__
with open(shader_files["path_output"], "r", encoding="utf-8") as f:
actual_output = f.read()
assert actual_output
with open(shader_files["path_expected_full"], "r", encoding="utf-8") as f:
expected_output = f.read()
assert actual_output == expected_output

View File

@ -1,37 +0,0 @@
import json
import pytest
from glsl_builders import RAWHeaderStruct, RDHeaderStruct, build_raw_header, build_rd_header
@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)
with open(shader_files["path_expected_parts"], "r", encoding="utf-8") as f:
expected_parts = json.load(f)
assert expected_parts == header.__dict__
with open(shader_files["path_output"], "r", encoding="utf-8") as f:
actual_output = f.read()
assert actual_output
with open(shader_files["path_expected_full"], "r", encoding="utf-8") as f:
expected_output = f.read()
assert actual_output == expected_output

View File

@ -0,0 +1,63 @@
#!/usr/bin/env python3
from __future__ import annotations
if __name__ != "__main__":
raise ImportError(f"{__name__} should not be used as a module.")
import os
import sys
from typing import Any, Callable
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../"))
from gles3_builders import build_gles3_header
from glsl_builders import build_raw_header, build_rd_header
FUNC_PATH_KWARGS: list[tuple[Callable[..., None], str, dict[str, Any]]] = [
(
build_gles3_header,
"tests/python_build/fixtures/gles3/vertex_fragment.out",
{"shader": "tests/python_build/fixtures/gles3/vertex_fragment.glsl"},
),
(
build_raw_header,
"tests/python_build/fixtures/glsl/compute.out",
{"shader": "tests/python_build/fixtures/glsl/compute.glsl"},
),
(
build_raw_header,
"tests/python_build/fixtures/glsl/vertex_fragment.out",
{"shader": "tests/python_build/fixtures/glsl/vertex_fragment.glsl"},
),
(
build_rd_header,
"tests/python_build/fixtures/rd_glsl/compute.out",
{"shader": "tests/python_build/fixtures/rd_glsl/compute.glsl"},
),
(
build_rd_header,
"tests/python_build/fixtures/rd_glsl/vertex_fragment.out",
{"shader": "tests/python_build/fixtures/rd_glsl/vertex_fragment.glsl"},
),
]
def main() -> int:
ret = 0
for func, path, kwargs in FUNC_PATH_KWARGS:
if os.path.exists(out_path := os.path.abspath(path)):
with open(out_path, "rb") as file:
raw = file.read()
func(path, **kwargs)
with open(out_path, "rb") as file:
if raw != file.read():
ret += 1
else:
func(path, **kwargs)
ret += 1
return ret
sys.exit(main())