Skip to content

Commit

Permalink
Merge 7320c0e into 33c81e1
Browse files Browse the repository at this point in the history
  • Loading branch information
s-m-i-t-a committed Aug 31, 2013
2 parents 33c81e1 + 7320c0e commit 34eacc4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ htmlcov/

# TextMate
.tm_properties

# Local env
.envs
8 changes: 4 additions & 4 deletions cookiecutter/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def prompt_for_config(context):
field names and sample values.
"""
cookiecutter_dict = {}

for key, val in iteritems(context['cookiecutter']):
prompt = "{0} (default is \"{1}\")? ".format(key, val)
new_val = input(prompt)
prompt = u"{0} (default is \"{1}\")? ".format(key, val)
new_val = input(prompt.encode('utf-8'))
new_val = new_val.strip()

if new_val == '':
new_val = val

if PY3:
cookiecutter_dict[key] = new_val
else:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@

PY3 = sys.version > '3'
if PY3:
import subprocess
from unittest.mock import patch
input_str = 'builtins.input'
from io import StringIO
else:
import subprocess32 as subprocess
import __builtin__
from mock import patch
input_str = '__builtin__.raw_input'
from cStringIO import StringIO

if sys.version_info[:2] < (2, 7):
if sys.version_info[:3] < (2, 7):
import unittest2 as unittest
import subprocess32 as subprocess
else:
import subprocess
import unittest

try:
Expand Down
16 changes: 15 additions & 1 deletion tests/test_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


class TestPrompt(unittest.TestCase):

@patch(input_str, lambda x: 'Audrey Roy')
def test_prompt_for_config_simple(self):
context = {"cookiecutter": {"full_name": "Your Name"}}
Expand All @@ -55,6 +55,20 @@ def test_prompt_for_config_unicode(self):
else:
self.assertEqual(cookiecutter_dict, {"full_name": u"Pizzä ïs Gööd"})

@patch(input_str, lambda x: 'Pizzä ïs Gööd')
def test_unicode_prompt_for_config_unicode(self):
context = {"cookiecutter": {"full_name": u"Řekni či napiš své jméno"}}

if not PY3:
sys.stdin = StringIO("Pizzä ïs Gööd")

cookiecutter_dict = prompt.prompt_for_config(context)

if PY3:
self.assertEqual(cookiecutter_dict, {"full_name": "Pizzä ïs Gööd"})
else:
self.assertEqual(cookiecutter_dict, {"full_name": u"Pizzä ïs Gööd"})


class TestQueryAnswers(unittest.TestCase):

Expand Down

0 comments on commit 34eacc4

Please sign in to comment.