Skip to content

Commit

Permalink
Add check_path function
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsavio committed Jan 29, 2016
1 parent e611bb6 commit 04a72ee
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
26 changes: 26 additions & 0 deletions hansel/check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
Helper functions to check crumbs or paths.
"""

from .crumb import Crumb


def check_path(path):
""" Return a Crumb if `path` has crumb arguments, a str otherwise.
Parameters
----------
path: str
Returns
-------
path: str or Crumb
"""
if Crumb.has_crumbs(path):
return Crumb(path)
else:
return path

15 changes: 15 additions & 0 deletions hansel/tests/test_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:


from six import string_types
from hansel.check import check_path
from hansel.crumb import Crumb


def test_check():

assert isinstance(check_path('/home/hansel/{files}'), Crumb)

assert isinstance(check_path('/home/hansel'), string_types)

0 comments on commit 04a72ee

Please sign in to comment.