From 6da1d5ae1ab04b55199f4f5242c94c2c4b926602 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 18:45:01 +0000 Subject: [PATCH] Add tests for existing Pyreverse bugs (#8983) (#9005) * Add Pyreverse bug tests * Sort Pyreverse class diagram names * Add test for bad line break (cherry picked from commit 14274610bdc7c3dec8f825e8e805f31a8d3133ab) Co-authored-by: Nick Drozd --- pylint/pyreverse/diagrams.py | 3 +- .../annotations/line_breaks.dot | 5 +++ .../annotations/line_breaks.mmd | 4 +++ .../annotations/line_breaks.puml | 6 ++++ .../class_diagrams/annotations/line_breaks.py | 5 +++ .../class_diagrams/annotations/line_breaks.rc | 2 ++ .../class_diagrams/attributes/duplicates.mmd | 20 ++++++++++++ .../class_diagrams/attributes/duplicates.py | 31 +++++++++++++++++++ 8 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tests/pyreverse/functional/class_diagrams/annotations/line_breaks.dot create mode 100644 tests/pyreverse/functional/class_diagrams/annotations/line_breaks.mmd create mode 100644 tests/pyreverse/functional/class_diagrams/annotations/line_breaks.puml create mode 100644 tests/pyreverse/functional/class_diagrams/annotations/line_breaks.py create mode 100644 tests/pyreverse/functional/class_diagrams/annotations/line_breaks.rc create mode 100644 tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd create mode 100644 tests/pyreverse/functional/class_diagrams/attributes/duplicates.py diff --git a/pylint/pyreverse/diagrams.py b/pylint/pyreverse/diagrams.py index 056dd8744b..543467e9d5 100644 --- a/pylint/pyreverse/diagrams.py +++ b/pylint/pyreverse/diagrams.py @@ -168,7 +168,8 @@ def class_names(self, nodes_lst: Iterable[nodes.NodeNG]) -> list[str]: if node.name not in names: node_name = node.name names.append(node_name) - return names + # sorted to get predictable (hence testable) results + return sorted(names) def has_node(self, node: nodes.NodeNG) -> bool: """Return true if the given node is included in the diagram.""" diff --git a/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.dot b/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.dot new file mode 100644 index 0000000000..f5c42258f3 --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.dot @@ -0,0 +1,5 @@ +digraph "classes" { +rankdir=BT +charset="utf-8" +"line_breaks.A" [color="black", fontcolor="black", label=<{A|
|f(x: str | None)
}>, shape="record", style="solid"]; +} diff --git a/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.mmd b/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.mmd new file mode 100644 index 0000000000..0abb8eeb76 --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.mmd @@ -0,0 +1,4 @@ +classDiagram + class A { + f(x: str | None)* + } diff --git a/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.puml b/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.puml new file mode 100644 index 0000000000..1515ea001e --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.puml @@ -0,0 +1,6 @@ +@startuml classes +set namespaceSeparator none +class "A" as line_breaks.A { + {abstract}f(x: str | None) +} +@enduml diff --git a/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.py b/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.py new file mode 100644 index 0000000000..2c084cebd2 --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.py @@ -0,0 +1,5 @@ +# OPEN BUG: https://github.com/pylint-dev/pylint/issues/8671 + +class A: + def f(self, x: str | None): + pass diff --git a/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.rc b/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.rc new file mode 100644 index 0000000000..9e2ff3d953 --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/annotations/line_breaks.rc @@ -0,0 +1,2 @@ +[testoptions] +output_formats=mmd,dot,puml diff --git a/tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd b/tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd new file mode 100644 index 0000000000..ee13b83462 --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd @@ -0,0 +1,20 @@ +classDiagram + class A { + } + class DuplicateAnnotations { + lav : list, list[str] + val : str, str | int + bar() None + } + class DuplicateArrows { + a + a + } + class DuplicateFields { + example1 : int + example1 : int + example2 : int + example2 : int + } + A --* DuplicateArrows : a + A --* DuplicateArrows : a diff --git a/tests/pyreverse/functional/class_diagrams/attributes/duplicates.py b/tests/pyreverse/functional/class_diagrams/attributes/duplicates.py new file mode 100644 index 0000000000..a3f05b81cb --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/attributes/duplicates.py @@ -0,0 +1,31 @@ +# OPEN BUG: https://github.com/pylint-dev/pylint/issues/8189 +class DuplicateFields(): + example1: int + example2: int + + def __init__(self): + self.example1 = 1 + self.example2 = 2 + + +# OPEN BUG: https://github.com/pylint-dev/pylint/issues/8522 +class A: + pass + +class DuplicateArrows: + a: A + + def __init__(self): + self.a = A() + + + +# OPEN BUG: https://github.com/pylint-dev/pylint/issues/8888 +class DuplicateAnnotations: + def __init__(self) -> None: + self.val: str | int = "1" + self.lav: list[str] = [] + + def bar(self) -> None: + self.val = "2" + self.lav = []