diff --git a/diagrams/__init__.py b/diagrams/__init__.py index 301dbcf..5139643 100644 --- a/diagrams/__init__.py +++ b/diagrams/__init__.py @@ -101,8 +101,9 @@ class Diagram: :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) diff --git a/tests/test_diagram.py b/tests/test_diagram.py index fd8abc2..bbb1aa5 100644 --- a/tests/test_diagram.py +++ b/tests/test_diagram.py @@ -100,6 +100,13 @@ class DiagramTest(unittest.TestCase): 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):