Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

65 rader
2.1 KiB

  1. import os
  2. import random
  3. import string
  4. import unittest
  5. from diagrams import Diagram
  6. from diagrams import setcluster, setdiagram
  7. from diagrams.c4 import Person, Container, Database, System, SystemBoundary, Relationship
  8. class C4Test(unittest.TestCase):
  9. def setUp(self):
  10. self.name = "diagram-" + "".join([random.choice(string.hexdigits) for n in range(7)])
  11. def tearDown(self):
  12. setdiagram(None)
  13. setcluster(None)
  14. try:
  15. os.remove(self.name + ".png")
  16. except FileNotFoundError:
  17. pass
  18. def test_nodes(self):
  19. with Diagram(name=self.name, show=False):
  20. person = Person("person", "A person.")
  21. container = Container("container", "Java application", "The application.")
  22. database = Database("database", "Oracle database", "Stores information.")
  23. def test_external_nodes(self):
  24. with Diagram(name=self.name, show=False):
  25. external_person = Person("person", external=True)
  26. external_system = System("external", external=True)
  27. def test_systems(self):
  28. with Diagram(name=self.name, show=False):
  29. system = System("system", "The internal system.")
  30. system_without_description = System("unknown")
  31. def test_edges(self):
  32. with Diagram(name=self.name, show=False):
  33. c1 = Container("container1")
  34. c2 = Container("container2")
  35. c1 >> c2
  36. def test_edges_with_labels(self):
  37. with Diagram(name=self.name, show=False):
  38. c1 = Container("container1")
  39. c2 = Container("container2")
  40. c1 >> Relationship("depends on") >> c2
  41. c1 << Relationship("is depended on by") << c2
  42. def test_edge_without_constraint(self):
  43. with Diagram(name=self.name, show=False):
  44. s1 = System("system 1")
  45. s2 = System("system 2")
  46. s1 >> Relationship(constraint="False") >> s2
  47. def test_cluster(self):
  48. with Diagram(name=self.name, show=False):
  49. with SystemBoundary("System"):
  50. Container("container", "type", "description")