Skip to content

Commit

Permalink
Merge pull request #197 from WinterFramework/fix-coverage
Browse files Browse the repository at this point in the history
Fix coverage
  • Loading branch information
pristupa authored Apr 6, 2021
2 parents 5842665 + bf5c291 commit 2bc9dfe
Show file tree
Hide file tree
Showing 42 changed files with 138 additions and 153 deletions.
6 changes: 5 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ codecov:
coverage:
precision: 2
round: down
range: 80...100
range: 99...100

status:
project:
Expand All @@ -28,3 +28,7 @@ coverage:
enabled: no

comment: false

ignore:
- "setup.py"
- "samples/*.py"
4 changes: 2 additions & 2 deletions tests/controllers/controller_with_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def handle(self, exception: CustomException) -> int:

class WithUnknownArgumentExceptionHandler(winter.web.ExceptionHandler):
@winter.response_status(400)
def handle(self, exception: CustomException, unknown_argument: int) -> str:
return 'Bad Request'
def handle(self, exception: CustomException, unknown_argument: int) -> str: # pragma: no cover
pass


winter.web.exception_handlers_registry.add_handler(CustomException, CustomExceptionHandler)
Expand Down
1 change: 0 additions & 1 deletion tests/controllers/controller_with_media_types_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
@winter.controller
@winter.route('controller_with_media_types_routing/')
class ControllerWithMediaTypesRouting:

@winter.route_get('xml/', produces=(MediaType.APPLICATION_XML, ))
def get_xml(self) -> str:
return 'Hello, sir!'
12 changes: 3 additions & 9 deletions tests/controllers/controller_with_path_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ class OneTwoEnumWithInt(enum.Enum):

@classmethod
def _missing_(cls, value): # This is need because of needing of instancing from string
try:
value = int(value)
except ValueError:
super()._missing_(cls, value)
else:
return cls(value)
return cls(int(value))


@winter.controller
@winter.route('controller_with_path_parameters/{param1}/')
class ControllerWithPathParameters:

@winter.route_get('{param2}/{param3}/{param4}/{param5}/{?param6}')
def test(
self,
Expand All @@ -36,5 +30,5 @@ def test(
param4: uuid.UUID,
param5: OneTwoEnumWithInt,
param6: str,
) -> str:
return 'Hello, sir!'
) -> str: # pragma: no cover
pass
4 changes: 2 additions & 2 deletions tests/controllers/controller_with_problem_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class AllFieldConstProblemExistsException(Exception):

class ProblemExistsExceptionHandler(winter.web.ExceptionHandler):
@winter.response_status(HTTPStatus.FORBIDDEN)
def handle(self, exception: ProblemExistsException, **kwargs) -> Dict:
return {'message': str(exception)}
def handle(self, exception: ProblemExistsException, **kwargs) -> Dict: # pragma: no cover
pass


@dataclasses.dataclass
Expand Down
4 changes: 2 additions & 2 deletions tests/controllers/controller_with_response_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ def two_headers(self, header1: ResponseHeader[str], header2: ResponseHeader[str]
return 'OK'

@winter.route_get('header-without-annotation/')
def header_without_annotation(self, header: ResponseHeader[str]) -> str:
return 'OK'
def header_without_annotation(self, header: ResponseHeader[str]) -> str: # pragma: no cover
pass
2 changes: 1 addition & 1 deletion tests/controllers/simple_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ def put(self):
pass

@winter.response_status(HTTPStatus.OK)
def no_route(self):
def no_route(self): # pragma: no cover
pass
20 changes: 4 additions & 16 deletions tests/core/json/test_decoder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dataclasses
import datetime
import decimal
import enum
Expand All @@ -9,7 +10,6 @@
from typing import Set
from typing import Tuple

import dataclasses
import pytest
from dateutil.tz import tzutc

Expand All @@ -20,27 +20,15 @@


class Id(int):

def __eq__(self, other):
if not isinstance(other, __class__):
return False
return super().__eq__(other)
pass


class Uid(uuid.UUID):

def __eq__(self, other):
if not isinstance(other, __class__):
return False
return super().__eq__(other)
pass


class Number(decimal.Decimal):

def __eq__(self, other, **kwargs):
if not isinstance(other, __class__):
return False
return super().__eq__(other, **kwargs)
pass


class Status(enum.Enum):
Expand Down
16 changes: 7 additions & 9 deletions tests/core/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ class SimpleComponent:
@pytest.mark.parametrize('decorator', (simple_annotation, simple_annotation_method))
def test_on_method_by_decorator(decorator):
class SimpleComponent:

@decorator('test')
def method(self):
def method(self): # pragma: no cover
pass

assert SimpleComponent.method.annotations.get(SimpleAnnotation) == [SimpleAnnotation('test')]
Expand Down Expand Up @@ -101,10 +100,9 @@ def test_annotate_with_instance(decorator_factory, error_message_template):
def test_empty_annotation():
@annotate(None)
class Controller:

@annotate(None)
def simple_method(self):
return None
def simple_method(self): # pragma: no cover
pass

component = Component.get_by_cls(Controller)

Expand All @@ -119,8 +117,8 @@ def test_try_twice_annotation_with_single():
with pytest.raises(AlreadyAnnotated) as exception:
@annotate(SimpleAnnotation('test'), single=True)
@annotate(SimpleAnnotation('test'), single=True)
def simple_method():
return None
def simple_method(): # pragma: no cover
pass

assert exception.value.annotation == SimpleAnnotation('test')
assert str(exception.value) == f'Cannot annotate twice: {SimpleAnnotation}'
Expand All @@ -130,8 +128,8 @@ def test_try_twice_annotation_with_unique():
with pytest.raises(AlreadyAnnotated) as exception:
@annotate(SimpleAnnotation('test'), unique=True)
@annotate(SimpleAnnotation('test'), unique=True)
def simple_method():
return None
def simple_method(): # pragma: no cover
pass

assert exception.value.annotation == SimpleAnnotation('test')
assert str(exception.value) == f'Cannot annotate twice: {SimpleAnnotation}'
11 changes: 4 additions & 7 deletions tests/core/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,19 @@ def simple_method(self):

def test_method_state():
class SimpleComponent:

@simple_annotation('/url/')
def simple_method(self):
return 123
def simple_method(self): # pragma: no cover
pass

assert SimpleComponent.simple_method.annotations.get(SimpleAnnotation) == [SimpleAnnotation('/url/')]


def test_method_state_many():

class SimpleComponent:

@simple_annotation('first')
@simple_annotation('second')
def simple_method(self):
return None
def simple_method(self): # pragma: no cover
pass

expected_annotations = [SimpleAnnotation('second'), SimpleAnnotation('first')]
assert SimpleComponent.simple_method.annotations.get(SimpleAnnotation) == expected_annotations
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_component_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def method(self, number: argument_type):


def test_component_method():
def test():
return None
def test(): # pragma: no cover
pass

method = ComponentMethod(test)
assert method is component_method(method)
4 changes: 2 additions & 2 deletions tests/core/test_component_method_argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def test_parameter():
def test(number: int) -> int:
def test(number: int) -> int: # pragma: no cover
return number

method = ComponentMethod(test)
Expand All @@ -17,7 +17,7 @@ def test(number: int) -> int:


def test_default():
def test(number: int) -> int:
def test(number: int) -> int: # pragma: no cover
return number

method = ComponentMethod(test)
Expand Down
3 changes: 1 addition & 2 deletions tests/data/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

def test_crud_repository_generic_parameters():
class MyEntity:
def __init__(self, id_: int):
self.id = id_
pass

class MyRepository(CRUDRepository[MyEntity, int]):
pass
Expand Down
7 changes: 2 additions & 5 deletions tests/entities/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@


class User:

@property
def is_authenticated(self):
return False

@property
def is_anonymous(self):
def is_anonymous(self): # pragma: no cover
return False


class Guest(User):

@property
def is_anonymous(self):
def is_anonymous(self): # pragma: no cover
return True


class AuthorizedUser(User):

def __init__(self, pk=None):
self.pk = pk if pk is not None else uuid.uuid4()

Expand Down
8 changes: 4 additions & 4 deletions tests/pagination/test_page_position_argument_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
def test_page_position_argument_inspector(argument_type, must_return_parameters):
class SimpleController:
@winter.route_get('')
def method(self, arg1: argument_type):
return arg1
def method(self, arg1: argument_type): # pragma: no cover
pass

route = get_route(SimpleController.method)

Expand Down Expand Up @@ -44,8 +44,8 @@ def test_page_position_argument_inspector_with_allowed_order_by_fields(default_s
class SimpleController:
@winter.route_get('')
@winter.web.pagination.order_by(['id'], default_sort=default_sort)
def method(self, arg1: PagePosition):
return arg1
def method(self, arg1: PagePosition): # pragma: no cover
pass

route = get_route(SimpleController.method)

Expand Down
11 changes: 5 additions & 6 deletions tests/pagination/test_page_position_argument_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
),
)
def test_is_supported_in_page_position_argument_resolver(argument_type, expected_is_supported):
def func(arg1: argument_type):
def func(arg1: argument_type): # pragma: no cover
return arg1

method = ComponentMethod(func)
Expand All @@ -35,7 +35,7 @@ def func(arg1: argument_type):

def test_resolve_argument_with_order_by_without_order_by_annotation():
@winter.core.component_method
def method(arg1: PagePosition):
def method(arg1: PagePosition): # pragma: no cover
return arg1

argument = method.get_argument('arg1')
Expand Down Expand Up @@ -65,7 +65,7 @@ def method(arg1: PagePosition):
)
def test_resolve_argument_ok_in_page_position_argument_resolver(query_string, expected_page_position):
@winter.web.pagination.order_by(['name', 'id', 'email', 'x'])
def method(page_position: PagePosition):
def method(page_position: PagePosition): # pragma: no cover
return page_position

argument = method.get_argument('page_position')
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_resolve_argument_ok_in_page_position_argument_resolver_with_default(
expected_page_position,
):
@winter.web.pagination.order_by(['name', 'id', 'email'], default_sort=default_sort)
def method(page_position: PagePosition):
def method(page_position: PagePosition): # pragma: no cover
return page_position

argument = method.get_argument('page_position')
Expand Down Expand Up @@ -124,9 +124,8 @@ def method(page_position: PagePosition):
),
)
def test_resolve_argument_fails_in_page_position_argument_resolver(query_string, exception_type, message):

@winter.web.pagination.order_by(['id'])
def method(arg1: int):
def method(arg1: int): # pragma: no cover
return arg1

argument = method.get_argument('arg1')
Expand Down
Loading

0 comments on commit 2bc9dfe

Please sign in to comment.