Problem understanding some unit tests in Python distribution

A

André

Hi everyone,

In the hope of perhaps contributing some additional unit tests for
Python (thus contributing back to the community), I dove in the code
and found something that should be simple but that I can not wrap my
head around.

In list_tests.py, one finds
===
from test import test_support, seq_tests

class CommonTest(seq_tests.CommonTest):

def test_init(self):
# Iterable arg is optional
self.assertEqual(self.type2test([]), self.type2test())
# etc.
===

Wanting to figure out what the type2test() method does, I looked in
seq_tests.py and found the following:

===
class CommonTest(unittest.TestCase):
# The type to be tested
type2test = None

def test_constructors(self):
l0 = []
l1 = [0]
l2 = [0, 1]

u = self.type2test()
u0 = self.type2test(l0)
u1 = self.type2test(l1)
u2 = self.type2test(l2)

# etc.
===
No where do I find a definition for the type2test() method - other
than seeing it as a class variable defined to be None by default. I
looked in unittest.TestCase and did not see it anywhere.

Am I missing something obvious? I would appreciate if someone could
point me in the right direction.

Cheers,

André
 
P

Peter Otten

André said:
Hi everyone,

In the hope of perhaps contributing some additional unit tests for
Python (thus contributing back to the community), I dove in the code
and found something that should be simple but that I can not wrap my
head around.

In list_tests.py, one finds
===
from test import test_support, seq_tests

class CommonTest(seq_tests.CommonTest):

def test_init(self):
# Iterable arg is optional
self.assertEqual(self.type2test([]), self.type2test())
# etc.
===

Wanting to figure out what the type2test() method does, I looked in
seq_tests.py and found the following:

===
class CommonTest(unittest.TestCase):
# The type to be tested
type2test = None

def test_constructors(self):
l0 = []
l1 = [0]
l2 = [0, 1]

u = self.type2test()
u0 = self.type2test(l0)
u1 = self.type2test(l1)
u2 = self.type2test(l2)

# etc.
===
No where do I find a definition for the type2test() method - other
than seeing it as a class variable defined to be None by default. I
looked in unittest.TestCase and did not see it anywhere.

Am I missing something obvious? I would appreciate if someone could
point me in the right direction.

Use grep ;)

CommonTest is not run standalone, it is used as a(n abstract) base class for
several other tests that override type2test.

E. g. in Lib/test/list_tests.py:

from test import test_support, seq_tests

class CommonTest(seq_tests.CommonTest):
....

And then in Lib/test/test_list.py:

from test import test_support, list_tests

class ListTest(list_tests.CommonTest):
type2test = list
....

Peter
 
A

André

André said:
Hi everyone,
In the hope of perhaps contributing some additional unit tests for
Python (thus contributing back to the community), I dove in the code
and found something that should be simple but that I can not wrap my
head around.
In list_tests.py, one finds
===
from test import test_support, seq_tests
class CommonTest(seq_tests.CommonTest):
    def test_init(self):
        # Iterable arg is optional
        self.assertEqual(self.type2test([]), self.type2test())
# etc.
===
Wanting to figure out what the type2test() method does, I looked in
seq_tests.py and found the following:
===
class CommonTest(unittest.TestCase):
    # The type to be tested
    type2test = None
    def test_constructors(self):
        l0 = []
        l1 = [0]
        l2 = [0, 1]
        u = self.type2test()
        u0 = self.type2test(l0)
        u1 = self.type2test(l1)
        u2 = self.type2test(l2)
# etc.
===
No where do I find a definition for the type2test() method - other
than seeing it as a class variable defined to be None by default.  I
looked in unittest.TestCase and did not see it anywhere.
Am I missing something obvious?  I would appreciate if someone could
point me in the right direction.

Use grep ;)

I sort of did (use a "find all" from within my editor...)
CommonTest is not run standalone, it is used as a(n abstract) base class for
several other tests that override type2test.

E. g. in Lib/test/list_tests.py:

from test import test_support, seq_tests

class CommonTest(seq_tests.CommonTest):
...

And then in Lib/test/test_list.py:

from test import test_support, list_tests

class ListTest(list_tests.CommonTest):
    type2test = list

I can't believe I missed that one.

Thank you very much!

André
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top