<commit_before># -*- coding: utf-8 -*-
import pytest
import json

from marshmallow.fields import Field, DateTime

from apispec import APISpec
from apispec.ext.marshmallow import swagger
from .schemas import PetSchema, AnalysisSchema, SampleSchema, RunSchema, SelfReferencingSchema,\
    OrderedSchema, PatternedObjectSchema, DefaultCallableSchema


@pytest.fixture()
def spec():
    return APISpec(
        title='Swagger Petstore',
        version='1.0.0',
        description='This is a sample Petstore server.  You can find out more '
        'about Swagger at <a href=\"http://swagger.wordnik.com\">http://swagger.wordnik.com</a> '
        'or on irc.freenode.net, #swagger.  For this sample, you can use the api '
        'key \"special-key\" to test the authorization filters',
        plugins=[
            'apispec.ext.marshmallow'
        ]
    )

class TestDefinitionHelper:

    @pytest.mark.parametrize('schema', [PetSchema, PetSchema()])
    def test_can_use_schema_as_as_definition(self, spec, schema):
        spec.definition('Pet', schema=schema)
        assert 'Pet' in spec._definitions
        props = spec._definitions['Pet']['properties']

        assert props['id']['type'] == 'integer'
        assert props['name']['type'] == 'string'


class TestCustomField:

    def test_can_use_custom_field_decorator(self, spec):

        @swagger.map_to_swagger_field(DateTime)
        class CustomNameA(Field):
            pass

        @swagger.map_to_swagger_field('integer', 'int32')
        class CustomNameB(Field):
            pass

        class CustomPetASchema(PetSchema):
            name = CustomNameA()

        class CustomPetBSchema(PetSchema):
            name = CustomNameB()

        spec.definition('Pet', schema=PetSchema)
        spec.definition('CustomPetA', schema=CustomPetASchema)
        spec.definition('CustomPetB', schema=CustomPetBSchema)

        props_0 = spec._definitions['Pet']['properties']
        props_a = spec._definitions['CustomPetA']['properties']
        props_b = spec._definitions['CustomPetB']['properties']

        assert props_0['name']['type'] == 'string'
        assert 'format' not in props_0['name']

        assert props_a['name']['type'] == 'string'
        assert props_a['name']['format'] == 'date-time'

        assert props_b['name']['type'] == 'integer'
        assert props_b['name']['format'] == 'int32'
<commit_msg>error on bad arg<commit_after># -*- coding: utf-8 -*-
import pytest
import json

from marshmallow.fields import Field, DateTime

from apispec import APISpec
from apispec.ext.marshmallow import swagger
from .schemas import PetSchema, AnalysisSchema, SampleSchema, RunSchema, SelfReferencingSchema,\
    OrderedSchema, PatternedObjectSchema, DefaultCallableSchema


@pytest.fixture()
def spec():
    return APISpec(
        title='Swagger Petstore',
        version='1.0.0',
        description='This is a sample Petstore server.  You can find out more '
        'about Swagger at <a href=\"http://swagger.wordnik.com\">http://swagger.wordnik.com</a> '
        'or on irc.freenode.net, #swagger.  For this sample, you can use the api '
        'key \"special-key\" to test the authorization filters',
        plugins=[
            'apispec.ext.marshmallow'
        ]
    )

class TestDefinitionHelper:

    @pytest.mark.parametrize('schema', [PetSchema, PetSchema()])
    def test_can_use_schema_as_as_definition(self, spec, schema):
        spec.definition('Pet', schema=schema)
        assert 'Pet' in spec._definitions
        props = spec._definitions['Pet']['properties']

        assert props['id']['type'] == 'integer'
        assert props['name']['type'] == 'string'


class TestCustomField:

    def test_can_use_custom_field_decorator(self, spec):

        @swagger.map_to_swagger_field(DateTime)
        class CustomNameA(Field):
            pass

        @swagger.map_to_swagger_field('integer', 'int32')
        class CustomNameB(Field):
            pass

        with pytest.raises(TypeError):
            @swagger.map_to_swagger_field('integer')
            class BadCustomField(Field):
                pass

        class CustomPetASchema(PetSchema):
            name = CustomNameA()

        class CustomPetBSchema(PetSchema):
            name = CustomNameB()

        spec.definition('Pet', schema=PetSchema)
        spec.definition('CustomPetA', schema=CustomPetASchema)
        spec.definition('CustomPetB', schema=CustomPetBSchema)

        props_0 = spec._definitions['Pet']['properties']
        props_a = spec._definitions['CustomPetA']['properties']
        props_b = spec._definitions['CustomPetB']['properties']

        assert props_0['name']['type'] == 'string'
        assert 'format' not in props_0['name']

        assert props_a['name']['type'] == 'string'
        assert props_a['name']['format'] == 'date-time'

        assert props_b['name']['type'] == 'integer'
        assert props_b['name']['format'] == 'int32'

{'fraction_non_alphanumeric': 0.12813765182186235, 'fraction_numerical': 0.004453441295546558, 'mean_word_length': 3.0936205468102735, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2336795', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1435, 'n_words': 315}