def testMul(self): """Test __mul__""" assert (self.plain1 * 7) == (self.proxied1 * 7) assert isProxy(self.proxied1 * 9) for p in self.proxied1: assert isProxy(p)
def testMul(self): """Test __mul__""" self.assertEqual((self.plain1 * 7), (self.proxied1 * 7)) self.assertTrue(isProxy(self.proxied1 * 9)) for p in self.proxied1: self.assertTrue(isProxy(p))
def testMul(self): """Test __mul__""" assert len(self.plain1 * 7) == len(self.proxied1 * 7) assert isProxy(self.proxied1 * 9) for p in self.proxied1: assert isProxy(p)
def testGet(self): assert isProxy(self.test_job.application.seq) assert isProxy(self.test_job.application.gList) assert isProxy(self.test_job.application.gListComp) assert isType(self.test_job.application.seq, gangaList) assert isType(self.test_job.application.gList, gangaList) assert isType(self.test_job.application.gListComp, gangaList)
def testApp(self): assert not isinstance(self.test_job.application.seq, list) for f in self.test_job.application.gListComp: assert isProxy(f), 'Items in list must be proxies' for s in self.test_job.application.gList: assert not isProxy(s), 'Items in list must not be proxies'
def testIAdd(self): """Test __iadd__""" self.assertTrue(isProxy(self.proxied1), 'Must be Proxy') self.assertTrue(isProxy(self.proxied2), 'Must be Proxy') self.plain1 += self.plain2 self.proxied1 += self.proxied2 self.assertEqual(self.plain1, self.proxied1, 'Addition should be the same') self.assertTrue(isProxy(self.proxied1), 'Proxy must be added')
def testIAdd(self): """Test __iadd__""" assert isProxy(self.proxied1), 'Must be Proxy' assert isProxy(self.proxied2), 'Must be Proxy' self.plain1 += self.plain2 self.proxied1 += self.proxied2 assert self.plain1 == self.proxied1, 'Addition should be the same' assert isProxy(self.proxied1), 'Proxy must be added'
def testApp(self): from Ganga.GPIDev.Base.Proxy import isProxy assert not isinstance(self.test_job.application.seq, list) for f in self.test_job.application.gListComp: assert isProxy(f), 'Items in list must be proxies' for s in self.test_job.application.gList: assert not isProxy(s), 'Items in list must not be proxies'
def testGet(self): from Ganga.GPIDev.Lib.GangaList.GangaList import GangaList as gangaList from Ganga.GPIDev.Base.Proxy import isProxy, isType assert isProxy(self.test_job.application.seq) assert isProxy(self.test_job.application.gList) assert isProxy(self.test_job.application.gListComp) assert isType(self.test_job.application.seq, gangaList) assert isType(self.test_job.application.gList, gangaList) assert isType(self.test_job.application.gListComp, gangaList)
def testGetDefaults(self): test_job = Job(application=GListApp(), backend=TestSubmitter()) assert isProxy(test_job.application.seq) assert isProxy(test_job.application.gList) assert isProxy(test_job.application.gListComp) assert isType(test_job.application.seq, gangaList) assert isType(test_job.application.gList, gangaList) assert isType(test_job.application.gListComp, gangaList)
def testAddMixed2(self): self.plain1 = range(10) self.plain2 = range(10) self.assertTrue(isProxy(self.proxied2[-1]), 'Element access must get proxies') self.assertFalse(isProxy(self.plain1[0]), 'Element access must not proxies') self.assertTrue(isProxy((self.plain1 + self.proxied2)[-1]), 'File objects should remain proxies') self.assertFalse(isProxy((self.plain1 + self.proxied2)[0]), 'Objects in plain lists should be left alone') self.assertEqual((self.plain1 + self.proxied2)[-1], self.proxied2[-1], 'File objects should be equal') self.assertIs((self.plain1 + self.proxied2)[-1], self.proxied2[-1], 'File objects should be identical')
def testAddMixed2(self): self.plain1 = range(10) self.plain2 = range(10) assert isProxy(self.proxied2[-1]), 'Element access must get proxies' assert not isProxy(self.plain1[0]), 'Element access must not proxies' assert isProxy((self.plain1 + self.proxied2)[-1]), 'File objects should remain proxies' assert not isProxy((self.plain1 + self.proxied2)[0]), 'Objects in plain lists should be left alone' assert (self.plain1 + self.proxied2)[-1] == self.proxied2[-1], 'File objects should be equal' assert (self.plain1 + self.proxied2)[-1] is self.proxied2[-1], 'File objects should be identical'
def testIAddSlice(self): """Test __iadd__ on slices""" s1 = self.plain1[3:7] s1 += self.plain2[2:5] s2 = self.proxied1[3:7] s2 += self.proxied2[2:5] self.assertEqual(s1, s2, 'Addition should be the same') self.assertFalse(isProxy(s1), 'Proxy Not Needed') self.assertTrue(isProxy(s2), 'Proxy Needed')
def testIAddSlice(self): """Test __iadd__ on slices""" s1 = self.plain1[3:7] s1 += self.plain2[2:5] s2 = self.proxied1[3:7] s2 += self.proxied2[2:5] assert s1 == s2, 'Addition should be the same' assert not isProxy(s1), 'Proxy Not Needed' assert isProxy(s2), 'Proxy Needed'
def testGetDefaults(self): from Ganga.GPI import Job, TestSubmitter, GListApp from Ganga.GPIDev.Lib.GangaList.GangaList import GangaList as gangaList from Ganga.GPIDev.Base.Proxy import isProxy, isType test_job = Job(application=GListApp(), backend=TestSubmitter()) assert isProxy(test_job.application.seq) assert isProxy(test_job.application.gList) assert isProxy(test_job.application.gListComp) assert isType(test_job.application.seq, gangaList) assert isType(test_job.application.gList, gangaList) assert isType(test_job.application.gListComp, gangaList)
def has_proxy_element(_list): """ Returns if a proxy object has crept into the list Args: _list (list): Any iterable object """ return all([isProxy(l) for l in _list])
def testIMul(self): """Test __imul__""" self.plain1 *= 5 self.proxied1 *= 5 self.assertEqual(self.plain1, self.proxied1, 'Multiplication should be the same') self.assertTrue(isProxy(self.proxied1), 'Proxy must be added')
def testSetSimple(self): """Sets a list of proxies and makes sure we get a GangaList""" # simple types s = [self._makeRandomString() for _ in range(15)] assert isinstance(s, list), 'Nothing funny going on here' for ss in s: assert not isProxy(ss), 'We have no proxies' self.test_job.application.gList = s assert len(self.test_job.application.gList) == len( s), 'List must have the correct length.' assert self.test_job.application.gList == s, 'lists should be the same' for ss in self.test_job.application.gList: assert not isProxy(ss), 'We have no proxies' assert isinstance(self.test_job.application.gList._impl, gangaList)
def testIMul(self): """Test __imul__""" self.plain1 *= 5 self.proxied1 *= 5 assert self.plain1 == self.proxied1, 'Multiplication should be the same' assert isProxy(self.proxied1), 'Proxy must be added'
def testContains(self): """Tests __contains__""" plist = [addProxy(x) for x in self.plain1] self.assertEqual(plist, self.proxied1) for p in plist: self.assertTrue(isProxy(p)) self.assertIn(p, self.proxied1, 'Proxied list should contain each proxied object')
def testSetComponent(self): """Sets a list of proxies and makes sure we get a GangaList""" # component types r = [self._makeRandomTFile() for _ in range(15)] assert isinstance(r, list), 'nothing funny going on' for rp in r: assert isProxy(rp), 'We have proxies' self.test_job.application.gListComp = r assert len(self.test_job.application.gListComp) == len( r), 'List must have the correct length.' assert self.test_job.application.gListComp == r, 'lists should be the same' for rp in self.test_job.application.gListComp: assert isProxy(rp), 'We have proxies' assert isinstance(self.test_job.application.gListComp._impl, gangaList)
def testAddMixed(self): """Test __add__ with mixed lists and GangaLists""" self.assertEqual((self.plain1 + self.plain2), (self.proxied1 + self.plain2)) self.assertEqual((self.plain2 + self.plain1), (self.plain2 + self.proxied1)) self.assertTrue(isProxy(self.proxied1 + self.plain2)) self.assertEqual((self.plain2 + self.plain1), (self.plain2 + self.proxied1)) self.assertEqual((self.plain1 + self.plain2), (self.plain1 + self.proxied2)) self.assertTrue(isinstance(self.plain1 + self.proxied2, list))
def testAddMixed(self): """Test __add__ with mixed lists and GangaLists""" assert (self.plain1 + self.plain2) == (self.proxied1 + self.plain2) assert (self.plain2 + self.plain1) == (self.plain2 + self.proxied1) assert isProxy(self.proxied1 + self.plain2) assert (self.plain2 + self.plain1) == (self.plain2 + self.proxied1) assert (self.plain1 + self.plain2) == (self.plain1 + self.proxied2) assert isinstance(self.plain1 + self.proxied2, list)
def testReversed(self): """Test the __reversed__ feature (new in python 2.4).""" count = len(self.proxied1) - 1 for i in self.proxied1.__reversed__(): self.assertIs(i, self.proxied1[count]) self.assertTrue(isProxy(i)) self.assertTrue(isType(i, TFile)) count -= 1
def testIter(self): count = 0 for f in self.proxied1: count += 1 self.assertTrue(isProxy(f)) self.assertTrue(isType(f, TFile)) self.assertEqual(count, len(self.proxied1), 'Must visit every member')
def testIAddMixed(self): """Test __iadd__ where we mix lists and GangaLists""" assert isProxy(self.proxied1), 'Must be Proxy' assert isProxy(self.proxied2), 'Must be Proxy' self.plain1 += self.plain2 self.proxied1 += self.plain2 assert self.plain1 == self.proxied1, 'Addition should be the same' assert isProxy(self.proxied1), 'Proxy must be added' assert isinstance(self.plain1, list), 'Must be list instance' self.plain2 += self.proxied1 self.proxied2 += self.proxied1 assert self.plain2 == self.proxied2, 'Addition should be the same' assert isProxy(self.proxied2), 'Proxy must be added' assert isinstance(self.plain2, list), 'Must be list instance'
def testContains(self): """Tests __contains__""" plist = [addProxy(x) for x in self.plain1] assert plist == self.proxied1 for p in plist: assert isProxy(p) assert p in self.proxied1, 'Proxied list should contain each proxied object'
def testIAddMixed(self): """Test __iadd__ where we mix lists and GangaLists""" self.assertTrue(isProxy(self.proxied1), 'Must be Proxy') self.assertTrue(isProxy(self.proxied2), 'Must be Proxy') self.plain1 += self.plain2 self.proxied1 += self.plain2 self.assertEqual(self.plain1, self.proxied1, 'Addition should be the same') self.assertTrue(isProxy(self.proxied1), 'Proxy must be added') self.assertTrue(isinstance(self.plain1, list), 'Must be list instance') self.plain2 += self.proxied1 self.proxied2 += self.proxied1 self.assertEqual(self.plain2, self.proxied2, 'Addition should be the same') self.assertTrue(isProxy(self.proxied2), 'Proxy must be added') self.assertTrue(isinstance(self.plain2, list), 'Must be list instance')
def testAddMixed2(self): self.plain1 = range(10) self.plain2 = range(10) assert isProxy(self.proxied2[-1]), 'Element access must get proxies' assert not isProxy(self.plain1[0]), 'Element access must not proxies' assert isProxy( (self.plain1 + self.proxied2)[-1]), 'File objects should remain proxies' assert not isProxy( (self.plain1 + self.proxied2)[0]), 'Objects in plain lists should be left alone' assert (self.plain1 + self.proxied2 )[-1] == self.proxied2[-1], 'File objects should be equal' assert (self.plain1 + self.proxied2 )[-1] is self.proxied2[-1], 'File objects should be identical'
def testReversed(self): """Test the __reversed__ feature (new in python 2.4).""" from TFile import TFile as tF count = len(self.proxied1) - 1 for i in self.proxied1.__reversed__(): assert i is self.proxied1[count] assert isProxy(i) assert isType(i, tF) count -= 1
def testIter(self): from TFile import TFile as tF count = 0 for f in self.proxied1: count += 1 assert isProxy(f) assert isType(f, tF) assert count == len(self.proxied1), 'Must visit every member'
def testSetItem(self): """Test __setitem__""" t = TFile(name='foo', subdir='cheese') test_index = 7 self.plain1[test_index] = t assert self.plain1[test_index] is t self.proxied1[test_index] = t assert self.proxied1[test_index] is t assert isProxy(self.proxied1[test_index])
def testSetItem(self): """Test __setitem__""" t = TFile(name='foo', subdir='cheese') test_index = 7 self.plain1[test_index] = t self.assertIs(self.plain1[test_index], t) self.proxied1[test_index] = t self.assertIs(self.proxied1[test_index], t) self.assertTrue(isProxy(self.proxied1[test_index]))