• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

qiskit-community / qiskit-algorithms / 13954979262

19 Mar 2025 07:21PM CUT coverage: 90.454% (-0.02%) from 90.477%
13954979262

Pull #226

github

web-flow
Merge 4f82d7263 into ca48697e8
Pull Request #226: Improve custom equals fns

4 of 6 new or added lines in 2 files covered. (66.67%)

6396 of 7071 relevant lines covered (90.45%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.14
/qiskit_algorithms/algorithm_result.py
1
# This code is part of a Qiskit project.
2
#
3
# (C) Copyright IBM 2020, 2023.
4
#
5
# This code is licensed under the Apache License, Version 2.0. You may
6
# obtain a copy of this license in the LICENSE.txt file in the root directory
7
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8
#
9
# Any modifications or derivative works of this code must retain this
10
# copyright notice, and modified files need to carry a notice indicating
11
# that they have been altered from the originals.
12

13
"""
14
This module implements the abstract base class for algorithm results.
15
"""
16

17
from abc import ABC
1✔
18
import inspect
1✔
19
import pprint
1✔
20

21

22
class AlgorithmResult(ABC):
1✔
23
    """Abstract Base Class for algorithm results."""
24

25
    def __str__(self) -> str:
1✔
26
        result = {}
×
27
        for name, value in inspect.getmembers(self):
×
28
            if (
×
29
                not name.startswith("_")
30
                and not inspect.ismethod(value)
31
                and not inspect.isfunction(value)
32
                and hasattr(self, name)
33
            ):
34

35
                result[name] = value
×
36

37
        return pprint.pformat(result, indent=4)
×
38

39
    def combine(self, result: "AlgorithmResult") -> None:
1✔
40
        """
41
        Any property from the argument that exists in the receiver is
42
        updated.
43
        Args:
44
            result: Argument result with properties to be set.
45
        Raises:
46
            TypeError: Argument is None
47
        """
48
        if result is None:
1✔
49
            raise TypeError("Argument result expected.")
×
50
        if result == self:
1✔
51
            return
×
52

53
        # find any result public property that exists in the receiver
54
        for name, value in inspect.getmembers(result):
1✔
55
            if (
1✔
56
                not name.startswith("_")
57
                and not inspect.ismethod(value)
58
                and not inspect.isfunction(value)
59
                and hasattr(self, name)
60
            ):
61
                try:
1✔
62
                    setattr(self, name, value)
1✔
63
                except AttributeError:
×
64
                    # some attributes may be read only
65
                    pass
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc