Skip to content

Commit

Permalink
fix DRY typed vars tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nitely committed Jul 5, 2017
1 parent 8b09e79 commit a029c16
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions tests/tests_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
logging.disable(logging.CRITICAL)


def is_int(var):
return var.isdigit()


def is_alphanum(var):
return var.isalnum()


class KuaTest(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -262,9 +270,6 @@ def test_var_validate(self):
"""
Should validate a var
"""
def is_int(var):
return var.isdigit()

self.routes.add(':var', 'foo', {'var': is_int})

route = self.routes.match('123')
Expand All @@ -277,12 +282,6 @@ def test_var_validate_many(self):
"""
Should validate a many vars
"""
def is_alphanum(var):
return var.isalnum()

def is_int(var):
return var.isdigit()

self.routes.add(':var/:var2/:var3', 'foo', {'var': is_int, 'var2': is_alphanum})

route = self.routes.match('123/foo123/bar123---')
Expand All @@ -296,12 +295,6 @@ def test_var_validate_clashing(self):
"""
Should validate clashing vars
"""
def is_alphanum(var):
return var.isalnum()

def is_int(var):
return var.isdigit()

# todo: support clashing urls!

self.routes.add(':var', 'foo', {'var': is_int})
Expand All @@ -317,9 +310,6 @@ def test_any_var_validate(self):
def is_each(func):
return lambda vars_: all(func(var) for var in vars_)

def is_int(var):
return var.isdigit()

self.routes.add(':*var', 'foo', {'var': is_each(is_int)})

route = self.routes.match('123/456/789')
Expand All @@ -332,9 +322,6 @@ def test_add_bad_validate_params(self):
"""
Should raise an error when validate params don't match pattern params
"""
def is_int(var):
return var.isdigit()

self.assertRaises(
routes.RouteError, self.routes.add, ':var', 'foo', {'bad': is_int})
self.assertRaises(
Expand Down

0 comments on commit a029c16

Please sign in to comment.