# Path: lighty/wsgi/urls.py
# def resolve(urls, path, method=None):
#     '''Resolve url for path and method name
#     '''
#     for expr, _, view, _, defaults, _, _, methods in urls:
#         if not method or method in methods:
#             match = expr.match(path)
#             if match:
#                 call_args = copy.copy(defaults)
#                 call_args.update(match.groupdict())
#                 return functools.partial(view, **call_args)
#     return NoneMonad(LookupError('There is no pattern matching path %s' %
#                                  path))
# 
# def reverse(urls, lookup_name, lookup_args=None):
#     '''Get url for name with specified args number
#     '''
#     lookup_keys = sorted(lookup_args.keys()) if lookup_args else []
#     for _, pattern, _, name, _, args, _, _ in urls:
#         if name == lookup_name and lookup_keys == sorted(args.keys()):
#             replacement = [(args[var], lookup_args[var])
#                            for var in lookup_keys]
#             return functools.reduce(replace_arg, [pattern] + replacement)
#     return NoneMonad(LookupError(
#                             'Url for name "%s" with args "%s" was not found' %
#                             (lookup_name, ','.join(lookup_keys))))
# 
# def url(pattern, view, name='', **kwargs):
#     '''Prepare url for application
#     '''
#     constraints = kwargs.get('constraints', {})
#     defaults = kwargs.get('defaults', {})
#     methods = kwargs.get('methods', HTTP_METHODS)
#     variables = [get_arg(var, constraints)
#                  for var in VARIABLE_PATTERN.findall(pattern)]
#     constrs = dict([(var[1], var[2]) for var in variables])
#     args = dict([(var[1], var[0]) for var in variables])
#     url_expr = re.compile(functools.reduce(replace_pattern,
#                                            [pattern + '$'] + variables))
#     view_func = load_view(view)
#     url_name = name is not '' and name or view_func
#     return (url_expr, pattern, view_func, url_name, defaults, args, constrs,
#             methods)


import unittest
from lighty.wsgi.urls import resolve, reverse, url
        func = resolve(self.urls, '/arg/a-1', method='GET').func
        assert func == one_arg_func_str, (
                'Non str argument function for /arg/a-1')

    def testDefaultArgUrl(self):
        '''Test resolving url with default type argument'''
        func = resolve(self.urls, '/default_arg/adftr/', method='GET').func
        assert func == one_arg_func, (
                'One arg function required for /default_arg/adftr/')

    def testTwoArgUrl(self):
        '''Test resolving url with two arguments'''
        func = resolve(self.urls, '/args/test/7/', method='GET').func
        assert func == two_arg_func, (
                'Two arg function required for /args/test/7/')

    def testNonExistsUrl(self):
        '''Test resolving not existen url'''
        func = resolve(self.urls, '/g/g/g/', method='GET')
        assert not func, 'Resolved with wrong arg for /args/test/g/'


    def testReverseNoArgsUrl(self):
        '''Test reversing url without arguments'''
        url = reverse(self.urls, 'noargs')
        assert url == '/test/', ('Error reversing url for name "noargs": %s' %
                                 url)

    def testReverseOneArgUrl(self):
        '''Test reversing url with one argument'''

# Path: lighty/wsgi/urls.py
# def resolve(urls, path, method=None):
#     '''Resolve url for path and method name
#     '''
#     for expr, _, view, _, defaults, _, _, methods in urls:
#         if not method or method in methods:
#             match = expr.match(path)
#             if match:
#                 call_args = copy.copy(defaults)
#                 call_args.update(match.groupdict())
#                 return functools.partial(view, **call_args)
#     return NoneMonad(LookupError('There is no pattern matching path %s' %
#                                  path))
# 
# def reverse(urls, lookup_name, lookup_args=None):
#     '''Get url for name with specified args number
#     '''
#     lookup_keys = sorted(lookup_args.keys()) if lookup_args else []
#     for _, pattern, _, name, _, args, _, _ in urls:
#         if name == lookup_name and lookup_keys == sorted(args.keys()):
#             replacement = [(args[var], lookup_args[var])
#                            for var in lookup_keys]
#             return functools.reduce(replace_arg, [pattern] + replacement)
#     return NoneMonad(LookupError(
#                             'Url for name "%s" with args "%s" was not found' %
#                             (lookup_name, ','.join(lookup_keys))))
# 
# def url(pattern, view, name='', **kwargs):
#     '''Prepare url for application
#     '''
#     constraints = kwargs.get('constraints', {})
#     defaults = kwargs.get('defaults', {})
#     methods = kwargs.get('methods', HTTP_METHODS)
#     variables = [get_arg(var, constraints)
#                  for var in VARIABLE_PATTERN.findall(pattern)]
#     constrs = dict([(var[1], var[2]) for var in variables])
#     args = dict([(var[1], var[0]) for var in variables])
#     url_expr = re.compile(functools.reduce(replace_pattern,
#                                            [pattern + '$'] + variables))
#     view_func = load_view(view)
#     url_name = name is not '' and name or view_func
#     return (url_expr, pattern, view_func, url_name, defaults, args, constrs,
#             methods)


# Path: tests/urls.py
import unittest
from lighty.wsgi.urls import resolve, reverse, url

        func = resolve(self.urls, '/arg/a-1', method='GET').func
        assert func == one_arg_func_str, (
                'Non str argument function for /arg/a-1')

    def testDefaultArgUrl(self):
        '''Test resolving url with default type argument'''
        func = resolve(self.urls, '/default_arg/adftr/', method='GET').func
        assert func == one_arg_func, (
                'One arg function required for /default_arg/adftr/')

    def testTwoArgUrl(self):
        '''Test resolving url with two arguments'''
        func = resolve(self.urls, '/args/test/7/', method='GET').func
        assert func == two_arg_func, (
                'Two arg function required for /args/test/7/')

    def testNonExistsUrl(self):
        '''Test resolving not existen url'''
        func = resolve(self.urls, '/g/g/g/', method='GET')
        assert not func, 'Resolved with wrong arg for /args/test/g/'


    def testReverseNoArgsUrl(self):
        '''Test reversing url without arguments'''
        url = reverse(self.urls, 'noargs')
        assert url == '/test/', ('Error reversing url for name "noargs": %s' %
                                 url)

    def testReverseOneArgUrl(self):
        '''Test reversing url with one argument'''

        url = reverse(self.urls, 'onearg', {'id': 10})