Compare nodes between spec and library. Returns list of Differences.
(specNodes, libNodes, libDefaults, geompropNames, compareDefaults=False)
| 729 | return None, None, None, None |
| 730 | |
| 731 | def compareNodes(specNodes, libNodes, libDefaults, geompropNames, compareDefaults=False): |
| 732 | '''Compare nodes between spec and library. Returns list of Differences.''' |
| 733 | differences = [] |
| 734 | |
| 735 | specNames = set(specNodes.keys()) |
| 736 | libNames = set(libNodes.keys()) |
| 737 | |
| 738 | # Nodes in spec but not in library |
| 739 | for nodeName in sorted(specNames - libNames): |
| 740 | differences.append(Difference( |
| 741 | diffType=DiffType.NODE_MISSING_IN_LIBRARY, |
| 742 | node=nodeName)) |
| 743 | |
| 744 | # Nodes in library but not in spec |
| 745 | for nodeName in sorted(libNames - specNames): |
| 746 | differences.append(Difference( |
| 747 | diffType=DiffType.NODE_MISSING_IN_SPEC, |
| 748 | node=nodeName)) |
| 749 | |
| 750 | # Compare signatures for common nodes |
| 751 | for nodeName in sorted(specNames & libNames): |
| 752 | specNode = specNodes[nodeName] |
| 753 | libNode = libNodes[nodeName] |
| 754 | |
| 755 | specSigs = specNode.signatures |
| 756 | libSigs = libNode.signatures |
| 757 | |
| 758 | # Track which signatures have been matched |
| 759 | matchedLibSigs = set() |
| 760 | matchedSpecSigs = set() |
| 761 | inputDiffMatches = [] # (specSig, libSig, extraInLib, extraInSpec) |
| 762 | |
| 763 | # For each spec signature, find matching library signature |
| 764 | for specSig in specSigs: |
| 765 | matchType, libSig, extraInLib, extraInSpec = findLibraryMatch(specSig, libSigs) |
| 766 | |
| 767 | if matchType == MatchType.EXACT: |
| 768 | matchedLibSigs.add(libSig) |
| 769 | matchedSpecSigs.add(specSig) |
| 770 | # Compare defaults for exact matches |
| 771 | if compareDefaults: |
| 772 | sigDefaults = libDefaults.get((nodeName, libSig), {}) |
| 773 | differences.extend(compareSignatureDefaults( |
| 774 | nodeName, specSig, specNode, sigDefaults, geompropNames)) |
| 775 | |
| 776 | elif matchType == MatchType.DIFFERENT_INPUTS: |
| 777 | matchedLibSigs.add(libSig) |
| 778 | matchedSpecSigs.add(specSig) |
| 779 | inputDiffMatches.append((specSig, libSig, extraInLib, extraInSpec)) |
| 780 | # Compare defaults for different input matches too (for common ports) |
| 781 | if compareDefaults: |
| 782 | sigDefaults = libDefaults.get((nodeName, libSig), {}) |
| 783 | differences.extend(compareSignatureDefaults( |
| 784 | nodeName, specSig, specNode, sigDefaults, geompropNames)) |
| 785 | |
| 786 | # Report different input set matches |
| 787 | for specSig, libSig, extraInLib, extraInSpec in sorted(inputDiffMatches, key=lambda x: str(x[0])): |
| 788 | differences.append(Difference( |
no test coverage detected