-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Bob Tests produces different results between 2/3 #123
Comments
The Bob test suite uses |
Have you run into some actual problems with the test suite? Unexpected test result? Otherwise I'll close this. |
There was a discussion in one of the submissions where they had to use |
It would be super helpful if you could track down that submission or reproduce it! Otherwise, maybe @kytrinyx can help us find it? |
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). |
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
For 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 # -*- 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:
|
Under Python 2:
'ÜMLäÜTS!'.isupper() is
True, but
u'ÜMLäÜTS!'.isupper()is
False`.Under Python 3:
'ÜMLäÜTS!'.isupper()
isFalse
The problem is that the string is using precomposed characters and under Python 2,
str
is encoded in the source code encoding of the tests (UTF-8).The text was updated successfully, but these errors were encountered: