Back to index

python3.2  3.2.2
Public Member Functions
test.test_dictviews.DictSetTest Class Reference

List of all members.

Public Member Functions

def test_constructors_not_callable
def test_dict_keys
def test_dict_items
def test_dict_mixed_keys_items
def test_dict_values
def test_dict_repr
def test_keys_set_operations
def test_items_set_operations

Detailed Description

Definition at line 4 of file test_dictviews.py.


Member Function Documentation

Definition at line 6 of file test_dictviews.py.

00006 
00007     def test_constructors_not_callable(self):
00008         kt = type({}.keys())
00009         self.assertRaises(TypeError, kt, {})
00010         self.assertRaises(TypeError, kt)
00011         it = type({}.items())
00012         self.assertRaises(TypeError, it, {})
00013         self.assertRaises(TypeError, it)
00014         vt = type({}.values())
00015         self.assertRaises(TypeError, vt, {})
00016         self.assertRaises(TypeError, vt)

Here is the call graph for this function:

Definition at line 37 of file test_dictviews.py.

00037 
00038     def test_dict_items(self):
00039         d = {1: 10, "a": "ABC"}
00040         items = d.items()
00041         self.assertEqual(len(items), 2)
00042         self.assertEqual(set(items), {(1, 10), ("a", "ABC")})
00043         self.assertEqual(items, {(1, 10), ("a", "ABC")})
00044         self.assertNotEqual(items, {(1, 10), ("a", "ABC"), "junk"})
00045         self.assertNotEqual(items, {(1, 10), ("a", "def")})
00046         self.assertNotEqual(items, {(1, 10)})
00047         self.assertNotEqual(items, 42)
00048         self.assertIn((1, 10), items)
00049         self.assertIn(("a", "ABC"), items)
00050         self.assertNotIn((1, 11), items)
00051         self.assertNotIn(1, items)
00052         self.assertNotIn((), items)
00053         self.assertNotIn((1,), items)
00054         self.assertNotIn((1, 2, 3), items)
00055         self.assertEqual(d.items(), d.items())
00056         e = d.copy()
00057         self.assertEqual(d.items(), e.items())
00058         e["a"] = "def"
00059         self.assertNotEqual(d.items(), e.items())

Here is the call graph for this function:

Definition at line 17 of file test_dictviews.py.

00017 
00018     def test_dict_keys(self):
00019         d = {1: 10, "a": "ABC"}
00020         keys = d.keys()
00021         self.assertEqual(len(keys), 2)
00022         self.assertEqual(set(keys), {1, "a"})
00023         self.assertEqual(keys, {1, "a"})
00024         self.assertNotEqual(keys, {1, "a", "b"})
00025         self.assertNotEqual(keys, {1, "b"})
00026         self.assertNotEqual(keys, {1})
00027         self.assertNotEqual(keys, 42)
00028         self.assertIn(1, keys)
00029         self.assertIn("a", keys)
00030         self.assertNotIn(10, keys)
00031         self.assertNotIn("Z", keys)
00032         self.assertEqual(d.keys(), d.keys())
00033         e = {1: 11, "a": "def"}
00034         self.assertEqual(d.keys(), e.keys())
00035         del e["a"]
00036         self.assertNotEqual(d.keys(), e.keys())

Here is the call graph for this function:

Definition at line 60 of file test_dictviews.py.

00060 
00061     def test_dict_mixed_keys_items(self):
00062         d = {(1, 1): 11, (2, 2): 22}
00063         e = {1: 1, 2: 2}
00064         self.assertEqual(d.keys(), e.items())
00065         self.assertNotEqual(d.items(), e.keys())

Here is the call graph for this function:

Definition at line 72 of file test_dictviews.py.

00072 
00073     def test_dict_repr(self):
00074         d = {1: 10, "a": "ABC"}
00075         self.assertIsInstance(repr(d), str)
00076         r = repr(d.items())
00077         self.assertIsInstance(r, str)
00078         self.assertTrue(r == "dict_items([('a', 'ABC'), (1, 10)])" or
00079                         r == "dict_items([(1, 10), ('a', 'ABC')])")
00080         r = repr(d.keys())
00081         self.assertIsInstance(r, str)
00082         self.assertTrue(r == "dict_keys(['a', 1])" or
00083                         r == "dict_keys([1, 'a'])")
00084         r = repr(d.values())
00085         self.assertIsInstance(r, str)
00086         self.assertTrue(r == "dict_values(['ABC', 10])" or
00087                         r == "dict_values([10, 'ABC'])")

Here is the call graph for this function:

Definition at line 66 of file test_dictviews.py.

00066 
00067     def test_dict_values(self):
00068         d = {1: 10, "a": "ABC"}
00069         values = d.values()
00070         self.assertEqual(set(values), {10, "ABC"})
00071         self.assertEqual(len(values), 2)

Here is the call graph for this function:

Definition at line 133 of file test_dictviews.py.

