Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(diagrams): Set a dummy filename to prevent raise error when both … #240

Merged
merged 3 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ def __init__(
:param edge_attr: Provide edge_attr dot config attributes.
"""
self.name = name

if not filename:
if not name and not filename:
filename = "diagrams_image"
elif not filename:
filename = "_".join(self.name.split()).lower()
self.filename = filename
self.dot = Digraph(self.name, filename=self.filename)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def test_custom_filename(self):
Node("node1")
self.assertTrue(os.path.exists(f"{self.name}.png"))

def test_empty_name(self):
"""Check that providing an empty name don't crash, but save in a diagrams_image.xxx file."""
self.name = 'diagrams_image'
with Diagram(show=False):
Node("node1")
self.assertTrue(os.path.exists(f"{self.name}.png"))


class ClusterTest(unittest.TestCase):
def setUp(self):
Expand Down