Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some tests fail #859

Open
piegamesde opened this issue Jun 4, 2020 · 1 comment · May be fixed by #926
Open

Some tests fail #859

piegamesde opened this issue Jun 4, 2020 · 1 comment · May be fixed by #926

Comments

@piegamesde
Copy link

Reproduce with nix-shell -p python37Packages.hug or nix-shell -p python38Packages.hug.

============================= test session starts ==============================
platform linux -- Python 3.8.2, pytest-5.3.5, py-1.8.1, pluggy-0.13.1
rootdir: /build/source, inifile: setup.cfg
collected 474 items / 4 deselected / 470 selected                              

tests/test_api.py .........                                              [  1%]
tests/test_async.py .....                                                [  2%]
tests/test_authentication.py .....                                       [  4%]
tests/test_context_factory.py ...F.....F.....F..                         [  7%]
tests/test_coroutines.py .....                                           [  8%]
tests/test_decorators.py ........................s...................... [ 18%]
............................................                             [ 28%]
tests/test_directives.py ..............                                  [ 31%]
tests/test_documentation.py ....                                         [ 32%]
tests/test_exceptions.py .                                               [ 32%]
tests/test_full_request.py .                                             [ 32%]
tests/test_global_context.py .                                           [ 32%]
tests/test_input_format.py .....                                         [ 33%]
tests/test_interface.py ....                                             [ 34%]
tests/test_introspect.py .......                                         [ 36%]
tests/test_main.py .                                                     [ 36%]
tests/test_middleware.py ...                                             [ 37%]
tests/test_output_format.py .................                            [ 40%]
tests/test_redirect.py ......                                            [ 41%]
tests/test_route.py ................                                     [ 45%]
tests/test_routing.py .................................................. [ 55%]
........................................................................ [ 71%]
..................................................................       [ 85%]
tests/test_store.py .                                                    [ 85%]
tests/test_test.py .                                                     [ 85%]
tests/test_this.py .                                                     [ 85%]
tests/test_transform.py ....                                             [ 86%]
tests/test_types.py .............................F.F....F                [ 94%]
tests/test_use.py ......................                                 [ 99%]
tests/test_validate.py ...                                               [100%]

=================================== FAILURES ===================================
____________________ TestContextFactoryLocal.test_transform ____________________

self = <Local object at 0x7fffe5822d40>, args = (), kwargs = {}
context = {'test': 'context', 'test_number': 43}, errors = {}

    def __call__(self, *args, **kwargs):
        context = self.api.context_factory(api=self.api, api_version=self.version, interface=self)
        """Defines how calling the function locally should be handled"""
    
        for _requirement in self.requires:
            lacks_requirement = self.check_requirements(context=context)
            if lacks_requirement:
                self.api.delete_context(context, lacks_requirement=lacks_requirement)
                return self.outputs(lacks_requirement) if self.outputs else lacks_requirement
    
        for index, argument in enumerate(args):
            kwargs[self.parameters[index]] = argument
    
        if not getattr(self, "skip_directives", False):
            for parameter, directive in self.directives.items():
                if parameter in kwargs:
                    continue
                arguments = (self.defaults[parameter],) if parameter in self.defaults else ()
                kwargs[parameter] = directive(
                    *arguments,
                    api=self.api,
                    api_version=self.version,
                    interface=self,
                    context=context
                )
    
        if not getattr(self, "skip_validation", False):
            errors = self.validate(kwargs, context)
            if errors:
                errors = {"errors": errors}
                if getattr(self, "on_invalid", False):
                    errors = self.on_invalid(errors)
                outputs = getattr(self, "invalid_outputs", self.outputs)
                self.api.delete_context(context, errors=errors)
                return outputs(errors) if outputs else errors
    
        self._rewrite_params(kwargs)
        try:
            result = self.interface(**kwargs)
            if self.transform:
                if hasattr(self.transform, "context"):
                    self.transform.context = context
