boltons/tests/test_strutils.py

27 lines
667 B
Python
Raw Normal View History

2015-05-20 06:18:38 +00:00
# -*- coding: utf-8 -*-
import uuid
2016-01-24 08:47:01 +00:00
from boltons import strutils
2015-05-20 06:18:38 +00:00
def test_asciify():
ref = u'Beyoncé'
2016-01-24 08:47:01 +00:00
b = strutils.asciify(ref)
2015-05-20 06:18:38 +00:00
assert len(b) == len(b)
assert b[-1:].decode('ascii') == 'e'
2016-01-24 08:47:01 +00:00
def test_indent():
to_indent = '\nabc\ndef\n\nxyz\n'
ref = '\n abc\n def\n\n xyz\n'
assert strutils.indent(to_indent, ' ') == ref
def test_is_uuid():
assert strutils.is_uuid(uuid.uuid4()) == True
assert strutils.is_uuid(uuid.uuid4(), version=1) == False
assert strutils.is_uuid(str(uuid.uuid4())) == True
assert strutils.is_uuid(str(uuid.uuid4()), version=1) == False
assert strutils.is_uuid(set('garbage')) == False