Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Attributes
test.test_weakref.WeakValueDictionaryTestCase Class Reference
Inheritance diagram for test.test_weakref.WeakValueDictionaryTestCase:
Inheritance graph
[legend]
Collaboration diagram for test.test_weakref.WeakValueDictionaryTestCase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_read
def test_write
def test_constructor
def test_bool
def test_keys
def test_values
def test_items
def test_len
def test_getitem
def test_update
def test_get
def test_setdefault
def test_popitem
def test_pop

Public Attributes

 reference
 other
 inmapping
 d
 i

Static Public Attributes

 type2test = weakref.WeakValueDictionary

Private Member Functions

def _reference

Static Private Attributes

dictionary __ref = {"key1":Object(1), "key2":Object(2), "key3":Object(3)}

Detailed Description

Check that WeakValueDictionary conforms to the mapping protocol

Definition at line 1233 of file test_weakref.py.


Member Function Documentation

Return a dictionary of values which are invariant by storage
in the object under test.

Reimplemented from test.mapping_tests.BasicTestMappingProtocol.

Definition at line 1237 of file test_weakref.py.

01237 
01238     def _reference(self):
01239         return self.__ref.copy()

Reimplemented in test.mapping_tests.TestMappingProtocol.

Definition at line 135 of file mapping_tests.py.

00135 
00136     def test_bool(self):
00137         self.assertTrue(not self._empty_mapping())
00138         self.assertTrue(self.reference)
00139         self.assertTrue(bool(self._empty_mapping()) is False)
00140         self.assertTrue(bool(self.reference) is True)

Here is the call graph for this function:

Reimplemented in test.mapping_tests.TestMappingProtocol.

Definition at line 132 of file mapping_tests.py.

00132 
00133     def test_constructor(self):
00134         self.assertEqual(self._empty_mapping(), self._empty_mapping())

Here is the call graph for this function:

Reimplemented in test.mapping_tests.TestMappingProtocol.

Definition at line 269 of file mapping_tests.py.

00269 
00270     def test_get(self):
00271         d = self._empty_mapping()
00272         self.assertTrue(d.get(list(self.other.keys())[0]) is None)
00273         self.assertEqual(d.get(list(self.other.keys())[0], 3), 3)
00274         d = self.reference
00275         self.assertTrue(d.get(list(self.other.keys())[0]) is None)
00276         self.assertEqual(d.get(list(self.other.keys())[0], 3), 3)
00277         self.assertEqual(d.get(list(self.inmapping.keys())[0]),
00278                          list(self.inmapping.values())[0])
00279         self.assertEqual(d.get(list(self.inmapping.keys())[0], 3),
00280                          list(self.inmapping.values())[0])
00281         self.assertRaises(TypeError, d.get)
00282         self.assertRaises(TypeError, d.get, None, None, None)

Here is the call graph for this function:

Reimplemented in test.mapping_tests.TestHashMappingProtocol, and test.mapping_tests.TestMappingProtocol.

Definition at line 165 of file mapping_tests.py.

00165 
00166     def test_getitem(self):
00167         d = self.reference
00168         self.assertEqual(d[list(self.inmapping.keys())[0]],
00169                          list(self.inmapping.values())[0])
00170 
00171         self.assertRaises(TypeError, d.__getitem__)

Here is the call graph for this function:

Reimplemented in test.test_os.EnvironTests, and test.mapping_tests.TestMappingProtocol.

Definition at line 155 of file mapping_tests.py.

00155 
00156     def test_items(self):
00157         d = self._empty_mapping()
00158         self.assertEqual(list(d.items()), [])
00159 
00160         self.assertRaises(TypeError, d.items, None)

Here is the call graph for this function:

Reimplemented in test.mapping_tests.TestMappingProtocol.

Definition at line 141 of file mapping_tests.py.

00141 
00142     def test_keys(self):
00143         d = self._empty_mapping()
00144         self.assertEqual(list(d.keys()), [])
00145         d = self.reference
00146         self.assertIn(list(self.inmapping.keys())[0], d.keys())
00147         self.assertNotIn(list(self.other.keys())[0], d.keys())
00148         self.assertRaises(TypeError, d.keys, None)

Here is the call graph for this function:

Reimplemented in test.mapping_tests.TestMappingProtocol.

Definition at line 161 of file mapping_tests.py.

00161 
00162     def test_len(self):
00163         d = self._empty_mapping()
00164         self.assertEqual(len(d), 0)

Here is the call graph for this function:

Reimplemented in test.mapping_tests.TestHashMappingProtocol, and test.mapping_tests.TestMappingProtocol.

Definition at line 292 of file mapping_tests.py.

