def test_simple(self): FooBar = TypedNamedTuple('FooBar', [('foo', unicode), ('bar', int)]) t = FooBar(foo='foo', bar=2) self.assertEquals(type(t), FooBar) self.assertEquals(t.foo, 'foo') self.assertEquals(t.bar, 2) self.assertEquals(t[0], 'foo') self.assertEquals(t[1], 2) FooBar('foo', 2) with self.assertRaises(TypeError): FooBar('foo', 'not integer') with self.assertRaises(TypeError): FooBar(2, 4) # Passing a tuple as the first argument is the same as passing multiple # arguments. t1 = ('foo', 3) t2 = FooBar(t1) self.assertEquals(type(t2), FooBar) self.assertEqual(FooBar(t1), FooBar('foo', 3))
def test_simple(self): FooBar = TypedNamedTuple("FooBar", [("foo", six.text_type), ("bar", int)]) t = FooBar(foo="foo", bar=2) self.assertEquals(type(t), FooBar) self.assertEquals(t.foo, "foo") self.assertEquals(t.bar, 2) self.assertEquals(t[0], "foo") self.assertEquals(t[1], 2) FooBar("foo", 2) with self.assertRaises(TypeError): FooBar("foo", "not integer") with self.assertRaises(TypeError): FooBar(2, 4) # Passing a tuple as the first argument is the same as passing multiple # arguments. t1 = ("foo", 3) t2 = FooBar(t1) self.assertEquals(type(t2), FooBar) self.assertEqual(FooBar(t1), FooBar("foo", 3))