>               result = self.transform(result)

/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/interface.py:436: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <hug.types.MarshmallowReturnSchema object at 0x7fffe57fd280>
value = {'name': 'test'}

    def __call__(self, value):
        # In marshmallow 2 schemas return tuple (`data`, `errors`) upon loading. They might also raise on invalid data
        # if configured so, but will still return a tuple.
        # In marshmallow 3 schemas always raise Validation error on load if input data is invalid and a single
        # value `data` is returned.
        if MARSHMALLOW_MAJOR_VERSION is None or MARSHMALLOW_MAJOR_VERSION == 2:
            value, errors = self.schema.dump(value)
        else:
            errors = {}
            try:
>               value = self.schema.dump(value)

/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/types.py:727: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <UserSchema(many=False)>, obj = {'name': 'test'}

    def dump(self, obj: typing.Any, *, many: bool = None):
        """Serialize an object to native Python data types according to this
        Schema's fields.
    
        :param obj: The object to serialize.
        :param many: Whether to serialize `obj` as a collection. If `None`, the value
            for `self.many` is used.
        :return: A dict of serialized data
        :rtype: dict
    
        .. versionadded:: 1.0.0
        .. versionchanged:: 3.0.0b7
            This method returns the serialized data rather than a ``(data, errors)`` duple.
            A :exc:`ValidationError <marshmallow.exceptions.ValidationError>` is raised
            if ``obj`` is invalid.
        .. versionchanged:: 3.0.0rc9
            Validation no longer occurs upon serialization.
        """
        many = self.many if many is None else bool(many)
        if many and is_iterable_but_not_string(obj):
            obj = list(obj)
    
        if self._has_processors(PRE_DUMP):
            processed_obj = self._invoke_dump_processors(
                PRE_DUMP, obj, many=many, original_data=obj
            )
        else:
            processed_obj = obj
    
        result = self._serialize(processed_obj, many=many)
    
        if self._has_processors(POST_DUMP):
>           result = self._invoke_dump_processors(
                POST_DUMP, result, many=many, original_data=obj
            )

/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/schema.py:556: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <UserSchema(many=False)>, tag = 'post_dump', data = {'name': 'test'}

    def _invoke_dump_processors(
        self, tag: str, data, *, many: bool, original_data=None
    ):
        # The pass_many post-dump processors may do things like add an envelope, so
        # invoke those after invoking the non-pass_many processors which will expect
        # to get a list of items.
>       data = self._invoke_processors(
            tag, pass_many=False, data=data, many=many, original_data=original_data
        )

/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/schema.py:1053: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <UserSchema(many=False)>, tag = 'post_dump', pass_many = False
data = {'name': 'test'}, many = False, original_data = {'name': 'test'}
kwargs = {}, key = ('post_dump', False), attr_name = 'check_context'
processor_kwargs = {'pass_original': False}

    def _invoke_processors(
        self,
        tag: str,
        *,
        pass_many: bool,
        data,
        many: bool,
        original_data=None,
        **kwargs
    ):
        key = (tag, pass_many)
        for attr_name in self._hooks[key]:
            # This will be a bound method.
            processor = getattr(self, attr_name)
    
            processor_kwargs = processor.__marshmallow_hook__[key]
            pass_original = processor_kwargs.get("pass_original", False)
    
            if many and not pass_many:
                if pass_original:
                    data = [
                        processor(item, original, many=many, **kwargs)
                        for item, original in zip(data, original_data)
                    ]
                else:
                    data = [processor(item, many=many, **kwargs) for item in data]
            else:
                if pass_original:
                    data = processor(data, original_data, many=many, **kwargs)
                else:
>                   data = processor(data, many=many, **kwargs)
E                   TypeError: check_context() got an unexpected keyword argument 'many'

/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/schema.py:1212: TypeError

During handling of the above exception, another exception occurred:

