Organize test-cases into folders, extract compatibility test into proper test, support adding test-case specific tests

This commit is contained in:
boukeversteegh
2020-05-22 12:54:01 +02:00
parent 3546f55146
commit b12f1e4e61
53 changed files with 332 additions and 218 deletions

View File

@@ -0,0 +1,3 @@
{
"value": true
}

View File

@@ -0,0 +1,5 @@
syntax = "proto3";
message Test {
bool value = 1;
}

View File

@@ -0,0 +1,8 @@
from betterproto.tests.output_betterproto.bool.bool import Test
from betterproto.tests.util import read_relative
def test_value():
message = Test().from_json(read_relative(__file__, 'bool.json'))
assert message.value

View File

@@ -0,0 +1,3 @@
{
"data": "SGVsbG8sIFdvcmxkIQ=="
}

View File

@@ -0,0 +1,5 @@
syntax = "proto3";
message Test {
bytes data = 1;
}

View File

@@ -0,0 +1,4 @@
{
"camelCase": 1,
"snakeCase": "ONE"
}

View File

@@ -0,0 +1,17 @@
syntax = "proto3";
enum my_enum {
ZERO = 0;
ONE = 1;
TWO = 2;
}
message Test {
int32 camelCase = 1;
my_enum snake_case = 2;
snake_case_message snake_case_message = 3;
}
message snake_case_message {
}

View File

@@ -0,0 +1,3 @@
{
"count": -123.45
}

View File

@@ -0,0 +1,3 @@
{
"count": 123.45
}

View File

@@ -0,0 +1,5 @@
syntax = "proto3";
message Test {
double count = 1;
}

View File

@@ -0,0 +1,3 @@
{
"greeting": "HEY"
}

View File

@@ -0,0 +1,14 @@
syntax = "proto3";
// Enum for the different greeting types
enum Greeting {
HI = 0;
HEY = 1;
// Formal greeting
HELLO = 2;
}
message Test {
// Greeting enum example
Greeting greeting = 1;
}

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1,5 @@
{
"maybe": false,
"ts": "1972-01-01T10:00:20.021Z",
"duration": "1.200s"
}

View File

@@ -0,0 +1,12 @@
syntax = "proto3";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";
message Test {
google.protobuf.BoolValue maybe = 1;
google.protobuf.Timestamp ts = 2;
google.protobuf.Duration duration = 3;
google.protobuf.Int32Value important = 4;
}

View File

@@ -0,0 +1,18 @@
syntax = "proto3";
import "google/protobuf/wrappers.proto";
service Test {
rpc GetInt32 (Input) returns (google.protobuf.Int32Value);
rpc GetAnotherInt32 (Input) returns (google.protobuf.Int32Value);
rpc GetInt64 (Input) returns (google.protobuf.Int64Value);
rpc GetOutput (Input) returns (Output);
}
message Input {
}
message Output {
google.protobuf.Int64Value int64 = 1;
}

View File

@@ -0,0 +1,18 @@
from typing import Optional
import pytest
from betterproto.tests.output_betterproto.googletypes_response.googletypes_response import TestStub
class TestStubChild(TestStub):
async def _unary_unary(self, route, request, response_type, **kwargs):
self.response_type = response_type
@pytest.mark.asyncio
async def test():
pytest.skip('todo')
stub = TestStubChild(None)
await stub.get_int64()
assert stub.response_type != Optional[int]

View File

@@ -0,0 +1,3 @@
{
"count": -150
}

View File

@@ -0,0 +1,3 @@
{
"count": 150
}

View File

@@ -0,0 +1,7 @@
syntax = "proto3";
// Some documentation about the Test message.
message Test {
// Some documentation about the count.
int32 count = 1;
}

View File

@@ -0,0 +1,5 @@
{
"for": 1,
"with": 2,
"as": 3
}

View File

@@ -0,0 +1,7 @@
syntax = "proto3";
message Test {
int32 for = 1;
int32 with = 2;
int32 as = 3;
}

View File

@@ -0,0 +1,7 @@
{
"counts": {
"item1": 1,
"item2": 2,
"item3": 3
}
}

