Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hello World: ümlauts & unicode #1353

Closed
kytrinyx opened this issue Feb 26, 2018 · 10 comments
Closed

Hello World: ümlauts & unicode #1353

kytrinyx opened this issue Feb 26, 2018 · 10 comments

Comments

@kytrinyx
Copy link
Member

From @englishm in #123 (comment)


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
@kytrinyx
Copy link
Member Author

I don't think Exercism's hello-world exercise is the right place to be confronted with those things.

I agree. We've discussed the value of simplifying hello world (see exercism/problem-specifications#520 and exercism/problem-specifications#548).

The outcome of that discussion was two things:

  1. We reworked the problem description for Hello World so that it can be a simple check that you've managed to wire everything up correctly.
  2. We implemented a new exercise called Two Fer, which has the same shape as the old Hello World exercise, but doesn't assume that it is placed at the beginning of the track.

My recommendation would be to implement two-fer, stick it somewhere farther along in the track, and simplify hello-world.

@cmccandless
Copy link
Contributor

This was fixed almost a year ago in #432.... @englishm, it looks like you are working with an old version of hello_world_test.py. Was this copied from your own workspace, or was this downloaded with exercism fetch python?

@englishm
Copy link

englishm commented Mar 2, 2018

@cmccandless my apologies! It's quite possible that I had a stale copy in my workspace - I probably fetched the python track long before I tried working on it. Sorry I didn't verify that first.

@englishm
Copy link

englishm commented Mar 2, 2018

It looks like exercism fetch python alone won't re-fetch files I already have.

I seem to recall now this being an issue I've run into before with other exercises that had been fixed, while my local copies still had the bugs...

Sure enough though, if I delete the test suite and then run exercism fetch python it gets me a version that works with both Python 3 and Python 2.7.

$ python2.7 hello_world_test.py                                                                                                                                                  
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
$ python3 hello_world_test.py 
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
$ 
hello_world_test.py diff
diff --git a/hello-world/hello_world_test.py b/hello-world/hello_world_test.py
index c6b5be9..c1bcd6c 100644
--- a/hello-world/hello_world_test.py
+++ b/hello-world/hello_world_test.py
@@ -1,30 +1,14 @@
-# -*- 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()
-        )
+# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0
 
-    def test_hello_with_name(self):
-        self.assertEqual(
-            'Hello, Jane!',
-            hello_world.hello('Jane')
-        )
+class HelloWorldTests(unittest.TestCase):
+    def test_hello(self):
+        self.assertEqual(hello_world.hello(), 'Hello, World!')
 
-    def test_hello_with_umlaut_name(self):
-        self.assertEqual(
-            'Hello, Jürgen!',
-            hello_world.hello('Jürgen')
-        )
 
 if __name__ == '__main__':
     unittest.main()

So sorry for the false alarm!

@englishm
Copy link

englishm commented Mar 2, 2018

I think this can be closed.

There may be a minor usability issue worth tracking about this exercism fetch behavior, but that's really a separate issue.

@englishm
Copy link

englishm commented Mar 2, 2018

Looks like there's already an open issue for the exercism fetch behavior that led to my misreport:

exercism/cli#255

@cmccandless
Copy link
Contributor

@englishm I ran into this issue with exercism fetch myself (although I just assumed this was intended behavior). I created this script to update test suites and exercise READMEs without modifying my solution.

@kytrinyx
Copy link
Member Author

kytrinyx commented Mar 2, 2018

It looks like exercism fetch python alone won't re-fetch files I already have.

It doesn't overwrite existing files (on purpose). When we move to v2 we'll be making that command interactive so it asks if it should overwrite the file instead of just silently not doing it.

@cmccandless
Copy link
Contributor

@kytrinyx @englishm As this has been determined to be a CLI issue and not a Python track issue, do either of you mind if a close this?

@kytrinyx
Copy link
Member Author

kytrinyx commented Mar 6, 2018

Closing, thanks!

@kytrinyx kytrinyx closed this as completed Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants