[issue9868] test_locale leaves locale changed

2010-09-24 Thread Hirokazu Yamamoto

Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp added the comment:

Committed in r84973(py3k) and r84990(release31-maint).

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com




[issue9868] test_locale leaves locale changed

2010-09-23 Thread Michael Foord

Michael Foord mich...@voidspace.org.uk added the comment:

unittest *can't* know which setUp methods have already been called if an error 
occurs in one of them (because they are called explicitly by the sub-classes 
and not by unittest itself). Given this, the specific fix suggested seems good.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9868] test_locale leaves locale changed

2010-09-23 Thread Hirokazu Yamamoto

Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp added the comment:

 unittest *can't* know which setUp methods have already been called if
 an error occurs in one of them (because they are called explicitly by
 the sub-classes and not by unittest itself).

Well, C++ constructor/destructor behaves like that when constructor
of subclass raised exception. Destructors of super classes are called
in reverse order. The benefit of it is implementator of subclass
don't have to care about finalization of super class. It is done
automatically. But if explicit call is essential for us, my proposal
is not needed.

 Given this, the specific fix suggested seems good.
Thanks, I'll commit this.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9868] test_locale leaves locale changed

2010-09-23 Thread Michael Foord

Michael Foord mich...@voidspace.org.uk added the comment:

Destructors are special cased in many languages and tearDown is not a 
destructor. More importantly though the change you suggest would be backwards 
incompatible.

The 'correct' way to do this in new code is to use cleanUp functions which 
*are* called even if an exception is raised during setUp.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9868] test_locale leaves locale changed

2010-09-23 Thread Hirokazu Yamamoto

Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp added the comment:

 Destructors are special cased in many languages and tearDown is not a
 destructor.

Yes, but they are similar.

 More importantly though the change you suggest would be
 backwards incompatible.

 The 'correct' way to do this in new code is to use cleanUp functions
 which *are* called even if an exception is raised during setUp.

I must admit I'm not familiar with unittest framework. Probably
better way exists.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9868] test_locale leaves locale changed

2010-09-20 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +giampaolo.rodola, lemburg, michael.foord, pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9868] test_locale leaves locale changed

2010-09-16 Thread Hirokazu Yamamoto

Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp added the comment:

This patch is *as is* patch.

Index: Lib/test/test_locale.py
===
--- Lib/test/test_locale.py (revision 84824)
+++ Lib/test/test_locale.py (working copy)
@@ -352,13 +352,13 @@
 locale_type = locale.LC_ALL
 
 def setUp(self):
-BaseLocalizedTest.setUp(self)
 enc = codecs.lookup(locale.getpreferredencoding(False) or 'ascii').name
 if enc not in ('utf-8', 'iso8859-1', 'cp1252'):
 raise unittest.SkipTest('encoding not suitable')
 if enc != 'iso8859-1' and (sys.platform == 'darwin' or
sys.platform.startswith('freebsd')):
 raise unittest.SkipTest('wcscoll/wcsxfrm have known bugs')
+BaseLocalizedTest.setUp(self)
 
 def test_strcoll_with_diacritic(self):
 self.assertLess(locale.strcoll('テ', 'b'), 0)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9868] test_locale leaves locale changed

2010-09-15 Thread Hirokazu Yamamoto

New submission from Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp:

I noticed test_locale leaves locale changed.

# test_boo is simple test just to print windows error.

E:\python-dev\py3k\Lib\testpy3k -m test.regrtest test_locale test_boo
[1/2] test_locale
[2/2] test_boo
test test_boo failed -- Traceback (most recent call last):
  File e:\python-dev\py3k\lib\test\test_boo.py, line 11, in test
os.rmdir(TMPDIR)
WindowsError: [Error 2] ?w’e?3?e??...@?c???a?c?a?c?e?u?1?n?b: 'e:\\python-dev\\
py3k\\lib\\test\\__boo__'
Traceback (most recent call last):
  File e:\python-dev\py3k\lib\test\regrtest.py, line 941, in runtest_inner
indirect_test()
  File e:\python-dev\py3k\lib\test\test_boo.py, line 14, in test_main
support.run_unittest(TestCase)
  File e:\python-dev\py3k\lib\test\support.py, line 1128, in run_unittest
_run_suite(suite)
  File e:\python-dev\py3k\lib\test\support.py, line , in _run_suite
