Beispiel #1
0
 def test_get_item(self):
     eur, usd = self.EUR().register(), self.USD().register()
     l = (eur, usd)
     o = ObjectList(l, self.Currency)
     o = self.CurrencyList(o)
     self.assertEqual(o['EUR'], eur)
     self.assertTrue(eur in o)
     self.assertEqual(o.index(eur), 0)
     self.assertEqual(o.get(eur), eur)
     self.assertEqual(o.get('EUR'), eur)
Beispiel #2
0
 def __init__(self, *args):
     super(MyVO, self).__init__(*args)
     self._none_prop_ = None
     self._str_prop_ = str('my str')
     self._int_prop_ = int(100)
     self._flt_prop_ = float(99.01)
     self._obj_prop_ = VisibleObject('YourVisibleObject')
     self._obj_list_prop_ = ObjectList()
     self._attr_list_prop_ = AttributeList()
     self._data_range_prop_ = DataRange()
Beispiel #3
0
 def test_objlist(self):
     names = ['obj' + str(i) for i in range(10)]
     l = ObjectList([MyVO(n) for n in names], object_type=VisibleObject)
     self.assertEqual(l.to_serializable(1), names)
     o = l[0]
     self.assertTrue(o in l)
Beispiel #4
0
    def test_objectList(self):
        eur, usd = self.EUR().register(), self.USD().register()
        l = (eur, usd)
        o = ObjectList(l, self.Currency)
        o = self.CurrencyList(o)
        self.assertTrue(o == o.__class__(l))
        self.assertTrue(o == o.__class__(o))
        self.assertTrue(o == o.__class__(o.to_serializable()))

        for x, y in zip(l, o.to_serializable()):
            self.assertTrue(type(y) is str)
            self.assertTrue(str(x) is y)

        const = self.FactoryDummy().register()
        ol = (lambda x: ObjectList(x, object_type=self.Currency))
        self.assertRaises(TypeError, ol, (eur, const))

        eur.register('eur')
        usd.register('usd')

        o[0] = eur
        self.assertTrue(eur in o)
        o.pop(0)
        self.assertTrue(eur not in o)
        o[0] = 'eur'
        self.assertTrue(eur in o)
        o.pop(0)
        o.insert(0, eur)
        self.assertTrue(eur in o)
        o.pop(0)
        o.insert(0, 'eur')
        self.assertTrue(eur in o)
        o.pop(0)
        o.append(eur)
        self.assertTrue(eur in o)
        o.pop(0)
        o.append('eur')
        self.assertTrue(eur in o)
        o.pop(0)
        o.extend([eur])
        self.assertTrue(eur in o)
        o.pop(0)
        o.extend(['eur'])
        self.assertTrue(eur in o)
        o.pop(0)
        # slices removed with migration to python 3
        # o[0:0] = [eur]
        # self.assertTrue(eur in o)
        # o.pop(0)
        # o[0:0] = ['eur']
        # self.assertTrue(eur in o)

        b = o + ['eur']
        self.assertTrue(isinstance(b, self.CurrencyList))
        self.assertTrue(eur in b)

        b = [eur] + o
        self.assertTrue(not isinstance(b, ObjectList))
        self.assertTrue(eur in b)