[Patches] [ python-Patches-736962 ] Port tests to unittest (Part 2)

SourceForge.net noreply at sourceforge.net
Wed Sep 22 20:36:28 CEST 2004


Patches item #736962, was opened at 2003-05-13 12:45
Message generated for change (Comment added) made by doerwalter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=736962&group_id=5470

Category: Tests
Group: None
Status: Open
Resolution: Accepted
Priority: 5
Submitted By: Walter Dörwald (doerwalter)
>Assigned to: Johannes Gijsbers (jlgijsbers)
Summary: Port tests to unittest (Part 2)

Initial Comment:
Here are the next test scripts ported to PyUnit:
test_winsound and test_array. For test_array many
additional tests have been added (code coverage is at 91%)

----------------------------------------------------------------------

>Comment By: Walter Dörwald (doerwalter)
Date: 2004-09-22 20:36

Message:
Logged In: YES 
user_id=89016

test_unpack_doctest.py looks good. Please check it in (as 
test_unpack.py)

----------------------------------------------------------------------

Comment By: Johannes Gijsbers (jlgijsbers)
Date: 2004-09-08 17:37

Message:
Logged In: YES 
user_id=469548

Yeah, bug #1023798 reported that and Brett fixed it.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2004-09-07 22:34

Message:
Logged In: YES 
user_id=89016

I'm getting the following error from the new test__locale:
test test__locale failed -- Traceback (most recent call last):
  File "/home/walter/Achtung/Python-codec-
small/dist/src/Lib/test/test__locale.py", line 37, in 
test_lc_numeric
    "%r != %r (%s); "
  File "/home/walter/Achtung/Python-codec-
small/dist/src/Lib/locale.py", line 363, in getlocale
    return _parse_localename(localename)
  File "/home/walter/Achtung/Python-codec-
small/dist/src/Lib/locale.py", line 278, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: lv_LV

BTW, could someone have a look at Johannes' test_doctest 
and test_inspect patches?

----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2004-09-07 04:32

Message:
Logged In: YES 
user_id=357491

OK, test__locale has been checked in.

----------------------------------------------------------------------

Comment By: Johannes Gijsbers (jlgijsbers)
Date: 2004-08-30 13:00

Message:
Logged In: YES 
user_id=469548

Brett: that's just one of the drawbacks of doing data-driven
testing with unittest. I don't think it's terribly
important, so the test is OK to me.

----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2004-08-27 05:44

Message:
Logged In: YES 
user_id=357491

Just attached a new version of test__locale.  Since it is so small of a file 
and the change so drastic I just uploaded the whole file.

Only drawback is before the test kept testing all locales when there was 
a failure while my implementation stops at the first failure discovered.  
Don't know if it is important to test all locales.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-08-24 18:59

Message:
Logged In: YES 
user_id=80475

Walter, I'm afraid I don't have time for these right now.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2004-08-20 18:39

Message:
Logged In: YES 
user_id=89016

Raymond, can you take a look at the patches?

----------------------------------------------------------------------

Comment By: Johannes Gijsbers (jlgijsbers)
Date: 2004-08-20 17:06

Message:
Logged In: YES 
user_id=469548

Another one: ported test_inspect to unittest and moved out
the inspect fodder out into two modules instead of using the
ugly imp.load_source and TESTFN. I also did a bit of
rearrangement so that the TestCase classes mostly match the
sections in the library docs.

I used a separate module (inspect_fodder2)  and class for
the decorators tests. Those are kind of small now, but I'll
check in http://python.org/sf/1011890 after this port and
let it grow without having to update test_getfunctions().

----------------------------------------------------------------------

Comment By: Johannes Gijsbers (jlgijsbers)
Date: 2004-08-19 17:14

Message:
Logged In: YES 
user_id=469548

Hum yes, that was me trying out how doctest fails. The
expected outcome should have been True. Can you try the
corrected version?

Test_zipfile has been checked in as rev 1.11.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2004-08-18 21:29

Message:
Logged In: YES 
user_id=89016

doctest tests should be OK. The error tests in test_unpack 
can be done with PyUnit too, you either use

self.assertRaises(ValueError, eval, "a,b = Seq()")

or

try:
   a,b = Seq()
except ValueError:
   pass
else:
   self.fail("failed")

test_zipfile_unittest.py looks OK, but should of course be 
named test_zipfile.py when you check it in.

test_unpack_doctest.py gives me:
**********************************************
************************
Failure in example: a == 4 and b == 5 and c == 6
from line #14 of test.test_unpack_doctest.doctests 
in /home/walter/Achtung/Python-
test/dist/src/Lib/test/test_unpack_doctest.pyc
Expected: False
Got: True
**********************************************
************************
1 items had failures:
   1 of  28 in test.test_unpack_doctest.doctests