View File

@@ -0,0 +1,5 @@
syntax = "proto3";
message Test {
map<string, int32> counts = 1;
}

View File

@@ -0,0 +1,10 @@
{
"items": {
"foo": {
"count": 1
},
"bar": {
"count": 2
}
}
}

View File

@@ -0,0 +1,9 @@
syntax = "proto3";
message Test {
map<string, Nested> items = 1;
}
message Nested {
int32 count = 1;
}

View File

@@ -0,0 +1,6 @@
{
"nested": {
"count": 150
},
"sibling": {}
}

View File

@@ -0,0 +1,18 @@
syntax = "proto3";
// A test message with a nested message inside of it.
message Test {
// This is the nested type.
message Nested {
// Stores a simple counter.
int32 count = 1;
}
Nested nested = 1;
Sibling sibling = 2;
Sibling sibling2 = 3;
}
message Sibling {
int32 foo = 1;
}

View File

@@ -0,0 +1,11 @@
{
"root": {
"name": "double-nested",
"parent": {
"child": [{"foo": "hello"}],
"enumChild": ["A"],
"rootParentChild": [{"a": "hello"}],
"bar": true
}
}
}

View File

@@ -0,0 +1,26 @@
syntax = "proto3";
message Test {
message Root {
message Parent {
message RootParentChild {
string a = 1;
}
enum EnumChild{
A = 0;
B = 1;
}
message Child {
string foo = 1;
}
reserved 1;
repeated Child child = 2;
repeated EnumChild enumChild=3;
repeated RootParentChild rootParentChild=4;
bool bar = 5;
}
string name = 1;
Parent parent = 2;
}
Root root = 1;
}

View File

@@ -0,0 +1,3 @@
{
"name": "foo"
}

View File

@@ -0,0 +1,3 @@
{
"count": 1
}

View File

@@ -0,0 +1,8 @@
syntax = "proto3";
message Test {
oneof foo {
int32 count = 1;
string name = 2;
}
}

View File

@@ -0,0 +1,5 @@
{
"greeting": {
"greeting": "hello"
}
}

View File

@@ -0,0 +1,9 @@
syntax = "proto3";
package ref;
import "repeatedmessage.proto";
message Test {
repeatedmessage.Sub greeting = 1;
}

View File

@@ -0,0 +1,11 @@
syntax = "proto3";
package repeatedmessage;
message Test {
repeated Sub greetings = 1;
}
message Sub {
string greeting = 1;
}

View File

@@ -0,0 +1,3 @@
{
"names": ["one", "two", "three"]
}

View File

@@ -0,0 +1,5 @@
syntax = "proto3";
message Test {
repeated string names = 1;
}

View File

@@ -0,0 +1,10 @@
{
"greetings": [
{
"greeting": "hello"
},
{
"greeting": "hi"
}
]
}

View File

@@ -0,0 +1,11 @@
syntax = "proto3";
package repeatedmessage;
message Test {
repeated Sub greetings = 1;
}
message Sub {
string greeting = 1;
}

View File

@@ -0,0 +1,5 @@
{
"counts": [1, 2, -1, -2],
"signed": ["1", "2", "-1", "-2"],
"fixed": [1.0, 2.7, 3.4]
}

View File

@@ -0,0 +1,7 @@
syntax = "proto3";
message Test {
repeated int32 counts = 1;
repeated sint64 signed = 2;
repeated double fixed = 3;
}

View File

@@ -0,0 +1,15 @@
syntax = "proto3";
package service;
message DoThingRequest {
int32 iterations = 1;
}
message DoThingResponse {
int32 successfulIterations = 1;
}
service ExampleService {
rpc DoThing (DoThingRequest) returns (DoThingResponse);
}

View File

@@ -0,0 +1,4 @@
{
"signed_32": -150,
"signed_64": "-150"
}

View File

@@ -0,0 +1,4 @@
{
"signed_32": 150,
"signed_64": "150"
}

View File

@@ -0,0 +1,6 @@
syntax = "proto3";
message Test {
sint32 signed_32 = 1;
sint64 signed_64 = 2;
}