Пример #1
0
    def test_del(self):
        """
        Test ParameterList __del__ overloading.
        """
        p1 = ParameterType(smirks='[*:1]')
        p2 = ParameterType(smirks='[#1:1]')
        p3 = ParameterType(smirks='[#7:1]')
        parameters = ParameterList([p1, p2, p3])

        with pytest.raises(IndexError,
                           match='list assignment index out of range'):
            del parameters[4]
        with pytest.raises(
                IndexError,
                match=r'SMIRKS \[#6:1\] not found in ParameterList'):
            del parameters['[#6:1]']

        # Test that original list deletion behavior is preserved.
        del parameters[2]
        assert len(parameters) == 2
        assert p1 in parameters
        assert p2 in parameters
        assert p3 not in parameters

        # Test that we can delete elements by their smirks.
        del parameters['[#1:1]']
        assert len(parameters) == 1
        assert p1 in parameters
        assert p2 not in parameters
Пример #2
0
 def test_base_parametertype_to_dict(self):
     """
     Test ParameterType to_dict.
     """
     p1 = ParameterType(smirks='[*:1]')
     param_dict = p1.to_dict()
     assert param_dict['smirks'] == '[*:1]'
     assert len(param_dict.keys()) == 1
Пример #3
0
 def test_insert(self):
     """
     Test ParameterList.insert, ensuring that the new parameter was added to the proper spot in
     the list and that it is propertly recorded as the most recently added.
     """
     p1 = ParameterType(smirks='[*:1]-[*:2]')
     p2 = ParameterType(smirks='[*:1]=[*:2]')
     p3 = ParameterType(smirks='[*:1]#[*:2]')
     param_list = ParameterList([p1, p2])
     param_list.insert(1, p3)
     assert param_list[1] == p3
Пример #4
0
 def test_contains(self):
     """Test ParameterList __contains__ overloading.
     """
     p1 = ParameterType(smirks='[*:1]')
     p2 = ParameterType(smirks='[#1:1]')
     p3 = ParameterType(smirks='[#7:1]')
     parameters = ParameterList([p1, p2])
     assert p1 in parameters
     assert p2 in parameters
     assert p3 not in parameters
     assert p1.smirks in parameters
     assert p2.smirks in parameters
     assert p3.smirks not in parameters
Пример #5
0
    def test_extend(self):
        """
        Test ParameterList.extend, ensuring that the new parameter was added to the proper spot in
        the list and that it is propertly recorded as the most recently added.
        """
        p1 = ParameterType(smirks='[*:1]-[*:2]')
        p2 = ParameterType(smirks='[*:1]=[*:2]')
        param_list1 = ParameterList()
        param_list2 = ParameterList([p1, p2])

        param_list1.extend(param_list2)
        assert len(param_list1) == 2
        assert '[*:1]-[*:2]' in param_list1
        assert '[*:1]=[*:2]' in param_list1
        assert param_list1[-1] == p2
Пример #6
0
 def test_append(self):
     """
     Test ParameterList.append, ensuring that the new parameter was added to the bottom of the list
     and that it is properly recorded as the most recently-added.
     """
     p1 = ParameterType(smirks='[*:1]-[*:2]')
     p2 = ParameterType(smirks='[*:1]=[*:2]')
     param_list = ParameterList()
     param_list.append(p1)
     assert len(param_list) == 1
     assert '[*:1]-[*:2]' in param_list
     param_list.append(p2)
     assert len(param_list) == 2
     assert '[*:1]=[*:2]' in param_list
     assert param_list[-1] == p2
Пример #7
0
    def test_getitem(self):
        """Test ParameterList __getitem__ overloading.
        """
        p1 = ParameterType(smirks='[*:1]')
        p2 = ParameterType(smirks='[#1:1]')
        parameters = ParameterList([p1, p2])
        assert parameters[0] == p1
        assert parameters[1] == p2
        assert parameters[p1.smirks] == p1
        assert parameters[p2.smirks] == p2

        # Note that this call access __getitem__, not __setitem__.
        parameters['[*:1]'].smirks = '[*X4:1]'
        assert parameters[0].smirks == '[*X4:1]'
        assert p1.smirks == '[*X4:1]'
Пример #8
0
    def test_index(self):
        """
        Tests the ParameterList.index() function by attempting lookups by SMIRKS and by ParameterType equivalence.

        """
        p1 = ParameterType(smirks='[*:1]')
        p2 = ParameterType(smirks='[#1:1]')
        p3 = ParameterType(smirks='[#7:1]')
        parameters = ParameterList([p1, p2, p3])
        assert parameters.index(p1) == 0
        assert parameters.index(p2) == 1
        assert parameters.index(p3) == 2
        assert parameters.index('[*:1]') == 0
        assert parameters.index('[#1:1]') == 1
        assert parameters.index('[#7:1]') == 2
        with pytest.raises(IndexError, match=r'SMIRKS \[#2:1\] not found in ParameterList') as excinfo:
            parameters.index('[#2:1]')

        p4 = ParameterType(smirks='[#2:1]')
        with pytest.raises(ValueError, match='is not in list') as excinfo:
            parameters.index(p4)
Пример #9
0
 def test_create(self):
     """Test creation of a parameter list.
     """
     p1 = ParameterType(smirks='[*:1]')
     p2 = ParameterType(smirks='[#1:1]')
     parameters = ParameterList([p1, p2])