def test_cli_consistency_with_the_default_configuration(entrypoint: List[str]): command = entrypoint + ['py2puml/domain', 'py2puml.domain'] cli_stdout = run(command, stdout=PIPE, stderr=PIPE, text=True, check=True).stdout puml_content = py2puml.py2puml('py2puml/domain', 'py2puml.domain') assert ''.join(puml_content).strip() == cli_stdout.strip()
def run(): argparser = ArgumentParser(description='Generate Plantuml diagrams to document your python code') argparser.add_argument('-v', '--version', action='version', version='py2puml 0.4.0') argparser.add_argument('path', metavar='path', type=str, help='the path of the domain') argparser.add_argument('module', metavar='module', type=str, help='the module of the domain', default=None) args = argparser.parse_args() print(''.join(py2puml(args.path, args.module)))
def test_py2puml_with_subdomain(): expected = """@startuml class tests.modules.withsubdomain.subdomain.insubdomain.Engine { horsepower: int } class tests.modules.withsubdomain.subdomain.insubdomain.Pilot { name: str } class tests.modules.withsubdomain.withsubdomain.Car { name: str engine: Engine } tests.modules.withsubdomain.withsubdomain.Car *-- tests.modules.withsubdomain.subdomain.insubdomain.Engine @enduml """ puml_content = py2puml.py2puml('tests/modules/withsubdomain/', 'tests.modules.withsubdomain') assert ''.join(puml_content) == expected
def test_py2puml_model(): """test py2puml on py2puml/domain.""" expected = """@startuml class py2puml.domain.umlclass.UmlAttribute { name: str type: str } class py2puml.domain.umlclass.UmlClass { attributes: List[UmlAttribute] } class py2puml.domain.umlitem.UmlItem { name: str fqdn: str } class py2puml.domain.umlenum.Member { name: str value: str } class py2puml.domain.umlenum.UmlEnum { members: List[Member] } enum py2puml.domain.umlrelation.RelType { COMPOSITION: * INHERITANCE: <| } class py2puml.domain.umlrelation.UmlRelation { source_fqdn: str target_fqdn: str type: RelType } py2puml.domain.umlclass.UmlClass *-- py2puml.domain.umlclass.UmlAttribute py2puml.domain.umlitem.UmlItem <|-- py2puml.domain.umlclass.UmlClass py2puml.domain.umlenum.UmlEnum *-- py2puml.domain.umlenum.Member py2puml.domain.umlitem.UmlItem <|-- py2puml.domain.umlenum.UmlEnum py2puml.domain.umlrelation.UmlRelation *-- py2puml.domain.umlrelation.RelType @enduml """ puml_content = py2puml.py2puml('py2puml/domain', 'py2puml.domain') assert ''.join(puml_content) == expected
from py2puml.py2puml import py2puml # outputs the PlantUML content in the terminal print(''.join(py2puml('py2puml/domain', 'py2puml.domain'))) # writes the PlantUML content in a file with open('py2puml/py2puml.domain.puml', 'w', encoding='utf8') as puml_file: puml_file.writelines(py2puml('py2puml/domain', 'py2puml.domain'))