コード例 #1
0
ファイル: test_io.py プロジェクト: thecapitalistcycle/sismic
    def test_cli(self, capsys):
        filepath = 'docs/examples/elevator/elevator.yaml'
        statechart = import_from_yaml(filepath=filepath)

        # Check default parameters
        cli([filepath])
        out, _ = capsys.readouterr()
        assert export_to_plantuml(statechart) == out.strip()

        # Check all parameters
        cli([
            filepath, '--based-on', 'docs/examples/elevator/elevator.plantuml',
            '--show-description', '--show-preamble', '--show-state-contracts',
            '--show-transition-contracts', '--hide-state-action',
            '--hide-name', '--hide-transition-action'
        ])
        out, _ = capsys.readouterr()
        export = export_to_plantuml(
            statechart,
            based_on_filepath='docs/examples/elevator/elevator.plantuml',
            statechart_description=True,
            statechart_preamble=True,
            state_contracts=True,
            transition_contracts=True,
            state_action=False,
            statechart_name=False,
            transition_action=False)
        assert export == out.strip()
コード例 #2
0
ファイル: test_io.py プロジェクト: thecapitalistcycle/sismic
    def test_export_based_on_filepath(self, elevator):
        filepath = 'docs/examples/elevator/elevator.plantuml'
        statechart = elevator.statechart
        with open(filepath, 'r') as f:
            p1 = f.read()

        assert p1 != export_to_plantuml(statechart)
        assert p1 == export_to_plantuml(statechart, based_on=p1)
        assert p1 == export_to_plantuml(statechart, based_on_filepath=filepath)
コード例 #3
0
ファイル: sismic_viz.py プロジェクト: drorspei/sismic-viz
def main():
    global global_config

    parser = argparse.ArgumentParser()
    parser.add_argument("input_file", type=str, help="Path to input yaml file.")

    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument('-it', '--interactive', action="store_true", dest="interactive",
                       help="Runs input file in a browser.")
    group.add_argument('-o', type=str, dest="output_file", help="Path to output dot file.")

    parser.add_argument('-T', type=str, default="dot", dest="file_type",
                        help="File type for output, if not in interactive mode. "
                             "If dot, produces dot file, others calls dot with \"-T{type}\". "
                             "If in interactive mode, the options are \"dot\" or \"puml\".")

    parser.add_argument("--no-guards", action="store_false", dest="include_guards",
                        help="Don't show transition guards")
    parser.set_defaults(include_guards=True)

    parser.add_argument("--no-actions", action="store_false", dest="include_actions",
                        help="Don't show tranision actions.")
    parser.set_defaults(include_actions=True)

    parser.add_argument("--trans-font-size", type=int, default=14,
                        help="Set font size of text on transitions. Default: 14.")
    args = parser.parse_args()

    if args.interactive:
        global_config["include_guards"] = args.include_guards
        global_config["include_actions"] = args.include_actions
        global_config["edge_fontsize"] = args.trans_font_size
        global_config["file_type"] = args.file_type

        run_interactive(args.input_file)
    else:
        sc = import_from_yaml(filepath=args.input_file)

        if args.file_type == "puml":
            export_to_plantuml(sc, filepath=args.output_file)
        else:
            dot = export_to_dot(sc=sc, include_guards=args.include_guards, include_actions=args.include_actions,
                                edge_fontsize=args.trans_font_size)

            if args.file_type == "dot":
                open(args.output_file, "w").write(dot)
            else:
                with tempfile.NamedTemporaryFile() as f:
                    f.write(dot)
                    f.flush()
                    os.system("dot -T{file_type} {inpath} -o {outpath}".format(file_type=args.file_type, inpath=f.name,
                                                                               outpath=args.output_file))
コード例 #4
0
ファイル: sismic_viz.py プロジェクト: drorspei/sismic-viz
def create_image(statechart, in_states, configuration, imagepath):
    if configuration["file_type"] == "dot":
        with tempfile.NamedTemporaryFile() as f:
            if configuration["file_type"] == "dot":
                output = export_to_dot(statechart,
                                       edge_fontsize=configuration["edge_fontsize"],
                                       include_guards=configuration["include_guards"],
                                       include_actions=configuration["include_actions"],
                                       configuration=in_states)
                f.write(output)
                f.flush()
                open("/tmp/hello.dot", "wb").write(output)
                os.system("dot -Tsvg {inpath} -o {outpath}".format(inpath=f.name, outpath=imagepath))
    else:
        dirname = tempfile.mkdtemp()
        try:
            output = export_to_plantuml(statechart)
            fname = os.path.join(dirname, "graph.puml")
            with open(fname, "wb") as f:
                f.write(output)
                f.flush()
            os.system("plantuml {inpath} -o {outpath} -tsvg".format(inpath=fname, outpath=dirname))
            open(imagefile_path, "wb").write(open(os.path.join(dirname, "graph.svg"), "rb").read())
        finally:
            shutil.rmtree(dirname)
コード例 #5
0
ファイル: test_io.py プロジェクト: thecapitalistcycle/sismic
 def test_export_example_from_docs(self, example_from_docs):
     export = export_to_plantuml(example_from_docs,
                                 statechart_name=True,
                                 statechart_description=True,
                                 statechart_preamble=True,
                                 state_contracts=True,
                                 state_action=True,
                                 transition_contracts=True,
                                 transition_action=True)
     assert len(export) > 0
コード例 #6
0
# sismic-bdd window_lifter.yaml --steps window_lifter_steps.py --features window_lifter.feature

from sismic.io import import_from_yaml, export_to_plantuml
from sismic.model import Statechart

with open('.\\window_lifter.yaml') as f:
    statechart = import_from_yaml(f)
    assert isinstance(statechart, Statechart)
    res = export_to_plantuml(statechart)
    print(res)
コード例 #7
0
#!/usr/bin/env python
from __future__ import print_function

import sys

import sismic.io as sio

if __name__ == "__main__":
    input_path = sys.argv[1]
    chart = sio.import_from_yaml(filepath=input_path)
    print(sio.export_to_plantuml(chart))