Giter Club home page Giter Club logo

Comments (7)

sjakobi avatar sjakobi commented on May 22, 2024

The Bob test suite uses unicode_literals to make sure that all strings are interpreted as unicode.

from python.

sjakobi avatar sjakobi commented on May 22, 2024

Have you run into some actual problems with the test suite? Unexpected test result?

Otherwise I'll close this.

from python.

AstraLuma avatar AstraLuma commented on May 22, 2024

There was a discussion in one of the submissions where they had to use str.decode() with str.isupper() and this was the only way I could figure out to reproduce the behavior.

from python.

sjakobi avatar sjakobi commented on May 22, 2024

It would be super helpful if you could track down that submission or reproduce it!

Otherwise, maybe @kytrinyx can help us find it?

from python.

sjakobi avatar sjakobi commented on May 22, 2024

I'm closing this for now but I'd be happy to discuss (and try to fix) this if the bug can actually be reproduced in a supported version of Python (2.7, 3.3, 3.4).

from python.

englishm avatar englishm commented on May 22, 2024

I ran into this issue while trying to demonstrate Exercism to a student new to programming. It was an unfortunate hurdle to encounter so early in the process.

There is certainly value in understanding the intricacies of Python unicode handling (and differences between 2 and 3), but I don't think Exercism's hello-world exercise is the right place to be confronted with those things.

$ python2.7 hello_world_test.py                                                        
.E.
======================================================================
ERROR: test_hello_with_umlaut_name (__main__.BobTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "hello_world_test.py", line 26, in test_hello_with_umlaut_name
    hello_world.hello('Jürgen')
  File "/Users/english/exercism/python/hello-world/hello_world.py", line 8, in hello
    return "Hello, {}!".format(name)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 1: ordinal
 not in range(128)                                                                    

----------------------------------------------------------------------
Ran 3 tests in 0.000s

FAILED (errors=1)
$ python3 hello_world_test.py 
...
----------------------------------------------------------------------
Ran 3 tests in 0.000s

OK
$ 

For hello_world.py:

def hello(name=''):
    if name != '':
        return "Hello, {}!".format(name)
    else:
      return 'Hello, World!'

(Very nearly the current example.py, so the results should be the same)

And hello_world_test.py:

# -*- coding: utf-8 -*-

from __future__ import unicode_literals
import unittest

import hello_world


class BobTests(unittest.TestCase):

    def test_hello_without_name(self):
        self.assertEqual(
            'Hello, World!',
            hello_world.hello()
        )

    def test_hello_with_name(self):
        self.assertEqual(
            'Hello, Jane!',
            hello_world.hello('Jane')
        )

    def test_hello_with_umlaut_name(self):
        self.assertEqual(
            'Hello, Jürgen!',
            hello_world.hello('Jürgen')
        )

if __name__ == '__main__':
    unittest.main()

Note that 2.7.x is still the default Python installed on many platforms, including macOS:

$ /usr/bin/python --version
Python 2.7.10

from python.

kytrinyx avatar kytrinyx commented on May 22, 2024

@englishm I've opened a new issue in the Python track about this: #1353

from python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.