Skip to content

Commit

Permalink
Move imports to top and add requirements.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwri committed Sep 28, 2016
1 parent 4d58148 commit cdaac81
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nose==1.3.7
six==1.10.0
4 changes: 3 additions & 1 deletion voluptuous/encoding.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sys


def to_utf8_py2(data):
import sys
if sys.version_info < (3,) and isinstance(data, unicode):
return data.encode('utf-8')
return data
3 changes: 1 addition & 2 deletions voluptuous/schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import error as er
except ImportError:
from . import error as er
from .encoding import to_utf8_py2

if sys.version_info >= (3,):
long = int
Expand Down Expand Up @@ -260,7 +261,6 @@ def _compile_mapping(self, schema, invalid_msg=None):
candidates = list(_iterate_mapping_candidates(_compiled_schema))

def validate_mapping(path, iterable, out):
from .encoding import to_utf8_py2
required_keys = all_required_keys.copy()
# keeps track of all default keys that haven't been filled
default_keys = all_default_keys.copy()
Expand Down Expand Up @@ -811,7 +811,6 @@ class Marker(object):
"""Mark nodes for special treatment."""

def __init__(self, schema_, msg=None):
from .encoding import to_utf8_py2
schema_ = to_utf8_py2(schema_)
self.schema = schema_
self._schema = Schema(schema_)
Expand Down
6 changes: 2 additions & 4 deletions voluptuous/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
validate, ExactSequence, Equal, Unordered
)
from voluptuous.humanize import humanize_error
from voluptuous.encoding import to_utf8_py2
import six


def test_exact_sequence():
Expand Down Expand Up @@ -560,7 +562,6 @@ def fn(arg):

def test_unicode_key_is_converted_to_utf8_when_in_marker():
"""Verify that when using unicode key the 'u' prefix is not thrown in the exception"""
import six
schema = Schema({Required(six.u('q')): 1})
# Can't use nose's raises (because we need to access the raised
# exception, nor assert_raises which fails with Python 2.6.9.
Expand All @@ -571,7 +572,6 @@ def test_unicode_key_is_converted_to_utf8_when_in_marker():


def test_unicode_key_is_converted_to_utf8_when_plain_text():
import six
key = six.u('q')
schema = Schema({key: int})
# Can't use nose's raises (because we need to access the raised
Expand All @@ -583,7 +583,5 @@ def test_unicode_key_is_converted_to_utf8_when_plain_text():


def test_to_utf8_py2():
import six
from voluptuous.encoding import to_utf8_py2
s = six.u('hello')
assert_true(isinstance(to_utf8_py2(s), str))

0 comments on commit cdaac81

Please sign in to comment.