self = <tests.test_context_factory.TestContextFactoryLocal object at 0x7fffe5e725b0>

    def test_transform(self):
        custom_context = dict(test="context", test_number=43)
    
        @hug.context_factory()
        def return_context(**kwargs):
            return custom_context
    
        @hug.delete_context()
        def delete_context(context, exception=None, errors=None, lacks_requirement=None):
            assert context == custom_context
            assert not exception
            assert not errors
            assert not lacks_requirement
            custom_context["launched_delete_context"] = True
    
        class UserSchema(Schema):
            name = fields.Str()
    
            @post_dump()
            def check_context(self, data):
                assert self.context["test"] == "context"
                self.context["test_number"] += 1
    
        @hug.local()
        def validation_local_function() -> UserSchema():
            return {"name": "test"}
    
>       validation_local_function()

tests/test_context_factory.py:139: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/interface.py:439: in __call__
    self.api.delete_context(context, exception=exception)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

context = {'test': 'context', 'test_number': 43}
exception = TypeError("check_context() got an unexpected keyword argument 'many'")
errors = None, lacks_requirement = None

    @hug.delete_context()
    def delete_context(context, exception=None, errors=None, lacks_requirement=None):
        assert context == custom_context
>       assert not exception
E       assert not TypeError("check_context() got an unexpected keyword argument 'many'")

tests/test_context_factory.py:122: AssertionError
_____________________ TestContextFactoryCLI.test_transform _____________________

self = <tests.test_context_factory.TestContextFactoryCLI object at 0x7fffe5f6a4c0>

    def test_transform(self):
        custom_context = dict(test="context", test_number=43)
    
        @hug.context_factory()
        def return_context(**kwargs):
            return custom_context
    
        @hug.delete_context()
        def delete_context(context, exception=None, errors=None, lacks_requirement=None):
            assert not exception
            assert context == custom_context
            assert not errors
            assert not lacks_requirement
            custom_context["launched_delete_context"] = True
    
        class UserSchema(Schema):
            name = fields.Str()
    
            @post_dump()
            def check_context(self, data):
                assert self.context["test"] == "context"
                self.context["test_number"] += 1
    
        @hug.cli()
        def transform_cli_function() -> UserSchema():
            custom_context["launched_cli_function"] = True
            return {"name": "test"}
    
        hug.test.cli(transform_cli_function)
        assert "launched_cli_function" in custom_context
>       assert "launched_delete_context" in custom_context
E       AssertionError: assert 'launched_delete_context' in {'launched_cli_function': True, 'test': 'context', 'test_number': 43}

tests/test_context_factory.py:318: AssertionError
____________________ TestContextFactoryHTTP.test_transform _____________________

self = <hug.interface.HTTP object at 0x7fffe5fae890>
request = <Request: GET 'http://falconframework.org/validation_function'>
response = <Response: 200 OK>, api_version = None, kwargs = {}
context = {'launched_local_function': True, 'test': 'context', 'test_number': 43}
exception_types = (), input_parameters = {}, lacks_requirement = None
errors = {}

    def __call__(self, request, response, api_version=None, **kwargs):
        context = self.api.context_factory(
            response=response,
            request=request,
            api=self.api,
            api_version=api_version,
            interface=self,
        )
        """Call the wrapped function over HTTP pulling information as needed"""
        if isinstance(api_version, str) and api_version.isdigit():
            api_version = int(api_version)
        else:
            api_version = None
        if not self.catch_exceptions:
            exception_types = ()
        else:
            exception_types = self.api.http.exception_handlers(api_version)
            exception_types = tuple(exception_types.keys()) if exception_types else ()
        input_parameters = {}
        try:
            self.set_response_defaults(response, request)
            lacks_requirement = self.check_requirements(request, response, context)
            if lacks_requirement:
                response.data = self.outputs(
                    lacks_requirement,
                    **self._arguments(self._params_for_outputs, request, response)
                )
                self.api.delete_context(context, lacks_requirement=lacks_requirement)
                return
    
            input_parameters = self.gather_parameters(
                request, response, context, api_version, **kwargs
            )
            errors = self.validate(input_parameters, context)
            if errors:
                self.api.delete_context(context, errors=errors)
                return self.render_errors(errors, request, response)
    
