test input: use explicit package declaration (#345)
This commit is contained in:
parent
74205e3319
commit
bd69862a02
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@ -13,6 +13,7 @@ jobs:
|
||||
name: ${{ matrix.os }} / ${{ matrix.python-version }}
|
||||
runs-on: ${{ matrix.os }}-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [Ubuntu, MacOS, Windows]
|
||||
python-version: ['3.6.7', '3.7', '3.8', '3.9', '3.10']
|
||||
@ -56,9 +57,7 @@ jobs:
|
||||
|
||||
- name: Install dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
poetry run python -m pip install pip -U
|
||||
poetry install
|
||||
run: poetry install
|
||||
|
||||
- name: Generate code from proto files
|
||||
shell: bash
|
||||
|
@ -1,3 +1,6 @@
|
||||
import copy
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@ -10,3 +13,10 @@ def pytest_addoption(parser):
|
||||
@pytest.fixture(scope="session")
|
||||
def repeat(request):
|
||||
return request.config.getoption("repeat")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def reset_sys_path():
|
||||
original = copy.deepcopy(sys.path)
|
||||
yield
|
||||
sys.path = original
|
||||
|
@ -78,7 +78,7 @@ async def generate_test_case_output(
|
||||
"""
|
||||
|
||||
test_case_output_path_reference = output_path_reference.joinpath(test_case_name)
|
||||
test_case_output_path_betterproto = output_path_betterproto.joinpath(test_case_name)
|
||||
test_case_output_path_betterproto = output_path_betterproto
|
||||
|
||||
os.makedirs(test_case_output_path_reference, exist_ok=True)
|
||||
os.makedirs(test_case_output_path_betterproto, exist_ok=True)
|
||||
|
@ -7,12 +7,12 @@ import grpclib.server
|
||||
import pytest
|
||||
from betterproto.grpc.util.async_channel import AsyncChannel
|
||||
from grpclib.testing import ChannelFor
|
||||
from tests.output_betterproto.service.service import (
|
||||
from tests.output_betterproto.service import (
|
||||
DoThingRequest,
|
||||
DoThingResponse,
|
||||
GetThingRequest,
|
||||
)
|
||||
from tests.output_betterproto.service.service import TestStub as ThingServiceClient
|
||||
from tests.output_betterproto.service import TestStub as ThingServiceClient
|
||||
|
||||
from .thing_service import ThingService
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
from tests.output_betterproto.service.service import (
|
||||
from tests.output_betterproto.service import (
|
||||
DoThingResponse,
|
||||
DoThingRequest,
|
||||
GetThingRequest,
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package bool;
|
||||
|
||||
message Test {
|
||||
bool value = 1;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package bytes;
|
||||
|
||||
message Test {
|
||||
bytes data = 1;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package casing;
|
||||
|
||||
enum my_enum {
|
||||
ZERO = 0;
|
||||
ONE = 1;
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package casing_message_field_uppercase;
|
||||
|
||||
message Test {
|
||||
int32 UPPERCASE = 1;
|
||||
int32 UPPERCASE_V2 = 2;
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package deprecated;
|
||||
|
||||
// Some documentation about the Test message.
|
||||
message Test {
|
||||
// Some documentation about the value.
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package deprecated_field;
|
||||
|
||||
// Some documentation about the Test message.
|
||||
message Test {
|
||||
// Some documentation about the value.
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package double;
|
||||
|
||||
message Test {
|
||||
double count = 1;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package empty_repeated;
|
||||
|
||||
message MessageA {
|
||||
repeated float values = 1;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package enum;
|
||||
|
||||
// Tests that enums are correctly serialized and that it correctly handles skipped and out-of-order enum values
|
||||
message Test {
|
||||
Choice choice = 1;
|
||||
|
@ -39,6 +39,8 @@
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package example;
|
||||
|
||||
// package google.protobuf;
|
||||
|
||||
option go_package = "google.golang.org/protobuf/types/descriptorpb";
|
||||
|
@ -2,7 +2,7 @@ from typing import AsyncIterable, AsyncIterator
|
||||
|
||||
import pytest
|
||||
from grpclib.testing import ChannelFor
|
||||
from tests.output_betterproto.example_service.example_service import (
|
||||
from tests.output_betterproto.example_service import (
|
||||
ExampleRequest,
|
||||
ExampleResponse,
|
||||
TestBase,
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package field_name_identical_to_type;
|
||||
|
||||
// Tests that messages may contain fields with names that are identical to their python types (PR #294)
|
||||
|
||||
message Test {
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package fixed;
|
||||
|
||||
message Test {
|
||||
fixed32 foo = 1;
|
||||
sfixed32 bar = 2;
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package float;
|
||||
|
||||
// Some documentation about the Test message.
|
||||
message Test {
|
||||
double positive = 1;
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package google_impl_behavior_equivalence;
|
||||
|
||||
message Foo{
|
||||
int64 bar = 1;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package googletypes;
|
||||
|
||||
import "google/protobuf/duration.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "google/protobuf/wrappers.proto";
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package googletypes_response;
|
||||
|
||||
import "google/protobuf/wrappers.proto";
|
||||
|
||||
// Tests that wrapped values can be used directly as return values
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package googletypes_response_embedded;
|
||||
|
||||
import "google/protobuf/wrappers.proto";
|
||||
|
||||
// Tests that wrapped values are supported as part of output message
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package googletypes_service_returns_empty;
|
||||
|
||||
import "google/protobuf/empty.proto";
|
||||
|
||||
service Test {
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package googletypes_service_returns_googletype;
|
||||
|
||||
import "google/protobuf/empty.proto";
|
||||
import "google/protobuf/struct.proto";
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package googletypes_struct;
|
||||
|
||||
import "google/protobuf/struct.proto";
|
||||
|
||||
message Test {
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package googletypes_value;
|
||||
|
||||
import "google/protobuf/struct.proto";
|
||||
|
||||
// Tests that fields of type google.protobuf.Value can contain arbitrary JSON-values.
|
||||
|
@ -1,7 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
|
||||
package Capitalized;
|
||||
package import_capitalized_package.Capitalized;
|
||||
|
||||
message Message {
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package import_capitalized_package;
|
||||
|
||||
import "capitalized.proto";
|
||||
|
||||
// Tests that we can import from a package with a capital name, that looks like a nested type, but isn't.
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package package.childpackage;
|
||||
package import_child_package_from_package.package.childpackage;
|
||||
|
||||
message ChildMessage {
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package import_child_package_from_package;
|
||||
|
||||
import "package_message.proto";
|
||||
|
||||
// Tests generated imports when a message in a package refers to a message in a nested child package.
|
||||
|
@ -2,7 +2,7 @@ syntax = "proto3";
|
||||
|
||||
import "child.proto";
|
||||
|
||||
package package;
|
||||
package import_child_package_from_package.package;
|
||||
|
||||
message PackageMessage {
|
||||
package.childpackage.ChildMessage c = 1;
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package childpackage;
|
||||
package import_child_package_from_root.childpackage;
|
||||
|
||||
message Message {
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package import_child_package_from_root;
|
||||
|
||||
import "child.proto";
|
||||
|
||||
// Tests generated imports when a message in root refers to a message in a child package.
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package import_circular_dependency;
|
||||
|
||||
import "root.proto";
|
||||
import "other.proto";
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "root.proto";
|
||||
package other;
|
||||
package import_circular_dependency.other;
|
||||
|
||||
message OtherPackageMessage {
|
||||
RootPackageMessage rootPackageMessage = 1;
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package import_circular_dependency;
|
||||
|
||||
message RootPackageMessage {
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package cousin.cousin_subpackage;
|
||||
package import_cousin_package.cousin.cousin_subpackage;
|
||||
|
||||
message CousinMessage {
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package test.subpackage;
|
||||
package import_cousin_package.test.subpackage;
|
||||
|
||||
import "cousin.proto";
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package cousin.subpackage;
|
||||
package import_cousin_package_same_name.cousin.subpackage;
|
||||
|
||||
message CousinMessage {
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package test.subpackage;
|
||||
package import_cousin_package_same_name.test.subpackage;
|
||||
|
||||
import "cousin.proto";
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package import_packages_same_name;
|
||||
|
||||
import "users_v1.proto";
|
||||
import "posts_v1.proto";
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package posts.v1;
|
||||
package import_packages_same_name.posts.v1;
|
||||
|
||||
message Post {
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package users.v1;
|
||||
package import_packages_same_name.users.v1;
|
||||
|
||||
message User {
|
||||
|
||||
|
@ -2,7 +2,7 @@ syntax = "proto3";
|
||||
|
||||
import "parent_package_message.proto";
|
||||
|
||||
package parent.child;
|
||||
package import_parent_package_from_child.parent.child;
|
||||
|
||||
// Tests generated imports when a message refers to a message defined in its parent package
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package parent;
|
||||
package import_parent_package_from_child.parent;
|
||||
|
||||
message ParentPackageMessage {
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package child;
|
||||
package import_root_package_from_child.child;
|
||||
|
||||
import "root.proto";
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package import_root_package_from_child;
|
||||
|
||||
|
||||
message RootMessage {
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package import_root_sibling;
|
||||
|
||||
import "sibling.proto";
|
||||
|
||||
// Tests generated imports when a message in the root package refers to another message in the root package
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package import_root_sibling;
|
||||
|
||||
message SiblingMessage {
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package child;
|
||||
package import_service_input_message.child;
|
||||
|
||||
message ChildRequestMessage {
|
||||
int32 child_argument = 1;
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package import_service_input_message;
|
||||
|
||||
import "request_message.proto";
|
||||
import "child_package_request_message.proto";
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package import_service_input_message;
|
||||
|
||||
message RequestMessage {
|
||||
int32 argument = 1;
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package int32;
|
||||
|
||||
// Some documentation about the Test message.
|
||||
message Test {
|
||||
// Some documentation about the count.
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package map;
|
||||
|
||||
message Test {
|
||||
map<string, int32> counts = 1;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package mapmessage;
|
||||
|
||||
message Test {
|
||||
map<string, Nested> items = 1;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package namespace_builtin_types;
|
||||
|
||||
// Tests that messages may contain fields with names that are python types
|
||||
|
||||
message Test {
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package namespace_keywords;
|
||||
|
||||
// Tests that messages may contain fields that are Python keywords
|
||||
//
|
||||
// Generated with Python 3.7.6
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package nested;
|
||||
|
||||
// A test message with a nested message inside of it.
|
||||
message Test {
|
||||
// This is the nested type.
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package nested2;
|
||||
|
||||
import "package.proto";
|
||||
|
||||
message Game {
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package equipment;
|
||||
package nested2.equipment;
|
||||
|
||||
message Weapon {
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package nestedtwice;
|
||||
|
||||
message Test {
|
||||
message Top {
|
||||
message Middle {
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package oneof;
|
||||
|
||||
message Test {
|
||||
oneof foo {
|
||||
int32 pitied = 1;
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package oneof_default_value_serialization;
|
||||
|
||||
import "google/protobuf/duration.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "google/protobuf/wrappers.proto";
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package oneof_empty;
|
||||
|
||||
message Nothing {}
|
||||
|
||||
message MaybeNothing {
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package oneof_enum;
|
||||
|
||||
message Test {
|
||||
oneof action {
|
||||
Signal signal = 1;
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package proto3_field_presence;
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
message InnerTest {
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package proto3_field_presence_oneof;
|
||||
|
||||
message Test {
|
||||
oneof kind {
|
||||
Nested nested = 1;
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package recursivemessage;
|
||||
|
||||
message Test {
|
||||
string name = 1;
|
||||
Test child = 2;
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ref;
|
||||
|
||||
import "repeatedmessage.proto";
|
||||
|
||||
message Test {
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package repeated;
|
||||
|
||||
message Test {
|
||||
repeated string names = 1;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package repeated_duration_timestamp;
|
||||
|
||||
import "google/protobuf/duration.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package repeatedpacked;
|
||||
|
||||
message Test {
|
||||
repeated int32 counts = 1;
|
||||
repeated sint64 signed = 2;
|
||||
|
@ -3,7 +3,7 @@ syntax = "proto3";
|
||||
import "google/protobuf/duration.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
package things.messages;
|
||||
package service_separate_packages.things.messages;
|
||||
|
||||
message DoThingRequest {
|
||||
string name = 1;
|
||||
|
@ -2,7 +2,7 @@ syntax = "proto3";
|
||||
|
||||
import "messages.proto";
|
||||
|
||||
package things.service;
|
||||
package service_separate_packages.things.service;
|
||||
|
||||
service Test {
|
||||
rpc DoThing (things.messages.DoThingRequest) returns (things.messages.DoThingResponse);
|
||||
|
@ -1,5 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package signed;
|
||||
|
||||
message Test {
|
||||
// todo: rename fields after fixing bug where 'signed_32_positive' will map to 'signed_32Positive' as output json
|
||||
sint32 signed32 = 1; // signed_32_positive
|
||||
|
@ -480,7 +480,7 @@ def test_iso_datetime_list():
|
||||
|
||||
|
||||
def test_service_argument__expected_parameter():
|
||||
from tests.output_betterproto.service.service import TestStub
|
||||
from tests.output_betterproto.service import TestStub
|
||||
|
||||
sig = signature(TestStub.do_thing)
|
||||
do_thing_request_parameter = sig.parameters["do_thing_request"]
|
||||
|
@ -23,8 +23,6 @@ from tests.util import (
|
||||
# break things because we can't properly reset the symbol database.
|
||||
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
|
||||
|
||||
from google.protobuf import symbol_database
|
||||
from google.protobuf.descriptor_pool import DescriptorPool
|
||||
from google.protobuf.json_format import Parse
|
||||
|
||||
|
||||
@ -125,14 +123,9 @@ def dict_replace_nans(input_dict: Dict[Any, Any]) -> Dict[Any, Any]:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_data(request):
|
||||
def test_data(request, reset_sys_path):
|
||||
test_case_name = request.param
|
||||
|
||||
# Reset the internal symbol database so we can import the `Test` message
|
||||
# multiple times. Ugh.
|
||||
sym = symbol_database.Default()
|
||||
sym.pool = DescriptorPool()
|
||||
|
||||
reference_module_root = os.path.join(
|
||||
*reference_output_package.split("."), test_case_name
|
||||
)
|
||||
@ -158,8 +151,6 @@ def test_data(request):
|
||||
)
|
||||
)
|
||||
|
||||
sys.path.remove(reference_module_root)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_data", test_cases.messages, indirect=True)
|
||||
def test_message_can_instantiated(test_data: TestData) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user