def test_clear(self): el = EntityList(self.instance1, 'artifact', Artifact) sd = self._make_desc(StringDescriptor, 'other') assert sd.__get__(self.instance1, None) == "thing" assert len(el) == 2 el.clear() assert len(el) == 0 assert sd.__get__(self.instance1, None) == "thing"
def test_append(self): el = EntityList(self.instance1, 'artifact', Artifact) assert len(el) == 2 assert len(el.instance.root.findall('artifact')) == 2 a3 = Artifact(self.lims, id='a3') el.append(a3) assert len(el) == 3 assert el[2] == a3 assert len(el._elems) == 3 assert len(el.instance.root.findall('artifact')) == 3
def test__get__(self): el = EntityList(self.instance1, 'artifact', Artifact) assert el[0] == self.a1 assert el[1] == self.a2 el = EntityList(self.instance2, 'artifact', Artifact, nesting=['nesting']) assert el[0] == self.a1 assert el[1] == self.a2
def test___add__(self): el1 = EntityList(self.instance1, 'artifact', Artifact) assert len(el1) == 2 assert len(el1.instance.root.findall('artifact')) == 2 el2 = [Artifact(self.lims, id='a3'), Artifact(self.lims, id='a4')] el3 = el1 + el2 assert len(el3) == 4 assert el3[:2] == el1 assert el3[2:] == el2
def test_set_list(self): el = EntityList(self.instance1, 'artifact', Artifact) assert len(el) == 2 assert len(el.instance.root.findall('artifact')) == 2 a3 = Artifact(self.lims, id='a3') a4 = Artifact(self.lims, id='a4') el[0:2] = [a3, a4] assert len(el) == 2 assert el[0] == a3 assert el[1] == a4
def test_set(self): el = EntityList(self.instance1, 'artifact', Artifact) assert len(el) == 2 assert len(el.instance.root.findall('artifact')) == 2 a3 = Artifact(self.lims, id='a3') el[1] = a3 assert len(el) == 2 assert el[1] == a3 assert len(el._elems) == 2 assert el.instance.root.findall('artifact')[1].attrib[ 'uri'] == 'http://testgenologics.com:4040/api/v2/artifacts/a3'
def test__iadd__(self): el1 = EntityList(self.instance1, 'artifact', Artifact) id1 = id(el1) assert len(el1) == 2 assert len(el1.instance.root.findall('artifact')) == 2 el2 = [Artifact(self.lims, id='a3'), Artifact(self.lims, id='a4')] el1 += el2 id2 = id(el1) assert id1 == id2 # still the same object assert len(el1) == 4 assert el1[2:] == el2