>           self.render_content(
                self.call_function(input_parameters), context, request, response, **kwargs
            )

/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/interface.py:916: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <hug.interface.HTTP object at 0x7fffe5fae890>, content = None
context = {'launched_local_function': True, 'test': 'context', 'test_number': 43}
request = <Request: GET 'http://falconframework.org/validation_function'>
response = <Response: 200 OK>, kwargs = {}

    def render_content(self, content, context, request, response, **kwargs):
        if hasattr(content, "interface") and (
            content.interface is True or hasattr(content.interface, "http")
        ):
            if content.interface is True:
                content(request, response, api_version=None, **kwargs)
            else:
                content.interface.http(request, response, api_version=None, **kwargs)
            return
    
>       content = self.transform_data(content, request, response, context)

/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/interface.py:851: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <hug.interface.HTTP object at 0x7fffe5fae890>, data = None
request = <Request: GET 'http://falconframework.org/validation_function'>
response = <Response: 200 OK>
context = {'launched_local_function': True, 'test': 'context', 'test_number': 43}

    def transform_data(self, data, request=None, response=None, context=None):
        transform = self.transform
        if hasattr(transform, "context"):
            self.transform.context = context
        """Runs the transforms specified on this endpoint with the provided data, returning the data modified"""
        if transform and not (isinstance(transform, type) and isinstance(data, transform)):
            if self._params_for_transform:
                return transform(
                    data, **self._arguments(self._params_for_transform, request, response)
                )
            else:
>               return transform(data)

/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/interface.py:778: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <hug.types.MarshmallowReturnSchema object at 0x7fffe5db2a80>
value = None

    def __call__(self, value):
        # In marshmallow 2 schemas return tuple (`data`, `errors`) upon loading. They might also raise on invalid data
        # if configured so, but will still return a tuple.
        # In marshmallow 3 schemas always raise Validation error on load if input data is invalid and a single
        # value `data` is returned.
        if MARSHMALLOW_MAJOR_VERSION is None or MARSHMALLOW_MAJOR_VERSION == 2:
            value, errors = self.schema.dump(value)
        else:
            errors = {}
            try:
>               value = self.schema.dump(value)

/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/types.py:727: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <UserSchema(many=False)>, obj = None

    def dump(self, obj: typing.Any, *, many: bool = None):
        """Serialize an object to native Python data types according to this
        Schema's fields.
    
        :param obj: The object to serialize.
        :param many: Whether to serialize `obj` as a collection. If `None`, the value
            for `self.many` is used.
        :return: A dict of serialized data
        :rtype: dict
    
        .. versionadded:: 1.0.0
        .. versionchanged:: 3.0.0b7
            This method returns the serialized data rather than a ``(data, errors)`` duple.
            A :exc:`ValidationError <marshmallow.exceptions.ValidationError>` is raised
            if ``obj`` is invalid.
        .. versionchanged:: 3.0.0rc9
            Validation no longer occurs upon serialization.
        """
        many = self.many if many is None else bool(many)
        if many and is_iterable_but_not_string(obj):
            obj = list(obj)
    
        if self._has_processors(PRE_DUMP):
            processed_obj = self._invoke_dump_processors(
                PRE_DUMP, obj, many=many, original_data=obj
            )
        else:
            processed_obj = obj
    
        result = self._serialize(processed_obj, many=many)
    
        if self._has_processors(POST_DUMP):
>           result = self._invoke_dump_processors(
                POST_DUMP, result, many=many, original_data=obj
            )

/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/schema.py:556: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <UserSchema(many=False)>, tag = 'post_dump', data = {}

    def _invoke_dump_processors(
        self, tag: str, data, *, many: bool, original_data=None
    ):
        # The pass_many post-dump processors may do things like add an envelope, so
        # invoke those after invoking the non-pass_many processors which will expect
        # to get a list of items.
>       data = self._invoke_processors(
            tag, pass_many=False, data=data, many=many, original_data=original_data
        )

/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/schema.py:1053: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <UserSchema(many=False)>, tag = 'post_dump', pass_many = False, data = {}
many = False, original_data = None, kwargs = {}, key = ('post_dump', False)
attr_name = 'check_context', processor_kwargs = {'pass_original': False}

    def _invoke_processors(
        self,
        tag: str,
        *,
        pass_many: bool,
        data,
        many: bool,
        original_data=None,
        **kwargs
    ):
        key = (tag, pass_many)
        for attr_name in self._hooks[key]:
            # This will be a bound method.
            processor = getattr(self, attr_name)
    
            processor_kwargs = processor.__marshmallow_hook__[key]
            pass_original = processor_kwargs.get("pass_original", False)
    
            if many and not pass_many:
                if pass_original:
                    data = [
                        processor(item, original, many=many, **kwargs)
                        for item, original in zip(data, original_data)
                    ]
                else:
                    data = [processor(item, many=many, **kwargs) for item in data]
            else:
                if pass_original:
                    data = processor(data, original_data, many=many, **kwargs)
                else:
>                   data = processor(data, many=many, **kwargs)
E                   TypeError: check_context() got an unexpected keyword argument 'many'

/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/schema.py:1212: TypeError

During handling of the above exception, another exception occurred:

self = <tests.test_context_factory.TestContextFactoryHTTP object at 0x7fffe5e546d0>

    def test_transform(self):
        custom_context = dict(test="context", test_number=43)
    
        @hug.context_factory()
        def return_context(**kwargs):
            return custom_context
    
        @hug.delete_context()
        def delete_context(context, exception=None, errors=None, lacks_requirement=None):
            assert context == custom_context
            assert not exception
            assert not errors
            assert not lacks_requirement
            custom_context["launched_delete_context"] = True
    
        class UserSchema(Schema):
            name = fields.Str()
    
            @post_dump()
            def check_context(self, data):
                assert self.context["test"] == "context"
                self.context["test_number"] += 1
    
        @hug.get("/validation_function")
        def validation_http_function() -> UserSchema():
            custom_context["launched_local_function"] = True
    
>       hug.test.get(module, "/validation_function", 43)