raise TestFailed(err)
test.support.TestFailed: Traceback (most recent call last):
  File e:\python-dev\py3k\lib\test\test_boo.py, line 11, in test
os.rmdir(TMPDIR)
WindowsError: [Error 2] ?w’e?3?e??...@?c???a?c?a?c?e?u?1?n?b: 'e:\\python-dev\\
py3k\\lib\\test\\__boo__'
test.support.TestFailed: Traceback (most recent call last):
  File e:\python-dev\py3k\lib\test\test_boo.py, line 11, in test
os.rmdir(TMPDIR)
WindowsError: [Error 2] ?w’e?3?e??...@?c???a?c?a?c?e?u?1?n?b: 'e:\\python-dev\\
py3k\\lib\\test\\__boo__'

During handling of the above exception, another exception occurred:

test test_boo failed -- Traceback (most recent call last):
  File e:\python-dev\py3k\lib\test\test_boo.py, line 11, in test
os.rmdir(TMPDIR)
WindowsError: [Error 2] ?w’e?3?e??...@?c???a?c?a?c?e?u?1?n?b: 'e:\\python-dev\\
py3k\\lib\\test\\__boo__'
test.support.TestFailed: Traceback (most recent call last):
  File e:\python-dev\py3k\lib\test\test_boo.py, line 11, in test
os.rmdir(TMPDIR)
WindowsError: [Error 2] ?w’e?3?e??...@?c???a?c?a?c?e?u?1?n?b: 'e:\\python-dev\\
py3k\\lib\\test\\__boo__'

During handling of the above exception, another exception occurred:

Exception IOError: 'raw write() returned invalid length 253 (should have been be
tween 0 and 252)' in _io.TextIOWrapper name='stdout' encoding='cp932' ignore
d
test.support.TestFailed: Traceback (most recent call last):
  File e:\python-dev\py3k\lib\test\test_boo.py, line 11, in test
os.rmdir(TMPDIR)
WindowsError: [Error 2] ?w’e?3?e??...@?c???a?c?a?c?e?u?1?n?b: 'e:\\python-dev\\
py3k\\lib\\test\\__boo__'

During handling of the above exception, another exception occurred:

Exception IOError: 'raw write() returned invalid length 253 (should have been be
tween 0 and 252)' in _io.TextIOWrapper name='stdout' encoding='cp932' ignore
d
[79459 refs]

/
// test_boo.py

from test import support
import unittest
import os

TMPDIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 
__notexist__)

class TestCase(unittest.TestCase):
def test(self):
os.rmdir(TMPDIR)

def test_main():
support.run_unittest(TestCase)

if __name__ == '__main__':
test_main()

--
components: Tests
messages: 116506
nosy: ocean-city
priority: normal
severity: normal
status: open
title: test_locale leaves locale changed
versions: Python 3.1, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9868] test_locale leaves locale changed

2010-09-15 Thread Hirokazu Yamamoto

Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp added the comment:

This happens because in Lib/test/test_locale.py,
TestEnUSCollation#setUp raises exception after
BaseLocalizedTest.setUp(self) changed locale.
tearDown never be called when setUp failedsetUp failed.

It's easy to fix this as is, but I think more general
solution would be better.

How about the mechanism like this? It calls setUp() and
tearDown() in according to MRO, if setUp() fails somewhere
in the chain, calls tearDown() for the class whose setUp()
is successfully called. (Be care, you shouldn't call
parent's setUp() or tearDown() directly)


// mockup

import unittest

class TestCase2(unittest.TestCase):
def setUp(self):
klasses = []
try:
for klass in reversed(self.__class__.__mro__):
func = getattr(klass, setUp2, None)
if func is not None:
func(self)
klasses.append(klass)
except:
for klass in reversed(klasses):
func = getattr(klass, tearDown2, None)
if func is not None:
func(self)
raise
def tearDown(self):
for klass in self.__class__.__mro__:
func = getattr(klass, tearDown2, None)
if func is not None:
func(self)

class A(TestCase2):
def setUp2(self):
print(A#setUp2)
def tearDown2(self):
print(A#tearDown2)

class B(A):
def setUp2(self):
print(B#setUp2)
raise RuntimeError(B#setUp2 failed)
def tearDown2(self):
print(B#tearDown2)
def test(self):
pass

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


// result

A#setUp2
B#setUp2
A#tearDown2
(snip)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9868
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com