00292 
00293     def test_pop(self):
00294         d = self._empty_mapping()
00295         k, v = list(self.inmapping.items())[0]
00296         d[k] = v
00297         self.assertRaises(KeyError, d.pop, list(self.other.keys())[0])
00298 
00299         self.assertEqual(d.pop(k), v)
00300         self.assertEqual(len(d), 0)
00301 
00302         self.assertRaises(KeyError, d.pop, k)
00303 

Here is the call graph for this function:

Reimplemented in test.test_collections.SubclassMappingTests, test.test_collections.GeneralMappingTests, and test.mapping_tests.TestMappingProtocol.

Definition at line 287 of file mapping_tests.py.

00287 
00288     def test_popitem(self):
00289         d = self._empty_mapping()
00290         self.assertRaises(KeyError, d.popitem)
00291         self.assertRaises(TypeError, d.popitem, 42)

Here is the call graph for this function:

Definition at line 42 of file mapping_tests.py.

00042 
00043     def test_read(self):
00044         # Test for read only operations on mapping
00045         p = self._empty_mapping()
00046         p1 = dict(p) #workaround for singleton objects
00047         d = self._full_mapping(self.reference)
00048         if d is p:
00049             p = p1
00050         #Indexing
00051         for key, value in self.reference.items():
00052             self.assertEqual(d[key], value)
00053         knownkey = list(self.other.keys())[0]
00054         self.assertRaises(KeyError, lambda:d[knownkey])
00055         #len
00056         self.assertEqual(len(p), 0)
00057         self.assertEqual(len(d), len(self.reference))
00058         #__contains__
00059         for k in self.reference:
00060             self.assertIn(k, d)
00061         for k in self.other:
00062             self.assertNotIn(k, d)
00063         #cmp
00064         self.assertEqual(p, p)
00065         self.assertEqual(d, d)
00066         self.assertNotEqual(p, d)
00067         self.assertNotEqual(d, p)
00068         #__non__zero__
00069         if p: self.fail("Empty mapping must compare to False")
00070         if not d: self.fail("Full mapping must compare to True")
00071         # keys(), items(), iterkeys() ...
00072         def check_iterandlist(iter, lst, ref):
00073             self.assertTrue(hasattr(iter, '__next__'))
00074             self.assertTrue(hasattr(iter, '__iter__'))
00075             x = list(iter)
00076             self.assertTrue(set(x)==set(lst)==set(ref))
00077         check_iterandlist(iter(d.keys()), list(d.keys()),
00078                           self.reference.keys())
00079         check_iterandlist(iter(d), list(d.keys()), self.reference.keys())
00080         check_iterandlist(iter(d.values()), list(d.values()),
00081                           self.reference.values())
00082         check_iterandlist(iter(d.items()), list(d.items()),
00083                           self.reference.items())
00084         #get
00085         key, value = next(iter(d.items()))
00086         knownkey, knownvalue = next(iter(self.other.items()))
00087         self.assertEqual(d.get(key, knownvalue), value)
00088         self.assertEqual(d.get(knownkey, knownvalue), knownvalue)
00089         self.assertNotIn(knownkey, d)

Here is the call graph for this function:

Reimplemented in test.mapping_tests.TestHashMappingProtocol, and test.mapping_tests.TestMappingProtocol.

Definition at line 283 of file mapping_tests.py.

00283 
00284     def test_setdefault(self):
00285         d = self._empty_mapping()
00286         self.assertRaises(TypeError, d.setdefault)

Here is the call graph for this function:

Reimplemented in test.mapping_tests.TestMappingProtocol.

Definition at line 172 of file mapping_tests.py.