tests/test_context_factory.py:490: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/test.py:81: in call
    result = api(
/nix/store/j7k4y6z6xrdlfl5nk6n05sb0ypjb1lql-python3.8-falcon-2.0.0/lib/python3.8/site-packages/falcon/api.py:269: in __call__
    responder(req, resp, **params)
/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/interface.py:945: in __call__
    self.api.delete_context(context, exception=exception)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

context = {'launched_local_function': True, 'test': 'context', 'test_number': 43}
exception = TypeError("check_context() got an unexpected keyword argument 'many'")
errors = None, lacks_requirement = None

    @hug.delete_context()
    def delete_context(context, exception=None, errors=None, lacks_requirement=None):
        assert context == custom_context
>       assert not exception
E       assert not TypeError("check_context() got an unexpected keyword argument 'many'")

tests/test_context_factory.py:473: AssertionError
___________________________ test_marshmallow_schema ____________________________

    def test_marshmallow_schema():
        """Test hug's marshmallow schema support"""
    
        class UserSchema(Schema):
            name = fields.Int()
    
        schema_type = hug.types.MarshmallowInputSchema(UserSchema())
        assert schema_type({"name": 23}, {}) == {"name": 23}
        assert schema_type("""{"name": 23}""", {}) == {"name": 23}
        assert schema_type.__doc__ == "UserSchema"
        with pytest.raises(InvalidTypeData):
            schema_type({"name": "test"}, {})
    
        schema_type = hug.types.MarshmallowReturnSchema(UserSchema())
        assert schema_type({"name": 23}) == {"name": 23}
        assert schema_type.__doc__ == "UserSchema"
        with pytest.raises(InvalidTypeData):
>           schema_type({"name": "test"})

tests/test_types.py:400: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/types.py:727: in __call__
    value = self.schema.dump(value)
/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/schema.py:553: in dump
    result = self._serialize(processed_obj, many=many)
/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/schema.py:517: in _serialize
    value = field_obj.serialize(attr_name, obj, accessor=self.get_attribute)
/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/fields.py:325: in serialize
    return self._serialize(value, attr, obj, **kwargs)
/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/fields.py:916: in _serialize
    ret = self._format_num(value)  # type: _T
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <fields.Integer(default=<marshmallow.missing>, attribute=None, validate=None, required=False, load_only=False, dump_on...be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid integer.', 'too_large': 'Number too large.'})>
value = 'test'

    def _format_num(self, value) -> typing.Any:
        """Return the number value for value, given this field's `num_type`."""
>       return self.num_type(value)
E       ValueError: invalid literal for int() with base 10: 'test'

/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/fields.py:891: ValueError
_______________________ test_marshmallow_custom_context ________________________

    def test_marshmallow_custom_context():
        custom_context = dict(context="global", factory=0, delete=0, marshmallow=0)
    
        @hug.context_factory(apply_globally=True)
        def create_context(*args, **kwargs):
            custom_context["factory"] += 1
            return custom_context
    
        @hug.delete_context(apply_globally=True)
        def delete_context(context, *args, **kwargs):
            assert context == custom_context
            custom_context["delete"] += 1
    
        class MarshmallowContextSchema(Schema):
            name = fields.String()
    
            @validates_schema
            def check_context(self, data):
                assert self.context == custom_context
                self.context["marshmallow"] += 1
    
        @hug.get()
        def made_up_hello(test: MarshmallowContextSchema()):
            return "hi"
    
>       assert hug.test.get(api, "/made_up_hello", {"test": {"name": "test"}}).data == "hi"
E       assert {'errors': {'test': "__call__() missing 1 required positional argument: 'context'"}} == 'hi'
E        +  where {'errors': {'test': "__call__() missing 1 required positional argument: 'context'"}} = <falcon.testing.srmock.StartResponseMock object at 0x7fffe5627c10>.data
E        +    where <falcon.testing.srmock.StartResponseMock object at 0x7fffe5627c10> = functools.partial(<function call at 0x7fffe69f3280>, 'GET')(<hug.api.API object at 0x7fffe6053c10>, '/made_up_hello', {'test': {'name': 'test'}})
E        +      where functools.partial(<function call at 0x7fffe69f3280>, 'GET') = <module 'hug.test' from '/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/test.py'>.get
E        +        where <module 'hug.test' from '/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/test.py'> = hug.test

tests/test_types.py:475: AssertionError
____________________ test_validate_route_args_negative_case ____________________

    def test_validate_route_args_negative_case():
        @hug.get("/hello", raise_on_invalid=True, args={"foo": fields.Integer()})
        def hello(foo: int):
            return str(foo)
    
        with pytest.raises(ValidationError):
            hug.test.get(api, "/hello", **{"foo": "a"})
    
        class TestSchema(Schema):
            bar = fields.Integer()
    
        @hug.get("/foo", raise_on_invalid=True, args={"return": TestSchema()})
        def foo():
            return {"bar": "a"}
    
        with pytest.raises(InvalidTypeData):
>           hug.test.get(api, "/foo")

tests/test_types.py:828: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/test.py:81: in call
    result = api(
/nix/store/j7k4y6z6xrdlfl5nk6n05sb0ypjb1lql-python3.8-falcon-2.0.0/lib/python3.8/site-packages/falcon/api.py:269: in __call__
    responder(req, resp, **params)
/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/interface.py:946: in __call__
    raise exception
/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/interface.py:916: in __call__
    self.render_content(
/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/interface.py:851: in render_content
    content = self.transform_data(content, request, response, context)
/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/interface.py:778: in transform_data
    return transform(data)
/nix/store/sbm03ivynvxfnbbm7rkqdxcyxdhqcdg1-python3.8-hug-2.6.0/lib/python3.8/site-packages/hug/types.py:727: in __call__
    value = self.schema.dump(value)
/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/schema.py:553: in dump
    result = self._serialize(processed_obj, many=many)
/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/schema.py:517: in _serialize
    value = field_obj.serialize(attr_name, obj, accessor=self.get_attribute)
/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/fields.py:325: in serialize
    return self._serialize(value, attr, obj, **kwargs)
/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/fields.py:916: in _serialize
    ret = self._format_num(value)  # type: _T
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <fields.Integer(default=<marshmallow.missing>, attribute=None, validate=None, required=False, load_only=False, dump_on...be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid integer.', 'too_large': 'Number too large.'})>
value = 'a'

    def _format_num(self, value) -> typing.Any:
        """Return the number value for value, given this field's `num_type`."""
>       return self.num_type(value)
E       ValueError: invalid literal for int() with base 10: 'a'

/nix/store/k9q33lax3gqnj0jnibq3xnk573mbl526-python3.8-marshmallow-3.3.0/lib/python3.8/site-packages/marshmallow/fields.py:891: ValueError
=============================== warnings summary ===============================
/nix/store/q5wyf15ymsq73ny992c3aiy5fh0qsbdl-python3.8-pytest-5.3.5/lib/python3.8/site-packages/_pytest/mark/structures.py:323
  /nix/store/q5wyf15ymsq73ny992c3aiy5fh0qsbdl-python3.8-pytest-5.3.5/lib/python3.8/site-packages/_pytest/mark/structures.py:323: PytestUnknownMarkWarning: Unknown pytest.mark.extnetwork - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
    warnings.warn(

tests/test_coroutines.py::test_basic_call_coroutine
  /build/source/tests/test_coroutines.py:35: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def hello_world():

tests/test_coroutines.py::test_nested_basic_call_coroutine
  /build/source/tests/test_coroutines.py:46: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def hello_world():

tests/test_coroutines.py::test_nested_basic_call_coroutine
  /build/source/tests/test_coroutines.py:51: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def nested_hello_world():

tests/test_coroutines.py::test_basic_call_on_method_coroutine
  /build/source/tests/test_coroutines.py:63: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def hello_world(self=None):

tests/test_coroutines.py::test_basic_call_on_method_through_api_instance_coroutine
  /build/source/tests/test_coroutines.py:83: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def hello_world():

tests/test_coroutines.py::test_basic_call_on_method_registering_without_decorator_coroutine
  /build/source/tests/test_coroutines.py:98: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def hello_world_method(self):

tests/test_decorators.py::test_startup
  /build/source/tests/test_decorators.py:1589: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def async_happens_on_startup(api):

-- Docs: https://docs.pytest.org/en/latest/warnings.html
===== 6 failed, 463 passed, 1 skipped, 4 deselected, 8 warnings in 17.69s ======
@urbas
Copy link

urbas commented Jan 16, 2021

The underlying reason seems to be that an old unstable 3.x version of marshmallow is used in hug, while the reporter is likely trying to build against a recent stable 3.x version of marshmallow.

stefanor added a commit to stefanor/hug that referenced this issue Nov 24, 2024
This is expected by upstream, and they have added arguments in newer
releases.

Fixes: hugapi#859
stefanor added a commit to stefanor/hug that referenced this issue Nov 24, 2024
@stefanor stefanor linked a pull request Nov 24, 2024 that will close this issue
stefanor added a commit to stefanor/hug that referenced this issue Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants