[issue15015] Access to non-existing "future" attribute in error path of futures

2012-06-06 Thread Éric Piel

New submission from Éric Piel :

concurrent.futures.Future.set_running_or_notify_cancel() has a reference to 
self.future, although Future has no future attribute. It's probably due to a 
copy/paste error. As it's in an error handling code path, most of the time the 
code is never used. Nevertheless it's worthy to fix it so that the right 
exception happens in case of error. This was detected by pylint.

Attaching a patch that fixes the error.

--
components: Library (Lib)
files: future-fix-attribute.patch
keywords: patch
messages: 162398
nosy: pieleric
priority: normal
severity: normal
status: open
title: Access to non-existing "future" attribute in error path of futures
versions: Python 3.4
Added file: http://bugs.python.org/file25844/future-fix-attribute.patch

___
Python tracker 
<http://bugs.python.org/issue15015>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17519] unittest should not try to run abstract classes

2013-03-22 Thread Éric Piel

New submission from Éric Piel:

Since Python 2.6 there is the notion if abstract class (ABC). It could be 
useful to use it for test cases, but unittest doesn't support it. Typically, 
I'd like to test a bunch of classes which all should behave similarly (at least 
for some cases). So I'd like to have one abstract class containing many test 
cases, and a separate real tests classes which inherit from this abstract class.

Unfortunately, for now unittest tries to instantiate the abstract class, which 
fails. 

Note that I'm not the only one thinking of this, here is a mention of the same 
idea on stack overflow:
http://stackoverflow.com/questions/4566910/abstract-test-case-using-python-unittest

Attached are two small examples of test cases. test_abs.py shows what I think 
is a good usage of ABC, with unittest. It fails to run with this error:
TypeError: Can't instantiate abstract class VirtualTest with abstract methods 
important_num
fake_abc.py is typically what people end up doing for using abstract classes 
with unittests (that's what people used to do before ABC exists). It does work, 
but it's not really beautiful as VirtualTest uses self.assertGreater() and 
self.important_num which are not explicitly part of the class.

My guess is that the following patch to Lib/unittest/loader.py should be enough 
(but it's untested):
diff -r a2128cb22372 Lib/unittest/loader.py
--- a/Lib/unittest/loader.pyThu Mar 21 23:04:45 2013 -0500
+++ b/Lib/unittest/loader.pyFri Mar 22 12:22:46 2013 +0100
@@ -6,6 +6,7 @@
 import traceback
 import types
 import functools
+import inspect
 
 from fnmatch import fnmatch
 
@@ -74,7 +75,8 @@
 tests = []
 for name in dir(module):
 obj = getattr(module, name)
-if isinstance(obj, type) and issubclass(obj, case.TestCase):
+if (isinstance(obj, type) and issubclass(obj, case.TestCase) and
+not inspect.isabstract(test_class)):
 tests.append(self.loadTestsFromTestCase(obj))
 
 load_tests = getattr(module, 'load_tests', None)

--
components: Library (Lib)
files: test_abc.py
messages: 184959
nosy: Éric.Piel
priority: normal
severity: normal
status: open
title: unittest should not try to run abstract classes
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file29544/test_abc.py

___
Python tracker 
<http://bugs.python.org/issue17519>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17519] unittest should not try to run abstract classes

2013-03-22 Thread Éric Piel

Changes by Éric Piel :


Added file: http://bugs.python.org/file29545/fake_abc.py

___
Python tracker 
<http://bugs.python.org/issue17519>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com