<commit_before># -*- coding: utf-8 -*-
import unittest
from mock import Mock, patch, NonCallableMock
from flask import Flask
from werkzeug import exceptions
from werkzeug.wrappers import Request
from werkzeug.datastructures import FileStorage
from flask_restful.reqparse import Argument, RequestParser, Namespace
import six

import json


class ReqParseTestCase(unittest.TestCase):
    def test_default_help(self):
        arg = Argument("foo")
        self.assertEquals(arg.help, None)

    @patch('flask_restful.abort')
    def test_help(self, abort):
        from werkzeug.datastructures import MultiDict
        parser = RequestParser()
        parser.add_argument('foo', choices=['one', 'two'], help='Bad choice')
        req = Mock(['values'])
        req.values = MultiDict([('foo', 'three')])
        parser.parse_args(req)
        abort.assert_called_with(400, message='Bad choice')

    @patch('flask_restful.abort', side_effect=exceptions.BadRequest('Bad Request'))
    def test_no_help(self, abort):
        def bad_choice():
            from werkzeug.datastructures import MultiDict
            parser = RequestParser()
            parser.add_argument('foo', choices=['one', 'two'])
            req = Mock(['values'])
            req.values = MultiDict([('foo', 'three')])
            parser.parse_args(req)
            abort.assert_called_with(400, message='three is not a valid choice')

        self.assertRaises(exceptions.BadRequest, bad_choice)

    def test_name(self):
        arg = Argument("foo")
        self.assertEquals(arg.name, "foo")

    def test_dest(self):
        arg = Argument("foo", dest="foobar")
        self.assertEquals(arg.dest, "foobar")

    def test_location_url(self):
        arg = Argument("foo", location="url")
        self.assertEquals(arg.location, "url")

    def test_location_url_list(self):
        arg = Argument("foo", location=["url"])
        self.assertEquals(arg.location, ["url"])

    def test_location_header(self):
        arg = Argument("foo", location="headers")
        self.assertEquals(arg.location, "headers")

    def test_location_json(self):
        arg = Argument("foo", location="json")
        self.assertEquals(arg.location, "json")

    def test_location_get_json(self):
        arg = Argument("foo", location="get_json")
        self.assertEquals(arg.location, "get_json")

    def test_location_header_list(self):
        arg = Argument("foo", location=["headers"])
        self.assertEquals(arg.location, ["headers"])

    def test_type(self):
        arg = Argument("foo", type=int)
        self.assertEquals(arg.type, int)

    def test_default(self):
        arg = Argument("foo", default=True)
        self.assertEquals(arg.default, True)

    def test_required(self):
        arg = Argument("foo", required=True)
        self.assertEquals(arg.required, True)

    def test_ignore(self):
        arg = Argument("foo", ignore=True)
        self.assertEquals(arg.ignore, True)

    def test_operator(self):
        arg = Argument("foo", operators=[">=", "<=", "="])
        self.assertEquals(arg.operators, [">=", "<=", "="])

    def test_action_filter(self):
        arg = Argument("foo", action="filter")
        self.assertEquals(arg.action, u"filter")

    def test_action(self):
        arg = Argument("foo", action="append")
        self.assertEquals(arg.action, u"append")

    def test_choices(self):
        arg = Argument("foo", choices=[1, 2])
        self.assertEquals(arg.choices, [1, 2])

    def test_default_dest(self):
        arg = Argument("foo")
        self.assertEquals(arg.dest, None)

    def test_default_operators(self):
        arg = Argument("foo")
        self.assertEquals(arg.operators[0], "=")
        self.assertEquals(len(arg.operators), 1)

    @patch('flask_restful.reqparse.six')
    def test_default_type(self, mock_six):
        arg = Argument("foo")
        sentinel = object()
        arg.type(sentinel)
        mock_six.text_type.assert_called_with(sentinel)

    def test_default_default(self):
        arg = Argument("foo")
        self.assertEquals(arg.default, None)

    def test_required_default(self):
        arg = Argument("foo")
        self.assertEquals(arg.required, False)

    def test_ignore_default(self):
        arg = Argument("foo")
        self.assertEquals(arg.ignore, False)

    def test_action_default(self):
        arg = Argument("foo")
        self.assertEquals(arg.action, u"store")

    def test_choices_default(self):
        arg = Argument("foo")
        self.assertEquals(len(arg.choices), 0)

    def test_source(self):
        req = Mock(['args', 'headers', 'values'])
        req.args = {'foo': 'bar'}
        req.headers = {'baz': 'bat'}
        arg = Argument('foo', location=['args'])
        self.assertEquals(arg.source(req), req.args)

        arg = Argument('foo', location=['headers'])
        self.assertEquals(arg.source(req), req.headers)

    def test_source_bad_location(self):
        req = Mock(['values'])
        arg = Argument('foo', location=['foo'])
        self.assertTrue(len(arg.source(req)) == 0)  # yes, basically you don't find it

    def test_source_default_location(self):
        req = Mock(['values'])
        req._get_child_mock = lambda **kwargs: NonCallableMock(**kwargs)
        arg = Argument('foo')
        self.assertEquals(arg.source(req), req.values)

    def test_option_case_sensitive(self):
        arg = Argument("foo", choices=["bar", "baz"], case_sensitive=True)<commit_msg>Updating tests for my pull request.<commit_after># -*- coding: utf-8 -*-
