def test_creation(self):
     "Test the creation of a Bag"
     # With a dictionary
     bag = Bag(self.bag)
     self.failUnless(bag == self.bag)
     # With optional parameters
     bag = Bag(**self.bag)
     self.failUnless(bag == self.bag)
     # With a list of tuples
     bag = Bag([(k, v) for (k, v) in self.bag.items()])
     self.failUnless(bag == self.bag)
class TestBag(TestCase):
    #
    def setUp(self):
        self.bag = Bag(a=1, b=2, c=3)

    #
    def test_getitem(self):
        "Try getitem/getattr"
        bag = self.bag
        self.failUnless(bag['a'] == 1)
        self.failUnless(bag.a == 1)

    #
    def test_creation(self):
        "Test the creation of a Bag"
        # With a dictionary
        bag = Bag(self.bag)
        self.failUnless(bag == self.bag)
        # With optional parameters
        bag = Bag(**self.bag)
        self.failUnless(bag == self.bag)
        # With a list of tuples
        bag = Bag([(k, v) for (k, v) in self.bag.items()])
        self.failUnless(bag == self.bag)

    #
    def test_set_by_attribute(self):
        "Try setting by attribute"
        bag = self.bag
        bag.d = 4
        self.failUnless(bag['d'] == 4)
        self.failUnless(bag.d == 4)
        #
        bag.a = -1
        self.failUnless(bag['a'] == 1)

    #
    def test_set_specials(self):
        "Try setting special functions"
        bag = self.bag
        try:
            bag.__dict__ = 7
        except TypeError:
            pass
        #
        bag.pop = 7
        self.failUnless(hasattr(bag.pop, '__call__'))

    def test_pickling(self):
        bag = self.bag
        import cPickle
        pickled = cPickle.loads(cPickle.dumps(bag))
        self.failUnless(pickled == bag)
Example #3
0
class TestBag(TestCase):
    #
    def setUp(self):
        self.bag = Bag(a=1, b=2, c=3)
    #
    def test_getitem(self):
        "Try getitem/getattr"
        bag = self.bag
        self.failUnless(bag['a'] == 1)
        self.failUnless(bag.a == 1)
    #
    def test_creation(self):
        "Test the creation of a Bag"
        # With a dictionary
        bag = Bag(self.bag)
        self.failUnless(bag==self.bag)
        # With optional parameters
        bag = Bag(**self.bag)
        self.failUnless(bag==self.bag)
        # With a list of tuples
        bag = Bag([(k,v) for (k,v) in self.bag.items()])
        self.failUnless(bag==self.bag)
    #
    def test_set_by_attribute(self):
        "Try setting by attribute"
        bag = self.bag
        bag.d = 4
        self.failUnless(bag['d'] == 4)
        self.failUnless(bag.d == 4)
        #
        bag.a = -1
        self.failUnless(bag['a'] == 1)
    #
    def test_set_specials(self):
        "Try setting special functions"
        bag = self.bag
        try:
            bag.__dict__ = 7
        except TypeError:
            pass
        #
        bag.pop = 7
        self.failUnless(hasattr(bag.pop, '__call__'))

    def test_pickling(self):
        bag = self.bag
        import cPickle
        pickled = cPickle.loads(cPickle.dumps(bag))
        self.failUnless(pickled==bag)
Example #4
0
 def setUp(self):
     self.bag = Bag(a=1, b=2, c=3)
 def setUp(self):
     self.bag = Bag(a=1, b=2, c=3)