Beispiel #1
0
class TestResidueAttributes:
    from pyrolyse.core.residue import _read_attributes, _read_write_attributes

    test_attributes = list(_read_attributes)
    test_attributes.remove('carbohydrate_info')
    test_write_attr = list(_read_write_attributes)
    ros_pose = get_pose('PYTEST')
    lys_res = ros_pose.residue(2)

    # Lazy but gets the work done.
    @pytest.mark.parametrize('attr', test_attributes)
    def test_get_readonly_attributes(self, attr):
        # Can we get every read-only attribute without error?
        print(attr)
        getattr(self.lys_res, attr)

    @pytest.mark.parametrize('attr', test_attributes)
    def test_set_readonly_attributes(self, attr):
        with pytest.raises(AttributeError):
            setattr(self.lys_res, attr, None)

    @pytest.mark.parametrize('attr', test_write_attr)
    def test_get_readwrite_attributes(self, attr):
        getattr(self.lys_res, attr)

    @pytest.mark.parametrize('attr', test_write_attr)
    def test_set_readwrite_attr(self, attr):
        old_attr = getattr(self.lys_res, attr)
        setattr(self.lys_res, attr, old_attr)

    @pytest.mark.parametrize('attr', test_write_attr)
    def test_set_readwrite_attr_wrong_type(self, attr):
        wrong_type = None
        with pytest.raises(TypeError):
            setattr(self.lys_res, attr, wrong_type)
Beispiel #2
0
class TestPoseTorsionList:
    pose = get_pose('PYTEST')

    def test_get(self, get_torsion, set_torsion, torsion_list):
        assert_array_equal(getattr(self.pose, torsion_list), [180.0] * 6)

    @pytest.mark.parametrize('resid', list(range(-6, 6)))
    def test_get_item_psis(self, get_torsion, set_torsion, torsion_list,
                           resid):
        """Test __getitem__ of parametrized TorsionList

        Ex: say we test the first residue with attribute phis, the code would
        be equivalent to:
        >>> self.pose.set_psi(1, 0.)
        >>> assert self.pose.psis[0] == self.pose.psi(1)
        """
        if resid >= 0:
            index = resid + 1
            value = 0.
        else:
            index = self.pose.size + resid + 1
            value = 33.
        getattr(self.pose, set_torsion)(index, value)
        assert (getattr(self.pose, torsion_list)[resid] == getattr(
            self.pose, get_torsion)(index))

    def test_get_slice_psis(self, get_torsion, set_torsion, torsion_list):
        assert_array_equal(getattr(self.pose, torsion_list)[2:-1], [0.] * 3)

    def test_set_psis(self, get_torsion, set_torsion, torsion_list):
        setattr(self.pose, torsion_list, [60.] * 6)
        for resid in range(1, self.pose.size):
            assert getattr(self.pose, get_torsion)(resid) == 60.

    @pytest.mark.parametrize('resid', list(range(-6, 6)))
    def test_set_item_psis(self, get_torsion, set_torsion, torsion_list,
                           resid):
        if resid >= 0:
            index = resid + 1
            value = -30.
        else:
            index = self.pose.size + resid + 1
            value = -60.
        getattr(self.pose, torsion_list)[resid] = value
        assert getattr(self.pose, get_torsion)(index) == value

    def test_set_range_psis(self, get_torsion, set_torsion, torsion_list):
        getattr(self.pose, torsion_list)[2:-1] = [90.] * 3
        for resid in range(3, 5):
            assert getattr(self.pose, get_torsion)(resid) == 90.
        assert_array_equal(getattr(self.pose, torsion_list),
                           [-30., -30., 90., 90., 90., -30.])
Beispiel #3
0
class TestPoseAttributes:
    from pyrolyse.core.pose import _read_attributes

    # Getting membrane_info returns an error as there is no membrane.
    test_attributes = list(_read_attributes)
    test_attributes.remove('membrane_info')
    pose = get_pose('PYTEST')

    # Lazy but gets the work done.
    @pytest.mark.parametrize('attr', test_attributes)
    def test_get_readonly_attributes(self, attr):
        # Can we get every read-only attribute without error?
        print(attr)
        getattr(self.pose, attr)

    @pytest.mark.parametrize('attr', test_attributes)
    def test_set_readonly_attributes(self, attr):
        with pytest.raises(AttributeError):
            setattr(self.pose, attr, None)

    @pytest.mark.parametrize('attr', ['fold_tree', 'pdb_info'])
    def test_get_readwrite_attributes(self, attr):
        getattr(self.pose, attr)

    @pytest.mark.parametrize('attr', ['fold_tree', 'pdb_info'])
    def test_set_readwrite_attr(self, attr):
        old_attr = getattr(self.pose, attr)
        setattr(self.pose, attr, old_attr)

    @pytest.mark.parametrize('attr', ['fold_tree', 'pdb_info'])
    def test_set_readwrite_attr_wrong_type(self, attr):
        wrong_type = 1
        with pytest.raises(TypeError):
            setattr(self.pose, attr, wrong_type)

    # Check data descriptors.
    def test_residues(self):
        assert self.pose.residues

    def test_reslabels(self):
        assert self.pose.reslabels

    def test_scores(self):
        # Killing two birds with one stone by also testing score functions.
        sfxn = get_fa_scorefxn()
        sfxn(self.pose)
        assert self.pose.scores
Beispiel #4
0
class TestPDBInfoAttributes:
    from pyrolyse.core.pdbinfo import (_read_attributes,
                                       _read_write_attributes, _get_set_pairs)

    test_attributes = list(_read_attributes)
    test_write_attr = list(_read_write_attributes)
    test_write_attr += [get_set[0] for get_set in _get_set_pairs]

    pose = get_pose('PYTEST')
    try:
        pdbinfo = pose.pdb_info()
    except TypeError:
        pdbinfo = pose.pdb_info

    # Lazy but gets the work done.
    @pytest.mark.parametrize('attr', test_attributes)
    def test_get_readonly_attributes(self, attr):
        # Can we get every read-only attribute without error?
        getattr(self.pdbinfo, attr)

    @pytest.mark.parametrize('attr', test_attributes)
    def test_set_readonly_attributes(self, attr):
        with pytest.raises(AttributeError):
            setattr(self.pdbinfo, attr, None)

    @pytest.mark.parametrize('attr', test_write_attr)
    def test_get_readwrite_attributes(self, attr):
        getattr(self.pdbinfo, attr)

    @pytest.mark.parametrize('attr', test_write_attr)
    def test_set_readwrite_attr(self, attr):
        old_attr = getattr(self.pdbinfo, attr)
        setattr(self.pdbinfo, attr, old_attr)

    @pytest.mark.parametrize('attr', test_write_attr)
    def test_set_readwrite_attr_wrong_type(self, attr):
        wrong_type = []
        with pytest.raises(TypeError):
            setattr(self.pdbinfo, attr, wrong_type)
Beispiel #5
0
def test_auto_get_pose(pose_input):
    assert get_pose(pose_input).residue(1)
Beispiel #6
0
def test_get_pose(pose_input, kind):
    assert get_pose(pose_input, kind).residue(1)