00133 
00134     def test_items_set_operations(self):
00135         d1 = {'a': 1, 'b': 2}
00136         d2 = {'a': 2, 'b': 2}
00137         d3 = {'d': 4, 'e': 5}
00138         self.assertEqual(
00139             d1.items() & d1.items(), {('a', 1), ('b', 2)})
00140         self.assertEqual(d1.items() & d2.items(), {('b', 2)})
00141         self.assertEqual(d1.items() & d3.items(), set())
00142         self.assertEqual(d1.items() & set(d1.items()),
00143                          {('a', 1), ('b', 2)})
00144         self.assertEqual(d1.items() & set(d2.items()), {('b', 2)})
00145         self.assertEqual(d1.items() & set(d3.items()), set())
00146 
00147         self.assertEqual(d1.items() | d1.items(),
00148                          {('a', 1), ('b', 2)})
00149         self.assertEqual(d1.items() | d2.items(),
00150                          {('a', 1), ('a', 2), ('b', 2)})
00151         self.assertEqual(d1.items() | d3.items(),
00152                          {('a', 1), ('b', 2), ('d', 4), ('e', 5)})
00153         self.assertEqual(d1.items() | set(d1.items()),
00154                          {('a', 1), ('b', 2)})
00155         self.assertEqual(d1.items() | set(d2.items()),
00156                          {('a', 1), ('a', 2), ('b', 2)})
00157         self.assertEqual(d1.items() | set(d3.items()),
00158                          {('a', 1), ('b', 2), ('d', 4), ('e', 5)})
00159 
00160         self.assertEqual(d1.items() ^ d1.items(), set())
00161         self.assertEqual(d1.items() ^ d2.items(),
00162                          {('a', 1), ('a', 2)})
00163         self.assertEqual(d1.items() ^ d3.items(),
00164                          {('a', 1), ('b', 2), ('d', 4), ('e', 5)})
00165 
00166         self.assertFalse(d1.items().isdisjoint(d1.items()))
00167         self.assertFalse(d1.items().isdisjoint(d2.items()))
00168         self.assertFalse(d1.items().isdisjoint(list(d2.items())))
00169         self.assertFalse(d1.items().isdisjoint(set(d2.items())))
00170         self.assertTrue(d1.items().isdisjoint({'x', 'y', 'z'}))
00171         self.assertTrue(d1.items().isdisjoint(['x', 'y', 'z']))
00172         self.assertTrue(d1.items().isdisjoint(set(['x', 'y', 'z'])))
00173         self.assertTrue(d1.items().isdisjoint(set(['x', 'y'])))
00174         self.assertTrue(d1.items().isdisjoint({}))
00175         self.assertTrue(d1.items().isdisjoint(d3.items()))
00176 
00177         de = {}
00178         self.assertTrue(de.items().isdisjoint(set()))
00179         self.assertTrue(de.items().isdisjoint([]))
00180         self.assertTrue(de.items().isdisjoint(de.items()))
00181         self.assertTrue(de.items().isdisjoint([1]))
00182 

Here is the call graph for this function:

Definition at line 88 of file test_dictviews.py.

00088 
00089     def test_keys_set_operations(self):
00090         d1 = {'a': 1, 'b': 2}
00091         d2 = {'b': 3, 'c': 2}
00092         d3 = {'d': 4, 'e': 5}
00093         self.assertEqual(d1.keys() & d1.keys(), {'a', 'b'})
00094         self.assertEqual(d1.keys() & d2.keys(), {'b'})
00095         self.assertEqual(d1.keys() & d3.keys(), set())
00096         self.assertEqual(d1.keys() & set(d1.keys()), {'a', 'b'})
00097         self.assertEqual(d1.keys() & set(d2.keys()), {'b'})
00098         self.assertEqual(d1.keys() & set(d3.keys()), set())
00099 
00100         self.assertEqual(d1.keys() | d1.keys(), {'a', 'b'})
00101         self.assertEqual(d1.keys() | d2.keys(), {'a', 'b', 'c'})
00102         self.assertEqual(d1.keys() | d3.keys(), {'a', 'b', 'd', 'e'})
00103         self.assertEqual(d1.keys() | set(d1.keys()), {'a', 'b'})
00104         self.assertEqual(d1.keys() | set(d2.keys()), {'a', 'b', 'c'})
00105         self.assertEqual(d1.keys() | set(d3.keys()),
00106                          {'a', 'b', 'd', 'e'})
00107 
00108         self.assertEqual(d1.keys() ^ d1.keys(), set())
00109         self.assertEqual(d1.keys() ^ d2.keys(), {'a', 'c'})
00110         self.assertEqual(d1.keys() ^ d3.keys(), {'a', 'b', 'd', 'e'})
00111         self.assertEqual(d1.keys() ^ set(d1.keys()), set())
00112         self.assertEqual(d1.keys() ^ set(d2.keys()), {'a', 'c'})
00113         self.assertEqual(d1.keys() ^ set(d3.keys()),
00114                          {'a', 'b', 'd', 'e'})
00115 
00116         self.assertFalse(d1.keys().isdisjoint(d1.keys()))
00117         self.assertFalse(d1.keys().isdisjoint(d2.keys()))
00118         self.assertFalse(d1.keys().isdisjoint(list(d2.keys())))
00119         self.assertFalse(d1.keys().isdisjoint(set(d2.keys())))
00120         self.assertTrue(d1.keys().isdisjoint({'x', 'y', 'z'}))
00121         self.assertTrue(d1.keys().isdisjoint(['x', 'y', 'z']))
00122         self.assertTrue(d1.keys().isdisjoint(set(['x', 'y', 'z'])))
00123         self.assertTrue(d1.keys().isdisjoint(set(['x', 'y'])))
00124         self.assertTrue(d1.keys().isdisjoint(['x', 'y']))
00125         self.assertTrue(d1.keys().isdisjoint({}))
00126         self.assertTrue(d1.keys().isdisjoint(d3.keys()))
00127 
00128         de = {}
00129         self.assertTrue(de.keys().isdisjoint(set()))
00130         self.assertTrue(de.keys().isdisjoint([]))
00131         self.assertTrue(de.keys().isdisjoint(de.keys()))
00132         self.assertTrue(de.keys().isdisjoint([1]))

Here is the call graph for this function:


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