Ejemplo n.º 1
0
    def test_invalid_process_type(self):
        """`get_results` should raise `ValueError` if `CalcJobNode` has invalid `process_type`"""
        node = CalcJobNode(computer=self.computer, process_type='aiida.calculations:not_existent')
        manager = CalcJobResultManager(node)

        with self.assertRaises(ValueError):
            manager.get_results()
Ejemplo n.º 2
0
def test_invalid_process_type(generate_calculation_node):
    """`get_results` should raise `ValueError` if `CalcJobNode` has invalid `process_type`"""
    node = generate_calculation_node(entry_point='aiida.calculations:invalid')
    manager = CalcJobResultManager(node)

    with pytest.raises(ValueError):
        manager.get_results()
Ejemplo n.º 3
0
    def test_no_process_type(self):
        """`get_results` should raise `ValueError` if `CalcJobNode` has no `process_type`"""
        node = CalcJobNode(computer=self.computer)
        manager = CalcJobResultManager(node)

        with self.assertRaises(ValueError):
            manager.get_results()
Ejemplo n.º 4
0
def test_no_process_type(generate_calculation_node):
    """`get_results` should raise `ValueError` if `CalcJobNode` has no `process_type`"""
    node = generate_calculation_node()
    manager = CalcJobResultManager(node)

    with pytest.raises(ValueError):
        manager.get_results()
Ejemplo n.º 5
0
def test_process_class_no_default_node(generate_calculation_node):
    """`get_results` should raise `ValueError` if process class does not define default output node."""
    # This is a valid process class however ArithmeticAddCalculation does define a default output node
    node = generate_calculation_node(
        entry_point='aiida.calculations:arithmetic.add')
    manager = CalcJobResultManager(node)

    with pytest.raises(ValueError):
        manager.get_results()
Ejemplo n.º 6
0
    def test_process_class_no_default_node(self):
        """`get_results` should raise `ValueError` if process class does not define default output node."""
        # This is a valid process class however ArithmeticAddCalculation does define a default output node
        process_class = CalculationFactory('arithmetic.add')
        process_type = get_entry_point_string_from_class(process_class.__module__, process_class.__name__)
        node = CalcJobNode(computer=self.computer, process_type=process_type)

        manager = CalcJobResultManager(node)

        with self.assertRaises(ValueError):
            manager.get_results()
Ejemplo n.º 7
0
def test_getitem_no_results(generate_calculation_node):
    """Test that `getitem` raises `KeyError` if no results can be retrieved whatsoever e.g. there is no output."""
    node = generate_calculation_node()
    manager = CalcJobResultManager(node)

    with pytest.raises(KeyError):
        assert manager['key']
Ejemplo n.º 8
0
def test_getattr_no_results(generate_calculation_node):
    """Test that `getattr` raises `AttributeError` if no results can be retrieved whatsoever e.g. there is no output."""
    node = generate_calculation_node()
    manager = CalcJobResultManager(node)

    with pytest.raises(AttributeError):
        assert getattr(manager, 'key')
Ejemplo n.º 9
0
def test_getitem(get_calcjob_node):
    """Test that the manager supports the getitem operator."""
    node, dictionary = get_calcjob_node
    manager = CalcJobResultManager(node)

    for key, value in dictionary.items():
        assert manager[key] == value

    with pytest.raises(KeyError):
        assert manager['non-existent-key']
Ejemplo n.º 10
0
def test_getattr(get_calcjob_node):
    """Test that the manager supports the getattr operator."""
    node, dictionary = get_calcjob_node
    manager = CalcJobResultManager(node)

    for key, value in dictionary.items():
        assert getattr(manager, key) == value

    with pytest.raises(AttributeError):
        assert getattr(manager, 'non-existent-key')
Ejemplo n.º 11
0
def test_dir(get_calcjob_node):
    """Test that `dir` returns all keys of the dictionary and nothing else."""
    node, dictionary = get_calcjob_node
    manager = CalcJobResultManager(node)

    assert len(dir(manager)) == len(dictionary)
    assert set(dir(manager)) == set(dictionary)

    # Check that it works also as an iterator
    assert len(list(manager)) == len(dictionary)
    assert set(manager) == set(dictionary)
Ejemplo n.º 12
0
    def res(self):
        """
        To be used to get direct access to the parsed parameters.

        :return: an instance of the CalcJobResultManager.

        :note: a practical example on how it is meant to be used: let's say that there is a key 'energy'
            in the dictionary of the parsed results which contains a list of floats.
            The command `calc.res.energy` will return such a list.
        """
        from aiida.orm.utils.calcjob import CalcJobResultManager
        return CalcJobResultManager(self)
Ejemplo n.º 13
0
 def test_getattr(self):
     """Test that the manager support getattr operator."""
     manager = CalcJobResultManager(self.node)
     self.assertEqual(getattr(manager, self.key_one), self.val_one)
Ejemplo n.º 14
0
 def test_getitem(self):
     """Test that the manager support getitem operator."""
     manager = CalcJobResultManager(self.node)
     self.assertEqual(manager[self.key_one], self.val_one)
Ejemplo n.º 15
0
 def test_iterator(self):
     """Test that the manager can be iterated over."""
     manager = CalcJobResultManager(self.node)
     for key in manager:
         self.assertIn(key, self.keys)
Ejemplo n.º 16
0
def test_iterator(get_calcjob_node):
    """Test that the manager can be iterated over."""
    node, dictionary = get_calcjob_node
    manager = CalcJobResultManager(node)
    for key in manager:
        assert key in dictionary.keys()