浏览代码

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

* fix(diagrams): Set a dummy filename to prevent raise error when both name and filename are not provided(#203)

* Update __init__.py

Update default name to "diagrams_image"

* Update test_diagram.py

Update unit test to reflect the file name change.
pull/242/head
gabriel-tessier 4 年前
committed by GitHub
父节点
当前提交
f26055608f
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 2 个文件被更改,包括 10 次插入2 次删除
  1. +3
    -2
      diagrams/__init__.py
  2. +7
    -0
      tests/test_diagram.py

+ 3
- 2
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)


+ 7
- 0
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):


正在加载...
取消
保存