***Test Failed*** 1 failures.
Traceback (most recent call last):
  File "Lib/test/test_unpack_doctest.py", line 133, in ?
    test_main(verbose=True)
  File "Lib/test/test_unpack_doctest.py", line 130, in test_main
    test_support.run_doctest(test_unpack_doctest, verbose)
  File "/home/walter/Achtung/Python-
test/dist/src/Lib/test/test_support.py", line 318, in 
run_doctest
    raise TestFailed("%d of %d doctests failed" % (f, t))
test.test_support.TestFailed: 1 of 28 doctests failed

----------------------------------------------------------------------

Comment By: Johannes Gijsbers (jlgijsbers)
Date: 2004-08-18 15:23

Message:
Logged In: YES 
user_id=469548

Is there any problem with porting test scripts to doctest
instead of unittest? doctest is just perfect for test_unpack
(doctest version attached).

I've also ported test_zipfile to unittest (attached as well).

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2004-05-31 18:31

Message:
Logged In: YES 
user_id=89016

OK, checked in as:
Lib/test/mapping_tests.py 1.1
Lib/test/test_os.py 1.22
Lib/test/test_shelve.py 1.7
Lib/test/test_types.py 1.60
Lib/test/test_userdict.py 1.19
Lib/test/test_weakref.py 1.39

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-05-29 01:02

Message:
Logged In: YES 
user_id=80475

Looks good.


----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2004-05-28 22:59

Message:
Logged In: YES 
user_id=89016

OK, I've updated the docstring for dict.update() 
(Object/dictobject.c 2.160)

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2004-05-27 21:04

Message:
Logged In: YES 
user_id=89016

dict_diff.txt is a patch that tries to share tests between 
test_dict, test_userdict, test_os, test_shelve and 
test_weakref.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2004-05-25 22:29

Message:
Logged In: YES 
user_id=31435

Don't really care myself.  Would be nice if the docstring for 
dict.update() matched the new realities, though <wink>.

BTW, there is a reliable and conventional way to detect 
whether the 'dict' argument was passed to UserDict.update:  
use a unique marker object instead of the universally visible 
None.  Like

_marker = object()

at module level, and

    ...(self, dict=_marker, ...)

in the method defn.  That can't be fooled without deliberate 
intent to deceive.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-05-25 22:21

Message:
Logged In: YES 
user_id=80475

IMO, it is fine as is.  I would be suprised if some code
were relying on UserDict.update(None) raising an exception.
 This sort of thing also comes up also in places like the
string and random modules whereever a function or method
with an optional argument gets wrapped by another function.
 The only way around this is to use *args and then you break
code that used the unfortunately named "dict" argument as a
keyword.



----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2004-05-25 21:32

Message:
Logged In: YES 
user_id=89016

Merging test_dict and test_userdict revealed a difference
between dict and UserDict.UserDict:

