Skip to content

Commit 7f2c19f

Browse files
Make tests more independant (#116)
* Add ignore_unknown_fields parameter * Add .gitignore * Remove .gitignore * Improve test generation * Fix poe commands * Fix first tests * Fix more tests * Fix more tests * Fix import * Fix workflow * Fix any test * Fix features test * Fix grpclib reflection test * Add missing tests * Fix service uppercase test * Fix stream_stream * Fix message enum descriptors * Fix casing * Fix nested twice * Fix more tests * Fix more tests * Fix more tests * Fix more tests * Fix more tests * Delete useless tests * Remove useless import * Fix first input tests * Fix more tests * Fix more tests * Add remaining tests * Disable ruff warning * Remove comments
1 parent 59f7441 commit 7f2c19f

File tree

61 files changed

+630
-447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+630
-447
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949

5050
- name: Move compiled files to betterproto2
5151
shell: bash
52-
run: mv betterproto2_compiler/tests/output_betterproto betterproto2_compiler/tests/output_betterproto_pydantic betterproto2_compiler/tests/output_betterproto_descriptor betterproto2_compiler/tests/output_reference betterproto2/tests
52+
run: cp -r betterproto2_compiler/tests/outputs betterproto2/tests
5353

5454
- name: Execute test suite
5555
working-directory: ./betterproto2

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
.python-version
88
build/
99
*/tests/output_*
10+
*/tests/outputs/*
1011
**/__pycache__
1112
dist
1213
**/*.egg-info
@@ -18,4 +19,4 @@ output
1819
.asv
1920
venv
2021
.devcontainer
21-
.ruff_cache
22+
.ruff_cache

betterproto2/pyproject.toml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ addopts = "-p no:warnings"
9292
# Dev workflow tasks
9393
[tool.poe.tasks.get-local-compiled-tests]
9494
# task useful for local development. Copies the compiled test files from the compiler folder to the tests folder
95-
shell = "rm -rf tests/output_* && cp -r ../betterproto2_compiler/tests/output_* tests"
95+
shell = "rm -rf tests/outputs* && cp -r ../betterproto2_compiler/tests/outputs tests"
9696

9797
[tool.poe.tasks.test]
9898
cmd = "pytest"
@@ -138,18 +138,6 @@ rm -rf .coverage .mypy_cache .pytest_cache
138138
"""
139139
help = "Clean out generated files from the workspace"
140140

141-
[tool.poe.tasks.pull-compiled-tests]
142-
shell = """
143-
rm -rf tests/output_* &&
144-
git clone https://github.com/betterproto/python-betterproto2-compiler --branch compiled-test-files --single-branch compiled_files &&
145-
mv compiled_files/tests_betterproto tests/output_betterproto &&
146-
mv compiled_files/tests_betterproto_pydantic tests/output_betterproto_pydantic &&
147-
mv compiled_files/tests_betterproto_pydantic tests/output_betterproto_descriptor &&
148-
mv compiled_files/tests_reference tests/output_reference &&
149-
rm -rf compiled_files
150-
"""
151-
help = "Pulls the compiled test files from the betterproto2-compiler repository"
152-
153141
[tool.poe.tasks.serve-docs]
154142
cmd = "mkdocs serve"
155143
help = "Serve the documentation locally"

betterproto2/tests/grpc/test_grpclib_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from grpclib.testing import ChannelFor
1010

1111
from tests.grpc.async_channel import AsyncChannel
12-
from tests.output_betterproto.service import (
12+
from tests.outputs.service.service import (
1313
DoThingRequest,
1414
DoThingResponse,
1515
GetThingRequest,

betterproto2/tests/grpc/test_grpclib_reflection.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
from grpclib.reflection.v1alpha.reflection_grpc import ServerReflectionBase as ServerReflectionBaseV1Alpha
99
from grpclib.testing import ChannelFor
1010

11-
from tests.output_betterproto.example_service import TestBase
12-
from tests.output_betterproto.grpc.reflection.v1 import (
11+
from tests.outputs.grpclib_reflection.example_service import TestBase
12+
from tests.outputs.grpclib_reflection.grpc.reflection.v1 import (
1313
ErrorResponse,
1414
ListServiceResponse,
1515
ServerReflectionRequest,
1616
ServerReflectionStub,
1717
ServiceResponse,
1818
)
19-
from tests.output_betterproto_descriptor.google_proto_descriptor_pool import default_google_proto_descriptor_pool
19+
from tests.outputs.grpclib_reflection_descriptors.google_proto_descriptor_pool import (
20+
default_google_proto_descriptor_pool,
21+
)
2022

2123

2224
class TestService(TestBase):
@@ -78,7 +80,7 @@ async def test_grpclib_reflection():
7880
assert response.file_descriptor_response is None
7981

8082
# now it should work
81-
import tests.output_betterproto_descriptor.example_service as example_service_with_desc
83+
import tests.outputs.grpclib_reflection_descriptors.example_service as example_service_with_desc
8284

8385
requests.put(ServerReflectionRequest(file_containing_symbol="example_service.Test"))
8486
response = await anext(responses)

betterproto2/tests/grpc/test_message_enum_descriptors.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import pytest
22

3-
from tests.output_betterproto.import_cousin_package_same_name.test.subpackage import Test
3+
from tests.outputs.import_cousin_package_same_name.import_cousin_package_same_name.test.subpackage import Test
44

55
# importing the cousin should cause no descriptor pool errors since the subpackage imports it once already
6-
from tests.output_betterproto_descriptor.import_cousin_package_same_name.cousin.subpackage import CousinMessage
7-
from tests.output_betterproto_descriptor.import_cousin_package_same_name.test.subpackage import Test as TestWithDesc
6+
from tests.outputs.import_cousin_package_same_name_descriptors.import_cousin_package_same_name.cousin.subpackage import ( # noqa: E501
7+
CousinMessage,
8+
)
9+
from tests.outputs.import_cousin_package_same_name_descriptors.import_cousin_package_same_name.test.subpackage import (
10+
Test as TestWithDesc,
11+
)
812

913

1014
def test_message_enum_descriptors():

betterproto2/tests/grpc/test_stream_stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
from tests.grpc.async_channel import AsyncChannel
7-
from tests.output_betterproto.stream_stream import Message
7+
from tests.outputs.stream_stream.stream_stream import Message
88

99

1010
@pytest.fixture

betterproto2/tests/grpc/thing_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import grpclib
22
import grpclib.server
33

4-
from tests.output_betterproto.service import (
4+
from tests.outputs.service.service import (
55
DoThingRequest,
66
DoThingResponse,
77
GetThingRequest,

betterproto2/tests/inputs/bool/test_bool.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22

33

44
def test_value():
5-
from tests.output_betterproto.bool import Test
5+
from tests.outputs.bool.bool import Test
66

77
message = Test()
88
assert not message.value, "Boolean is False by default"
99

1010

1111
def test_pydantic_no_value():
12-
from tests.output_betterproto_pydantic.bool import Test as TestPyd
12+
from tests.outputs.bool_pydantic.bool import Test as TestPyd
1313

1414
message = TestPyd()
1515
assert not message.value, "Boolean is False by default"
1616

1717

1818
def test_pydantic_value():
19-
from tests.output_betterproto_pydantic.bool import Test as TestPyd
19+
from tests.outputs.bool_pydantic.bool import Test as TestPyd
2020

2121
message = TestPyd(value=False)
2222
assert not message.value
2323

2424

2525
def test_pydantic_bad_value():
26-
from tests.output_betterproto_pydantic.bool import Test as TestPyd
26+
from tests.outputs.bool_pydantic.bool import Test as TestPyd
2727

2828
with pytest.raises(ValueError):
2929
TestPyd(value=123)

betterproto2/tests/inputs/casing/test_casing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import tests.output_betterproto.casing as casing
2-
from tests.output_betterproto.casing import Test
1+
import tests.outputs.casing.casing as casing
2+
from tests.outputs.casing.casing import Test
33

44

55
def test_message_attributes():

0 commit comments

Comments
 (0)