def test_cmp(self): x = U.idict(Foo = 42, Bar = 37) y = U.idict(Foo = 42, Bar = 37) z = U.idict(Foo = 42, Bar = 99) self.assertGreater(z, x) self.assertGreaterEqual(z, y) self.assertLess(y, z) self.assertLessEqual(x, y)
def test_copy(self): x = U.idict(Foo = 42, Bar = 37) y = x.copy() self.assertIsInstance(y, U.idict) self.assertEqual(x, y) del x['foo'] self.assertNotEqual(x, y)
def test_len(self): x = U.idict() self.assertEqual(len(x), 0) x['Foo'] = 42; x['Bar'] = 37 self.assertEqual(len(x), 2) del x['foo'] self.assertEqual(len(x), 1)
def test_repr(self): x = H.Request(body="<body>") y = [("method", "GET"), ("uri", H.URI("/")), ("version", "HTTP/1.1"), ("headers", U.idict()), ("body", (b"<body>", )), ("env", {})] self.assertEqual( repr(x), "Request({})".format(", ".join("{} = {}".format(k, repr(v)) for (k, v) in y)))
def test_init_data_str(self): x = H.Response("<body>") self.assertEqual( dict(x.iteritems()), dict(version="HTTP/1.1", status=200, reason="OK", headers=U.idict(), body=(b"<body>", )))
def test_init_data_int(self): x = H.Response(500) self.assertEqual( dict(x.iteritems()), dict(version="HTTP/1.1", status=500, reason="Internal Server Error", headers=U.idict(), body=(b"", )))
def test_init_data_tuple(self): x = H.Response((404, dict(Foo="bar"), "<body>")) self.assertEqual( dict(x.iteritems()), dict(version="HTTP/1.1", status=404, reason="Not Found", headers=U.idict(Foo="bar"), body=(b"<body>", )))
def test_init_empty(self): x = H.Request() self.assertEqual( dict(x.iteritems()), # also tests iteritems dict(method="GET", uri="/", version="HTTP/1.1", headers=U.idict(), body=(b"", ), env={}))
def test_init_kwds(self): x = H.Request(method="POST", uri="/foo", headers=dict(Foo="bar"), body="<body>") self.assertEqual( dict(x.iteritems()), dict(method="POST", uri="/foo", version="HTTP/1.1", headers=U.idict(Foo="bar"), body=(b"<body>", ), env={}))
def test_eq(self): x = U.idict(Foo = 42, Bar = 37) y = U.idict(Foo = 42, Bar = 37) z = U.idict(Foo = 42, Bar = 99) self.assertEqual(x, y) self.assertNotEqual(x, z)
def test_iteritems_lower(self): x = U.idict(Foo = 42, Bar = 37) y = x.iteritems_lower() self.assertIsInstance(y, type(x for x in [])) self.assertEqual(sorted(y), [("bar", 37), ("foo", 42)])
def test_iter(self): x = U.idict(Foo = 42, Bar = 37) y = iter(x) self.assertIsInstance(y, type(x for x in [])) self.assertEqual(sorted(y), ["Bar", "Foo"])
def test_del(self): x = U.idict(Foo = 42); del x['foo'] self.assertEqual(list(x.values()), [])
def test_get(self): x = U.idict(Foo = 42, Bar = 37) self.assertEqual(x['Foo'], 42) self.assertEqual(x['foo'], 42) self.assertEqual(x['fOO'], 42) self.assertEqual(x['Bar'], 37)
def test_set(self): x = U.idict(); x['Foo'] = 42; x['Bar'] = 37 self.assertEqual(x['Foo'], 42) self.assertEqual(x['foo'], 42) self.assertEqual(x['fOO'], 42) self.assertEqual(x['Bar'], 37)
def test_repr(self): x = U.idict(x = 42) self.assertEqual(str(x), "idict({'x': 42})")
def test_init_headers(self): x = H.Request(headers=dict(x=37, y=42)) self.assertIsInstance(x.headers, U.idict) self.assertEqual(x.headers, U.idict(x=37, Y=42))