本文整理汇总了Python中cobra.DictList类的典型用法代码示例。如果您正苦于以下问题:Python DictList类的具体用法?Python DictList怎么用?Python DictList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DictList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testIndependent
def testIndependent(self):
a = DictList([Object("o1"), Object("o2")])
b = DictList()
self.assertIn("o1", a)
self.assertNotIn("o1", b)
b.append(Object("o3"))
self.assertNotIn("o3", a)
self.assertIn("o3", b)
示例2: test_independent
def test_independent(self):
a = DictList([Object("o1"), Object("o2")])
b = DictList()
assert "o1" in a
assert "o1" not in b
b.append(Object("o3"))
assert "o3" not in a
assert "o3" in b
示例3: testSet
def testSet(self):
obj_list = DictList(Object("test%d" % (i)) for i in range(10))
obj_list[4] = Object("testa")
self.assertEqual(obj_list.index("testa"), 4)
self.assertEqual(obj_list[4].id, "testa")
obj_list[5:7] = [Object("testb"), Object("testc")]
self.assertEqual(obj_list.index("testb"), 5)
self.assertEqual(obj_list[5].id, "testb")
self.assertEqual(obj_list.index("testc"), 6)
self.assertEqual(obj_list[6].id, "testc")
示例4: testInitCopy
def testInitCopy(self):
self.list.append(Object("test2"))
copied = DictList(self.list)
self.assertIsNot(self.list, copied)
self.assertIsInstance(copied, self.list.__class__)
self.assertEqual(len(self.list), len(copied))
for i, v in enumerate(self.list):
self.assertEqual(self.list[i].id, copied[i].id)
self.assertEqual(i, copied.index(v.id))
self.assertIs(self.list[i], copied[i])
self.assertIs(v, copied.get_by_id(v.id))
示例5: test_init_copy
def test_init_copy(self, dict_list):
obj, test_list = dict_list
test_list.append(Object("test2"))
copied = DictList(test_list)
assert test_list is not copied
assert isinstance(copied, test_list.__class__)
assert len(test_list) == len(copied)
for i, v in enumerate(test_list):
assert test_list[i].id == copied[i].id
assert i == copied.index(v.id)
assert test_list[i] is copied[i]
assert v is copied.get_by_id(v.id)
示例6: TestDictList
class TestDictList(TestCase):
def setUp(self):
self.obj = Object("test1")
self.list = DictList()
self.list.append(self.obj)
def testAppend(self):
obj2 = Object("test2")
self.list.append(obj2)
self.assertRaises(ValueError, self.list.append,
Object("test1"))
self.assertEqual(self.list.index(obj2), 1)
self.assertEqual(self.list[1], obj2)
self.assertEqual(self.list.get_by_id("test2"), obj2)
self.assertEqual(len(self.list), 2)
def testExtend(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list.extend(obj_list)
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testIadd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list += obj_list
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testAdd(self):
from os import name as __name
if __name == 'java':
warn('\t\n**cobra.test.unit_tests.testAdd does not yet work with %s'%__name)
return
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
sum = self.list + obj_list
self.assertEqual(self.list[0].id, "test1")
self.assertEqual(sum[1].id, "test2")
self.assertEqual(sum.get_by_id("test2"), obj_list[0])
self.assertEqual(sum[8].id, "test9")
self.assertEqual(len(self.list), 1)
self.assertEqual(len(sum), 9)
def testDeepcopy(self):
from copy import deepcopy
copied = deepcopy(self.list)
for i, v in enumerate(self.list):
assert self.list[i].id == copied[i].id
assert self.list[i] is not copied[i]
示例7: testRemoval
def testRemoval(self):
obj_list = DictList(Object("test%d" % (i)) for i in range(2, 10))
del obj_list[3]
self.assertNotIn("test5", obj_list)
self.assertEqual(obj_list.index(obj_list[-1]), len(obj_list) - 1)
del obj_list[3:5]
self.assertNotIn("test6", obj_list)
self.assertNotIn("test7", obj_list)
self.assertEqual(obj_list.index(obj_list[-1]), len(obj_list) - 1)
removed = obj_list.pop(1)
self.assertEqual(obj_list.index(obj_list[-1]), len(obj_list) - 1)
self.assertEqual(removed.id, "test3")
self.assertNotIn("test3", obj_list)
示例8: testSet
def testSet(self):
obj_list = DictList(Object("test%d" % (i)) for i in range(10))
obj_list[4] = Object("testa")
self.assertEqual(obj_list.index("testa"), 4)
self.assertEqual(obj_list[4].id, "testa")
obj_list[5:7] = [Object("testb"), Object("testc")]
self.assertEqual(obj_list.index("testb"), 5)
self.assertEqual(obj_list[5].id, "testb")
self.assertEqual(obj_list.index("testc"), 6)
self.assertEqual(obj_list[6].id, "testc")
# Even if the object is unique, if it is present twice in the new
# list, it should still raise an exception
self.assertRaises(ValueError, obj_list.__setitem__, slice(5, 7),
[Object("testd"), Object("testd")])
示例9: testSortandReverse
def testSortandReverse(self):
dl = DictList(Object("test%d" % (i)) for i in reversed(range(10)))
self.assertEqual(dl[0].id, "test9")
dl.sort()
self.assertEqual(len(dl), 10)
self.assertEqual(dl[0].id, "test0")
self.assertEqual(dl.index("test0"), 0)
dl.reverse()
self.assertEqual(dl[0].id, "test9")
self.assertEqual(dl.index("test0"), 9)
示例10: test_sort_and_reverse
def test_sort_and_reverse(self):
dl = DictList(Object("test%d" % (i)) for i in reversed(range(10)))
assert dl[0].id == "test9"
dl.sort()
assert len(dl) == 10
assert dl[0].id == "test0"
assert dl.index("test0") == 0
dl.reverse()
assert dl[0].id == "test9"
assert dl.index("test0") == 9
示例11: TestDictList
class TestDictList(TestCase):
def setUp(self):
self.obj = Object("test1")
self.list = DictList()
self.list.append(self.obj)
def testAppend(self):
obj2 = Object("test2")
self.list.append(obj2)
self.assertRaises(ValueError, self.list.append, Object("test1"))
self.assertEqual(self.list.index(obj2), 1)
self.assertEqual(self.list[1], obj2)
self.assertEqual(self.list.get_by_id("test2"), obj2)
self.assertEqual(len(self.list), 2)
def testExtend(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list.extend(obj_list)
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testIadd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list += obj_list
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testAdd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
sum = self.list + obj_list
self.assertEqual(self.list[0].id, "test1")
self.assertEqual(sum[1].id, "test2")
self.assertEqual(sum.get_by_id("test2"), obj_list[0])
self.assertEqual(sum[8].id, "test9")
self.assertEqual(len(self.list), 1)
self.assertEqual(len(sum), 9)
示例12: __iadd__
def __iadd__(self, other):
if not isinstance(other, StrainDesign):
raise AssertionError("Only instances of StrainDesign can be added together")
targets = {}
for target in self.targets:
if target.id not in targets:
targets[target.id] = set()
targets[target.id].add(target)
for target in other.targets:
if target.id not in targets:
targets[target.id] = set()
targets[target.id].add(target)
targets = [next(iter(t)) if len(t) == 1 else EnsembleTarget(id, t) for id, t in six.iteritems(targets)]
self.targets = DictList(targets)
return self
示例13: test_set
def test_set(self):
obj_list = DictList(Object("test%d" % (i)) for i in range(10))
obj_list[4] = Object("testa")
assert obj_list.index("testa") == 4
assert obj_list[4].id == "testa"
obj_list[5:7] = [Object("testb"), Object("testc")]
assert obj_list.index("testb") == 5
assert obj_list[5].id == "testb"
assert obj_list.index("testc") == 6
assert obj_list[6].id == "testc"
# Even if the object is unique, if it is present twice in the new
# list, it should still raise an exception
with pytest.raises(ValueError):
obj_list.__setitem__(slice(5, 7),
[Object("testd"), Object("testd")])
示例14: _build_targets
def _build_targets(self):
targets = DictList()
for reaction in self.reactions:
reaction = self._replace_adapted_metabolites(reaction)
if reaction.id in metanetx.mnx2all:
target = ReactionKnockinTarget(reaction.id, reaction, accession_id=reaction.id, accession_db='metanetx')
else:
target = ReactionKnockinTarget(reaction.id, reaction)
targets.append(target)
for reaction in self.exchanges:
reaction = self._replace_adapted_metabolites(reaction)
targets.append(ReactionKnockinTarget(reaction.id, reaction))
product = self._replace_adapted_metabolites(self.product)
product.lower_bound = 0
targets.append(ReactionKnockinTarget(product.id, product))
return targets
示例15: test_removal
def test_removal(self):
obj_list = DictList(Object("test%d" % (i)) for i in range(2, 10))
del obj_list[3]
assert "test5" not in obj_list
assert obj_list.index(obj_list[-1]) == len(obj_list) - 1
assert len(obj_list) == 7
del obj_list[3:5]
assert "test6" not in obj_list
assert "test7" not in obj_list
assert obj_list.index(obj_list[-1]) == len(obj_list) - 1
assert len(obj_list) == 5
removed = obj_list.pop(1)
assert obj_list.index(obj_list[-1]) == len(obj_list) - 1
assert removed.id == "test3"
assert "test3" not in obj_list
assert len(obj_list) == 4
removed = obj_list.pop()
assert removed.id == "test9"
assert removed.id not in obj_list
assert len(obj_list) == 3