00172 
00173     def test_update(self):
00174         # mapping argument
00175         d = self._empty_mapping()
00176         d.update(self.other)
00177         self.assertEqual(list(d.items()), list(self.other.items()))
00178 
00179         # No argument
00180         d = self._empty_mapping()
00181         d.update()
00182         self.assertEqual(d, self._empty_mapping())
00183 
00184         # item sequence
00185         d = self._empty_mapping()
00186         d.update(self.other.items())
00187         self.assertEqual(list(d.items()), list(self.other.items()))
00188 
00189         # Iterator
00190         d = self._empty_mapping()
00191         d.update(self.other.items())
00192         self.assertEqual(list(d.items()), list(self.other.items()))
00193 
00194         # FIXME: Doesn't work with UserDict
00195         # self.assertRaises((TypeError, AttributeError), d.update, None)
00196         self.assertRaises((TypeError, AttributeError), d.update, 42)
00197 
00198         outerself = self
00199         class SimpleUserDict:
00200             def __init__(self):
00201                 self.d = outerself.reference
00202             def keys(self):
00203                 return self.d.keys()
00204             def __getitem__(self, i):
00205                 return self.d[i]
00206         d.clear()
00207         d.update(SimpleUserDict())
00208         i1 = sorted(d.items())
00209         i2 = sorted(self.reference.items())
00210         self.assertEqual(i1, i2)
00211 
00212         class Exc(Exception): pass
00213 
00214         d = self._empty_mapping()
00215         class FailingUserDict:
00216             def keys(self):
00217                 raise Exc
00218         self.assertRaises(Exc, d.update, FailingUserDict())
00219 
00220         d.clear()
00221 
00222         class FailingUserDict:
00223             def keys(self):
00224                 class BogonIter:
00225                     def __init__(self):
00226                         self.i = 1
00227                     def __iter__(self):
00228                         return self
00229                     def __next__(self):
00230                         if self.i:
00231                             self.i = 0
00232                             return 'a'
00233                         raise Exc
00234                 return BogonIter()
00235             def __getitem__(self, key):
00236                 return key
00237         self.assertRaises(Exc, d.update, FailingUserDict())
00238 
00239         class FailingUserDict:
00240             def keys(self):
00241                 class BogonIter:
00242                     def __init__(self):
00243                         self.i = ord('a')
00244                     def __iter__(self):
00245                         return self
00246                     def __next__(self):
00247                         if self.i <= ord('z'):
00248                             rtn = chr(self.i)
00249                             self.i += 1
00250                             return rtn
00251                         raise StopIteration
00252                 return BogonIter()
00253             def __getitem__(self, key):
00254                 raise Exc
00255         self.assertRaises(Exc, d.update, FailingUserDict())
00256 
00257         d = self._empty_mapping()
00258         class badseq(object):
00259             def __iter__(self):
00260                 return self
00261             def __next__(self):
00262                 raise Exc()
00263 
00264         self.assertRaises(Exc, d.update, badseq())
00265 
00266         self.assertRaises(ValueError, d.update, [(1, 2, 3)])

Here is the call graph for this function:

Reimplemented in test.mapping_tests.TestMappingProtocol.

Definition at line 149 of file mapping_tests.py.

00149 
00150     def test_values(self):
00151         d = self._empty_mapping()
00152         self.assertEqual(list(d.values()), [])
00153 
00154         self.assertRaises(TypeError, d.values, None)

Here is the call graph for this function:

Definition at line 90 of file mapping_tests.py.

00090 
00091     def test_write(self):
00092         # Test for write operations on mapping
00093         p = self._empty_mapping()
00094         #Indexing
00095         for key, value in self.reference.items():
00096             p[key] = value
00097             self.assertEqual(p[key], value)
00098         for key in self.reference.keys():
00099             del p[key]
00100             self.assertRaises(KeyError, lambda:p[key])
00101         p = self._empty_mapping()
00102         #update
00103         p.update(self.reference)
00104         self.assertEqual(dict(p), self.reference)
00105         items = list(p.items())
00106         p = self._empty_mapping()
00107         p.update(items)
00108         self.assertEqual(dict(p), self.reference)
00109         d = self._full_mapping(self.reference)
00110         #setdefault
00111         key, value = next(iter(d.items()))
00112         knownkey, knownvalue = next(iter(self.other.items()))
00113         self.assertEqual(d.setdefault(key, knownvalue), value)
00114         self.assertEqual(d[key], value)
00115         self.assertEqual(d.setdefault(knownkey, knownvalue), knownvalue)
00116         self.assertEqual(d[knownkey], knownvalue)
00117         #pop
00118         self.assertEqual(d.pop(knownkey), knownvalue)
00119         self.assertNotIn(knownkey, d)
00120         self.assertRaises(KeyError, d.pop, knownkey)
00121         default = 909
00122         d[knownkey] = knownvalue
00123         self.assertEqual(d.pop(knownkey, default), knownvalue)
00124         self.assertNotIn(knownkey, d)
00125         self.assertEqual(d.pop(knownkey, default), default)
00126         #popitem
00127         key, value = d.popitem()
00128         self.assertNotIn(key, d)
00129         self.assertEqual(value, self.reference[key])
00130         p=self._empty_mapping()
00131         self.assertRaises(KeyError, p.popitem)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

dictionary test.test_weakref.WeakValueDictionaryTestCase.__ref = {"key1":Object(1), "key2":Object(2), "key3":Object(3)} [static, private]

Definition at line 1235 of file test_weakref.py.

Reimplemented in test.mapping_tests.TestMappingProtocol.

Definition at line 200 of file mapping_tests.py.

Definition at line 225 of file mapping_tests.py.

Definition at line 39 of file mapping_tests.py.

Definition at line 35 of file mapping_tests.py.

Definition at line 31 of file mapping_tests.py.

Reimplemented from test.mapping_tests.BasicTestMappingProtocol.

Definition at line 1236 of file test_weakref.py.


The documentation for this class was generated from the following file: