Skip to content

Commit

Permalink
Add tests for existing Pyreverse bugs (#8983) (#9005)
Browse files Browse the repository at this point in the history
* Add Pyreverse bug tests

* Sort Pyreverse class diagram names

* Add test for bad line break

(cherry picked from commit 1427461)

Co-authored-by: Nick Drozd <[email protected]>
  • Loading branch information
github-actions[bot] and nickdrozd authored Sep 4, 2023
1 parent c72a149 commit 6da1d5a
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pylint/pyreverse/diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
digraph "classes" {
rankdir=BT
charset="utf-8"
"line_breaks.A" [color="black", fontcolor="black", label=<{A|<br ALIGN="LEFT"/>|<I>f</I>(x: str | None)<br ALIGN="LEFT"/>}>, shape="record", style="solid"];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
classDiagram
class A {
f(x: str | None)*
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@startuml classes
set namespaceSeparator none
class "A" as line_breaks.A {
{abstract}f(x: str | None)
}
@enduml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# OPEN BUG: https://github.com/pylint-dev/pylint/issues/8671

class A:
def f(self, x: str | None):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[testoptions]
output_formats=mmd,dot,puml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions tests/pyreverse/functional/class_diagrams/attributes/duplicates.py
Original file line number Diff line number Diff line change
@@ -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 = []

0 comments on commit 6da1d5a

Please sign in to comment.