def test_contains(self): g = Group(1, 'a', 'A') p1 = Entity(None, 'p1', '') p2 = Entity(None, 'p2', '') g.assign_picture(p1) assert p1 in g assert p2 not in g
def test_assign_picture(self): g = Group(1, 'a', 'A') p1 = Entity(None, 'p1', '') p2 = Entity(None, 'p2', '') g.assign_picture(p1) g.assign_picture(p2) pics = [p for p in g] assert 2 == len(pics) assert p1 in pics assert p2 in pics
def test_remove_picture(self): """Test assigning and removing of a picture. Removing it twice shall be ignored.""" g = Group(1, 'a', 'A') p1 = Entity(None, 'p1', '') g.assign_picture(p1) assert p1 in g assert 1 == len(g) g.remove_picture(p1) assert 0 == len(g) # ignore removing unknown picture g.remove_picture(p1)
def test_assign_same_picture_multiple_times(self): g = Group(1, 'a', 'A') p1 = Entity(None, 'p1', '') g.assign_picture(p1) assert p1 in g assert 1 == len(g) g.assign_picture(p1) assert 1 == len(g)
def test_iterate_over_pictures(self): """Test iteration without pictures assigned.""" g = Group(1, 'a', 'A') p1 = Entity(None, 'p1', '') p2 = Entity(None, 'p2', '') for _ in g: pytest.fail('No pictures expected.') assert 0 == len([p for p in g]) g.assign_picture(p1) assert 1 == len([p for p in g]), 'One picture expected.' g.assign_picture(p2) assert 2 == len([p for p in g]), 'Two pictures expected.'
def _new_grp_t(self, description='', parent=None): """Create new transient group.""" return Group(None, self._uq_name(P_GRP), description, parent)
def test_is_iterable(self): """Check that Group instances are iterable.""" g = Group(1, 'a', 'A') assert isinstance(g, Iterable)
def setUp(self): """Setup test data.""" self.g = Group(1, 'a', 'A') self.p1 = Entity(None, 'p1', '') self.p2 = Entity(None, 'p2', '')