import unittest
from mock import Mock, patch, NonCallableMock
from flask import Flask
from werkzeug import exceptions, MultiDict
from werkzeug.wrappers import Request
from werkzeug.datastructures import FileStorage
from flask_restful.reqparse import Argument, RequestParser, Namespace
import six

import json


class ReqParseTestCase(unittest.TestCase):
    def test_default_help(self):
        arg = Argument("foo")
        self.assertEquals(arg.help, None)

    @patch('flask_restful.abort')
    def test_help(self, abort):
        from werkzeug.datastructures import MultiDict
        parser = RequestParser()
        parser.add_argument('foo', choices=['one', 'two'], help='Bad choice')
        req = Mock(['values'])
        req.values = MultiDict([('foo', 'three')])
        parser.parse_args(req)
        abort.assert_called_with(400, message='Bad choice')

    @patch('flask_restful.abort', side_effect=exceptions.BadRequest('Bad Request'))
    def test_no_help(self, abort):
        def bad_choice():
            from werkzeug.datastructures import MultiDict
            parser = RequestParser()
            parser.add_argument('foo', choices=['one', 'two'])
            req = Mock(['values'])
            req.values = MultiDict([('foo', 'three')])
            parser.parse_args(req)
            abort.assert_called_with(400, message='three is not a valid choice')

        self.assertRaises(exceptions.BadRequest, bad_choice)

    def test_name(self):
        arg = Argument("foo")
        self.assertEquals(arg.name, "foo")

    def test_dest(self):
        arg = Argument("foo", dest="foobar")
        self.assertEquals(arg.dest, "foobar")

    def test_location_url(self):
        arg = Argument("foo", location="url")
        self.assertEquals(arg.location, "url")

    def test_location_url_list(self):
        arg = Argument("foo", location=["url"])
        self.assertEquals(arg.location, ["url"])

    def test_location_header(self):
        arg = Argument("foo", location="headers")
        self.assertEquals(arg.location, "headers")

    def test_location_json(self):
        arg = Argument("foo", location="json")
        self.assertEquals(arg.location, "json")

    def test_location_get_json(self):
        arg = Argument("foo", location="get_json")
        self.assertEquals(arg.location, "get_json")

    def test_location_header_list(self):
        arg = Argument("foo", location=["headers"])
        self.assertEquals(arg.location, ["headers"])

    def test_type(self):
        arg = Argument("foo", type=int)
        self.assertEquals(arg.type, int)

    def test_default(self):
        arg = Argument("foo", default=True)
        self.assertEquals(arg.default, True)

    def test_required(self):
        arg = Argument("foo", required=True)
        self.assertEquals(arg.required, True)

    def test_ignore(self):
        arg = Argument("foo", ignore=True)
        self.assertEquals(arg.ignore, True)

    def test_operator(self):
        arg = Argument("foo", operators=[">=", "<=", "="])
        self.assertEquals(arg.operators, [">=", "<=", "="])

    def test_action_filter(self):
        arg = Argument("foo", action="filter")
        self.assertEquals(arg.action, u"filter")

    def test_action(self):
        arg = Argument("foo", action="append")
        self.assertEquals(arg.action, u"append")

    def test_choices(self):
        arg = Argument("foo", choices=[1, 2])
        self.assertEquals(arg.choices, [1, 2])

    def test_default_dest(self):
        arg = Argument("foo")
        self.assertEquals(arg.dest, None)

    def test_default_operators(self):
        arg = Argument("foo")
        self.assertEquals(arg.operators[0], "=")
        self.assertEquals(len(arg.operators), 1)

    @patch('flask_restful.reqparse.six')
    def test_default_type(self, mock_six):
        arg = Argument("foo")
        sentinel = object()
        arg.type(sentinel)
        mock_six.text_type.assert_called_with(sentinel)

    def test_default_default(self):
        arg = Argument("foo")
        self.assertEquals(arg.default, None)

    def test_required_default(self):
        arg = Argument("foo")
        self.assertEquals(arg.required, False)

    def test_ignore_default(self):
        arg = Argument("foo")
        self.assertEquals(arg.ignore, False)

    def test_action_default(self):
        arg = Argument("foo")
        self.assertEquals(arg.action, u"store")

    def test_choices_default(self):
        arg = Argument("foo")
        self.assertEquals(len(arg.choices), 0)

    def test_source(self):
        req = Mock(['args', 'headers', 'values'])
        req.args = {'foo': 'bar'}
        req.headers = {'baz': 'bat'}
        arg = Argument('foo', location=['args'])
        self.assertEquals(arg.source(req), MultiDict(req.args))

        arg = Argument('foo', location=['headers'])
        self.assertEquals(arg.source(req), MultiDict(req.headers))

    def test_source_bad_location(self):
        req = Mock(['values'])
        arg = Argument('foo', location=['foo'])
        self.assertTrue(len(arg.source(req)) == 0)  # yes, basically you don't find it

    def test_source_default_location(self):
        req = Mock(['values'])
        req._get_child_mock = lambda **kwargs: MultiDict()
        arg = Argument('foo')
        self.assertEquals(arg.source(req), req.values)

    def test_option_case_sensitive(self):
        arg = Argument("foo", choices=["bar", "baz"], case_sensitive=True)
{'fraction_non_alphanumeric': 0.14229895502044526, 'fraction_numerical': 0.0027260336210813267, 'mean_word_length': 3.097542814594192, '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': '1966247', 'n_tokens_mistral': 3289, 'n_tokens_neox': 3194, 'n_words': 649}