>>> import UserDict
>>> d = UserDict.UserDict()
>>> d.update(None)
>>> d
{}
>>> d = {}
>>> d.update(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: iteration over non-sequence

Should we do anything about this?

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-05-20 18:03

Message:
Logged In: YES 
user_id=80475

test_dict is fine.

Consider beefing up the tests for update().  As of Py2.4, it
now takes all the same argument possibilites as dict():
   
     d.update(a=1, b=2)
     d.update([('a', 1), ('b', 2)])

Also, try to link in:
       from test_userdict import TestMappingProtocol

This was supposed to provide tests common to all mappings.
   

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2004-04-03 13:06

Message:
Logged In: YES 
user_id=89016

The attached test_dict.py moves the dict tests from 
test_types.py to a new PyUnit test script. Code coverage for 
dictobject.c is at 90.76% (up from 89.51%)

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2004-03-15 13:17

Message:
Logged In: YES 
user_id=89016

Checked in as:
Lib/test/output/test_binascii delete
Lib/test/test_binascii.py 1.17

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-03-13 21:26

Message:
Logged In: YES 
user_id=80475

Okay, this one is fine.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-12-19 00:49

Message:
Logged In: YES 
user_id=89016

Here's the next one: test_binascii.py. Code coverage in
binascii.c is at 92% (could be improved by enhancing
test_binhex.py).

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-12-13 23:46

Message:
Logged In: YES 
user_id=33168

Looked good to me, test_future_pyunit.diff checked in as:
 * Lib/test/badsyntax_future3.py 1.2
 * Lib/test/badsyntax_future4.py 1.2
 * Lib/test/badsyntax_future5.py 1.2
 * Lib/test/badsyntax_future6.py 1.2
 * Lib/test/badsyntax_future7.py 1.2
 * Lib/test/badsyntax_future8.py 1.1
 * Lib/test/badsyntax_future9.py 1.1
 * Lib/test/test_future.py 1.7
 * Lib/test/test_future1.py 1.3
 * Lib/test/test_future2.py 1.2
 * Lib/test/output/test_future 1.4

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-12-13 22:47

Message:
Logged In: YES 
user_id=33168

Walter, I didn't get a mail from SF either.  After you do a
cvs add, you need to use -N to cvs diff.  For example, cvs
diff -N new_file_added_to_cvs_but_not_committed.  If you
look carefully, you can see this in the patch on the diff
line for each file.  I'll take a look at the patch.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-12-13 21:18

Message:
Logged In: YES 
user_id=89016

Here is a version of test_future ported to PyUnit
(test_future_pyunit.diff). If this makes sense to you Neal,
please check it in.

(BTW, how did you convince CVS to include
badsyntax_future8.py and badsyntax_future9.py in the diff?
Doing a &quot;cvs add&quot; only results in &quot;
Lib/test/badsyntax_future8.py is a new entry, no comparison
available&quot;)

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-12-11 13:36

Message:
Logged In: YES 
user_id=89016

md5/weakref patch checked in as:
Lib/test/test_weakref.py 1.33
Lib/test/test_md5.py 1.5
Lib/test/output/test_md5 remove


----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-12-11 07:05

Message:
Logged In: YES 
user_id=33168

Improve coverage for test_future too.  I'm not sure if test
future can be ported to PyUnit.

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-12-11 06:52

Message:
Logged In: YES 
user_id=33168

Attached are two tests (in one file, I'm being lazy, sorry)
to improve test coverage for md5c.c and _weakref.c. 
test_md5 was ported to unittest, weakref, just adds two
little tests to get coverage up to 100%.  If you like, just
go ahead and check in.  You will need to remove
Lib/test/output/test_md5

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-12-08 12:42

Message:
Logged In: YES 
user_id=89016

Checked in as:
Lib/test/list_tests.py 1.1
Lib/test/seq_tests.py 1.1
Lib/test/test_list.py 1.1
Lib/test/test_tuple.py 1.1
Lib/test/test_types.py 1.56
Lib/test/test_userlist.py 1.11
Lib/test/output/test_types 1.3

Next will be test_binascii.py before I continue with
test_types.py.


----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-12-08 00:49

Message:
Logged In: YES 
user_id=80475

Looks good.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-11-27 20:48

Message:
Logged In: YES 
user_id=89016

Here the first part of the test_types port: list and tuple
tests have been moved to their own scripts: test_tuple.py
and test_list.py. Common tests for tuple, list and UserList
are shared (in seq_test.py and list_test.py)

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-09-02 03:53

Message:
Logged In: YES 
user_id=80475

Applied as:
   Lib/test/test_slice.py 1.5.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-09-01 01:52

Message:
Logged In: YES 
user_id=80475

Looks good.
I added a couple of minor tests.
Revised patch attached.
Okay to apply.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-08-31 21:49

Message:
Logged In: YES 
user_id=89016

Thanks! Here's another one: test_slice.py

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-08-31 01:04

Message:
Logged In: YES 
user_id=80475

Done.

See:
Lib/test/test_longexp.py 1.9; previous revision: 1.8
Lib/test/test_pep263.py 1.3; previous revision: 1.2
Lib/test/test_sets.py 1.27; previous revision: 1.26
Lib/test/test_structseq.py 1.5; previous revision: 1.4
Lib/test/output/test_longexp delete; previous revision: 1.3

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-08-30 19:10

Message:
Logged In: YES 
user_id=80475

Will do!

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-08-30 19:06

Message:
Logged In: YES 
user_id=89016

Here's test_structse.py converted with a few additional
tests. If all three scripts are OK, could you check them in
Raymond, as I'll be on vacation for three weeks?

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-08-09 17:47

Message:
Logged In: YES 
user_id=89016

Here are two simple ones: test_pep263 and test_longexp. I
can't think of any additional tests to add.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-23 15:38

Message:
Logged In: YES 
user_id=80475

Fixed Walter's review comments and
committed as Lib/test/test_compile.py 1.19

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-06-23 13:49

Message:
Logged In: YES 
user_id=89016

Are you sure, that the code path is the same in the new
test_argument_handling() as in the old test? I.e. is
&quot;eval('lambda a,a: 0')&quot; the same as &quot;exec 'def f(a, a): pass'&quot;?

The print statement in test_float_literals should be changed
to a comment.

Should the imports in test_unary_minus() be moved to the
start of the script?

Otherwise the test looks (and runs) OK.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-20 21:26

Message:
Logged In: YES 
user_id=80475

Here's one for you:

test_compile.py is ready.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-06-19 11:46

Message:
Logged In: YES 
user_id=89016

Maybe test_types.py should be split into several scripts:
test_dict, test_tuple, test_list, test_int, test_long etc.
Some of them already exist (like test_long), some don't. The
constructor tests from test_builtin should probably be moved
to the new test scripts as well. Furthermore we should try
to share as much testing functionality as possible (e.g.
between test_int and test_long, or between test_list and
test_userlist)

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-18 21:48

Message:
Logged In: YES 
user_id=80475

Great!
Can I suggest that test_types.py be next.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-06-18 16:27

Message:
Logged In: YES 
user_id=89016

Checked in as:
Lib/test/test_builtin.py 1.21
Lib/test/test_complex.py 1.10

(I've moved the constructor tests from test_builtin to
test_complex)

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-18 01:49

Message:
Logged In: YES 
user_id=80475

I added a few tests.  If they are fine with you, go ahead and 
commit.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-06-17 23:36

Message:
Logged In: YES 
user_id=89016

Here's the next one: text_complex.py.

There one test that's currently commented out, because it
crashes Python on Alpha (see http://www.python.org/sf/756093.

The old test scripts states that tests for the constructor
are in test_builtin, but I've added many tests to this
script, so this is no longer true. We could move the tests
to test_builtin, but IMHO that doesn't make sense, we'd
better move the rest of the constructor tests from
test_builtin to test_complex.

I'd like to have a version of assertAlmostEqual() in
unittest.py that can cope with complex numbers, but this
would have to be coordinated with the standalone version of
PyUnit (and it would probably have to wait until the 2.4
cycle starts) (I noticed that there is no assertAlmostEqual
in the code on pyunit.sf.net anyway.)

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-06-17 14:06

Message:
Logged In: YES 
user_id=89016

I'd like to keep this patch open, as it is an ongoing task
(the next test scripts to be converted will be test_complex
and then maybe test_marshal)

----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2003-06-16 23:55

Message:
Logged In: YES 
user_id=357491

OK, all tests pass cleanly.  Applied as revision 1.6.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-06-16 21:51

Message:
Logged In: YES 
user_id=89016

The joys of unittesting: Breaking code to make it better! ;)

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-16 21:41

Message:
Logged In: YES 
user_id=80475

Okay, it runs fine here.  Once Brett confirms that it runs on 
the Mac, go ahead and load it.

P.S. Your improved test_mimetools.py helped detect a latent 
error in mimetools.py when it was run under Windows.  Tim 
made the fix this weekend.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-06-16 21:33

Message:
Logged In: YES 
user_id=89016

Strange, I didn't get this failure here, but I got it on my
laptop at home. I've removed the comparison with the
getatime() value from test_time(). I hope this fixes it.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-16 21:09

Message:
Logged In: YES 
user_id=80475


Walter, there is one failure left:
======================================
================================
FAIL: test_time (__main__.PosixPathTest)
-------------------------------------------------------------------
---
Traceback (most recent call last):
  File &quot;test_posixpath.py&quot;, line 125, in test_time
    self.assert_(
  File &quot;C:\PY23\lib\unittest.py&quot;, line 268, in failUnless
    if not expr: raise self.failureException, msg
AssertionError




Brett, after Walter revises the patch, just load the patch and 
make sure the test runs on the Mac.  Between the three of 
us, we can validate the suite on three different platforms.  
Cheers.



----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2003-06-16 20:20

Message:
Logged In: YES 
user_id=357491

Just wanting to work me like a dog, huh, Raymond?  =)

And to clarify for my and Walter's benefit, when you say guards, 
you mean that the tests don't crap out and say they failed on 
Windows, right?  I thought posixpath was not meant to work 
under Windows.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-06-16 20:09

Message:
Logged In: YES 
user_id=89016

I didn't realize that test_posixpath must work on Windows
too. Here's a new version.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-16 18:04

Message:
Logged In: YES 
user_id=80475

The previous comment applied to another patch.
It should have said:

Assigning to Brett to make sure the patch runs on the Mac.  
Don't accept this one until it has guards that allow the tests 
to run on Windows.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-16 17:59

Message:
Logged In: YES 
user_id=80475

Assigning to Brett to give experience doing a detail review on 
this type of change.

* examine every line of the diff and consider whether there is 
any semantic change (exceptions raised, etc).

* apply the diff and run the test suite

* in the interactive mode, call-up each function and make 
sure it behaves as expected (this is necessary because the 
test coverage is very low).

* verify that the whitespace has been cleaned up.

* look for missing changes (such as use of +=)

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-16 17:44

Message:
Logged In: YES 
user_id=80475

The test file now has dependencies that do not apply to 
windows.  The failure messages are attached.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-06-16 14:48

Message:
Logged In: YES 
user_id=89016

Here's the next one: test_posixpath.py with many additional
tests.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-05-22 19:33

Message:
Logged In: YES 
user_id=89016

Checked in as:
Lib/test/output/test_mimetools delete
Lib/test/test_mimetools.py 1.4

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-22 18:18

Message:
Logged In: YES 
user_id=80475

test_mimetools.py is ready.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-05-22 17:05

Message:
Logged In: YES 
user_id=89016

I've attached a third version of test_mimetools.py that does
some checks for the mimetools.Message class.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-21 15:04

Message:
Logged In: YES 
user_id=80475

Attaching a slightly modified test_mimetools which covers 
more encodings and has a stronger set test.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-05-19 01:46

Message:
Logged In: YES 
user_id=89016

Agreed, this is too much magic for too little gain.

Back to business: Here is test_mimetools ported to PyUnit.
Tests for mimetools.Message are still missing. If you can
think of any tests please add them.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-18 05:18

Message:
Logged In: YES 
user_id=80475

Get the module with sys.modules:
  tests = test_support.findtestclasses(sys.modules
[__name__])
  test_support.unittest(*tests)

Yeah, the inheritance thing is a problem.  I was trying to 
avoid having to modify unittest.TestCase to have a 
metaclass.  The control of the module is kept in a 
separate SF project and one of its goals is to be backward 
compatible through 1.5.2 (meaning no metaclasses).

A possible workaround is to define a modified testcase in 
test_support so that people don't import unittest directly 
anymore:

test_support.py
-------------------------
import unittest
class SmartTestCase(unittest.TestCase):
    __metaclass__ = autotracktests
    pass

test_sets.py
------------------
class TestBasicOps(test_support.SmartTestCase):
    run = False
. . .
class TestBasicOpsEmpty(TestBasicOps):
    def setUp(self):
    . . .

Still, this is starting to seem a bit magical and tricky.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-05-18 04:52

Message:
Logged In: YES 
user_id=89016

But how do I pass the module object from inside the module?
And skipping abstract classes seems to be more work in this
version: If skipping is done via a class attribute, derived
classes have to explicitely reset this flag because of
interitance.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-18 03:59

Message:
Logged In: YES 
user_id=80475

Good call.

Instead of using metaclasses, perhaps add a module 
introspector function to test_support:

def findtestclasses(mod):
    tests = []
    for elem in dir(mod):
        member = getattr(mod, elem)
        if type(member) != type: continue
        if issubclass(member, unittest.TestCase):
            tests.append(member)
    return tests

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-05-18 03:45

Message:
Logged In: YES 
user_id=89016

But this can be solved with a special non-inheritable class
attribute:

class BaseTest(unittest.TestCase):
    run = False

Then the metaclass can do the following:
def __new__(cls, name, bases, dict):
    if &quot;run&quot; not in dict:
       dict[&quot;run&quot;]  = True
    cls = type.__new__(cls, name, bases, dict)
    if cls.run:
        tests.append(cls)
    return cls


----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-18 03:04

Message:
Logged In: YES 
user_id=80475

I don't think metaclasses or module introspection would 
help whenever there are classes that derive from TestCase 
but are not meant to be run directly (their subclasses have 
the setup/teardown/or class data).  test_sets.py has 
examples of that kind of thing.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-05-18 02:50

Message:
Logged In: YES 
user_id=89016

Checked in as:
Lib/test/test_array.py 1.20
Lib/test/test_winsound.py 1.5
Lib/test/output/test_winsound delete

&gt; The approach of using tests.append() is elegant and
&gt; makes it easier to verify that no tests are being omitted.

The most elegant approach would probably be a metaclass that
collects all TestCase subclasses that get defined. Classes
that only serve as a base class could be skipped by
specifying a certain class attribute.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-18 01:35

Message:
Logged In: YES 
user_id=80475

The approach of using tests.append() is elegant and 
makes it easier to verify that no tests are being omitted.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=736962&group_id=5470


More information about the Patches mailing list