Skip to content

Commit 4874a16

Browse files
committed
Remove useless compilation code
1 parent d160d2c commit 4874a16

4 files changed

Lines changed: 10 additions & 259 deletions

File tree

tests/conftest.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/generate.py

Lines changed: 0 additions & 171 deletions
This file was deleted.

tests/test_inputs.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copy
12
import importlib
23
import json
34
import math
@@ -12,12 +13,7 @@
1213
import betterproto2
1314
from tests.inputs import config as test_input_config
1415
from tests.mocks import MockChannel
15-
from tests.util import (
16-
find_module,
17-
get_directories,
18-
get_test_case_json_data,
19-
inputs_path,
20-
)
16+
from tests.util import find_module, get_directories, get_test_case_json_data, inputs_path
2117

2218
# Force pure-python implementation instead of C++, otherwise imports
2319
# break things because we can't properly reset the symbol database.
@@ -113,6 +109,13 @@ def dict_replace_nans(input_dict: dict[Any, Any]) -> dict[Any, Any]:
113109
return result
114110

115111

112+
@pytest.fixture
113+
def reset_sys_path():
114+
original = copy.deepcopy(sys.path)
115+
yield
116+
sys.path = original
117+
118+
116119
@pytest.fixture
117120
def test_data(request, reset_sys_path):
118121
test_case_name = request.param

tests/util.py

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import asyncio
2-
import atexit
31
import importlib
42
import os
5-
import platform
6-
import sys
7-
import tempfile
8-
from collections.abc import Callable, Generator
3+
from collections.abc import Callable
94
from dataclasses import dataclass
105
from pathlib import Path
116
from types import ModuleType
@@ -14,78 +9,13 @@
149

1510
root_path = Path(__file__).resolve().parent
1611
inputs_path = root_path.joinpath("inputs")
17-
output_path_reference = root_path.joinpath("output_reference")
18-
output_path_betterproto = root_path.joinpath("output_betterproto")
19-
output_path_betterproto_pydantic = root_path.joinpath("output_betterproto_pydantic")
20-
21-
22-
def get_files(path, suffix: str) -> Generator[str, None, None]:
23-
for r, dirs, files in os.walk(path):
24-
for filename in [f for f in files if f.endswith(suffix)]:
25-
yield os.path.join(r, filename)
2612

2713

2814
def get_directories(path):
2915
for root, directories, files in os.walk(path):
3016
yield from directories
3117

3218

33-
async def protoc(
34-
path: str | Path,
35-
output_dir: str | Path,
36-
reference: bool = False,
37-
pydantic_dataclasses: bool = False,
38-
):
39-
path: Path = Path(path).resolve()
40-
output_dir: Path = Path(output_dir).resolve()
41-
python_out_option: str = "python_betterproto_out" if not reference else "python_out"
42-
43-
if pydantic_dataclasses:
44-
plugin_path = Path("src/betterproto2/plugin/main.py")
45-
46-
if "Win" in platform.system():
47-
with tempfile.NamedTemporaryFile("w", encoding="UTF-8", suffix=".bat", delete=False) as tf:
48-
# See https://stackoverflow.com/a/42622705
49-
tf.writelines(
50-
[
51-
"@echo off",
52-
f"\nchdir {os.getcwd()}",
53-
f"\n{sys.executable} -u {plugin_path.as_posix()}",
54-
]
55-
)
56-
57-
tf.flush()
58-
59-
plugin_path = Path(tf.name)
60-
atexit.register(os.remove, plugin_path)
61-
62-
command = [
63-
sys.executable,
64-
"-m",
65-
"grpc.tools.protoc",
66-
f"--plugin=protoc-gen-custom={plugin_path.as_posix()}",
67-
"--experimental_allow_proto3_optional",
68-
"--custom_opt=pydantic_dataclasses",
69-
f"--proto_path={path.as_posix()}",
70-
f"--custom_out={output_dir.as_posix()}",
71-
*[p.as_posix() for p in path.glob("*.proto")],
72-
]
73-
else:
74-
command = [
75-
sys.executable,
76-
"-m",
77-
"grpc.tools.protoc",
78-
f"--proto_path={path.as_posix()}",
79-
f"--{python_out_option}={output_dir.as_posix()}",
80-
*[p.as_posix() for p in path.glob("*.proto")],
81-
]
82-
proc = await asyncio.create_subprocess_exec(
83-
*command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
84-
)
85-
stdout, stderr = await proc.communicate()
86-
return stdout, stderr, proc.returncode
87-
88-
8919
@dataclass
9020
class TestCaseJsonFile:
9121
json: str

0 commit comments

Comments
 (0)