Skip to content

Commit

Permalink
Consolidate the two test_negative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunn1313 committed Nov 12, 2022
1 parent 71bcf9e commit e9c69a3
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 224 deletions.
2 changes: 1 addition & 1 deletion run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ for PY_VER in $PY_VER_UNIT_TESTS; do
fi

# run mypy on negative-tests (expected mypy failures)
NEGATIVE_MODULES=( -m test_negative.negative -m test_negative.negative_38 "${MODULES[@]}" )
NEGATIVE_MODULES=( -m test_negative.negative "${MODULES[@]}" )

MYPY_OUTPUT=$(mktemp -d)
call_mypy() {
Expand Down
2 changes: 1 addition & 1 deletion test/test_generated_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def grab_expectations(filename: str, marker: str) -> Generator[Tuple[str, int],

errors_38 = set(grab_errors("test_negative/output.expected.3.8"))

expected_errors_38 = set(grab_expectations("test_negative/negative.py", "E:3.8")) | set(grab_expectations("test_negative/negative_38.py", "E:3.8"))
expected_errors_38 = set(grab_expectations("test_negative/negative.py", "E:3.8"))

assert errors_38 == expected_errors_38

Expand Down
97 changes: 96 additions & 1 deletion test_negative/negative.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"""

from test.test_generated_mypy import Email, UserId
from typing import List
from typing import Generator, Iterator, List

import grpc
from testproto.dot.com.test_pb2 import TestMessage
from testproto.grpc.dummy_pb2 import DummyReply, DummyRequest
from testproto.grpc.dummy_pb2_grpc import DummyServiceServicer, DummyServiceStub
from testproto.test3_pb2 import OuterEnum, OuterMessage3, SimpleProto3
from testproto.test_extensions2_pb2 import SeparateFileExtension
from testproto.test_pb2 import (
Expand Down Expand Up @@ -178,3 +181,95 @@
assert PythonReservedKeywords().valid == PythonReservedKeywords.valid_in_finally
a_string = "hi"
a_string = PythonReservedKeywords().valid # E:3.8

stub0 = DummyServiceStub() # E:3.8
channel = grpc.insecure_channel("127.0.0.1:8080")
stub1 = DummyServiceStub(channel)
request1 = DummyRequest()

response1 = stub1.UnaryUnary(request1)
value = response1.value
value2 = response1.not_exists # E:3.8
for _result1 in stub1.UnaryUnary(request1): # E:3.8
pass

for result2 in stub1.UnaryStream(request1):
value = result2.value
value2 = result2.not_exists # E:3.8
response2 = stub1.UnaryStream(request1)
value = response2.value # E:3.8


def iter_requests() -> Generator[DummyRequest, None, None]:
yield request1


response3 = stub1.StreamUnary(request1) # E:3.8
response4 = stub1.StreamUnary(iter_requests())
for _result3 in stub1.StreamUnary(request1): # E:3.8
pass

for _result4 in stub1.StreamStream(request1): # E:3.8
pass
for result5 in stub1.StreamStream(iter_requests()):
value = result5.value
value2 = result5.not_exists # E:3.8


class GoodServicer(DummyServiceServicer):
def UnaryUnary(
self,
request: DummyRequest,
context: grpc.ServicerContext,
) -> DummyReply:
return DummyReply()

def UnaryStream(
self,
request: DummyRequest,
context: grpc.ServicerContext,
) -> Iterator[DummyReply]:
yield DummyReply()

def StreamUnary(
self,
request: Iterator[DummyRequest],
context: grpc.ServicerContext,
) -> DummyReply:
for _data in request:
pass
return DummyReply()

def StreamStream(
self,
request: Iterator[DummyRequest],
context: grpc.ServicerContext,
) -> Iterator[DummyReply]:
for _data in request:
yield DummyReply()


class BadServicer(DummyServiceServicer):
def UnaryUnary( # E:3.8
self,
request: Iterator[DummyRequest],
context: grpc.ServicerContext,
) -> Iterator[DummyReply]:
for _data in request:
yield DummyReply()

def UnaryStream( # E:3.8
self,
request: Iterator[DummyRequest],
context: grpc.ServicerContext,
) -> DummyReply:
for _data in request:
pass
return DummyReply()

def StreamUnary( # E:3.8
self,
request: DummyRequest,
context: grpc.ServicerContext,
) -> Iterator[DummyReply]:
yield DummyReply()
102 changes: 0 additions & 102 deletions test_negative/negative_38.py

This file was deleted.

Loading

0 comments on commit e9c69a3

Please sign in to comment.