Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tutte [label="TUTTE HERMSGERVORDENBROTBORDA"]
"M00se" -- trained_by
trained_by -- tutte
}
>>> dot.view('test-output/m00se.gv') # doctest: +SKIP
'test-output/m00se.gv.pdf'
"""
from . import lang
from . import files
__all__ = ['Graph', 'Digraph']
class Dot(files.File):
"""Assemble, save, and render DOT source code, open result in viewer."""
_comment = '// %s'
_subgraph = 'subgraph %s{'
_subgraph_plain = '%s{'
_node = _attr = '\t%s%s'
_attr_plain = _attr % ('%s', '')
_tail = '}'
_quote = staticmethod(lang.quote)
_quote_edge = staticmethod(lang.quote_edge)
_a_list = staticmethod(lang.a_list)
_attr_list = staticmethod(lang.attr_list)
def __init__(self, name=None, comment=None,
# Do the trees exist? Does 'cancer' appear in tree0?
self.assertTrue(isinstance(model.tree(0, 'cancer'), str))
self.assertTrue(isinstance(model.tree(1, 'cancer'), str))
self.assertTrue(isinstance(model.tree(2, 'cancer'), str))
self.assertTrue(isinstance(model.tree(3, 'cancer'), str))
self.assertTrue(isinstance(model.tree(4, 'cancer'), str))
self.assertTrue(isinstance(model.tree(5, 'cancer'), str))
self.assertTrue(isinstance(model.tree(6, 'cancer'), str))
self.assertTrue(isinstance(model.tree(7, 'cancer'), str))
self.assertTrue(isinstance(model.tree(8, 'cancer'), str))
self.assertTrue(isinstance(model.tree(9, 'cancer'), str))
self.assertTrue('cancer' in model.tree(0, 'cancer'))
# Can the tree be converted to an image?
#import graphviz
self.assertTrue(isinstance(model.tree(0, 'cancer', image=True), graphviz.files.Source))
self.assertTrue(isinstance(model.tree(1, 'cancer', image=True), graphviz.files.Source))
self.assertTrue(isinstance(model.tree(2, 'cancer', image=True), graphviz.files.Source))
self.assertTrue(isinstance(model.tree(3, 'cancer', image=True), graphviz.files.Source))
self.assertTrue(isinstance(model.tree(9, 'cancer', image=True), graphviz.files.Source))
# Does training time return either a float or an int?
self.assertTrue(isinstance(model.traintime(), float))
self.assertEqual(model._training_time_to_float(['1', 'milliseconds']), 0.001)
self.assertEqual(model._training_time_to_float(['1', 'days', '981', 'milliseconds']), 86400.981)
self.assertEqual(model._training_time_to_float(['2', 'hours', '1', 'minutes', '25', 'seconds', '120', 'milliseconds']), 7285.12)
self.assertTrue(isinstance(model.tree(0, 'cancer'), str))
self.assertTrue(isinstance(model.tree(1, 'cancer'), str))
self.assertTrue(isinstance(model.tree(2, 'cancer'), str))
self.assertTrue(isinstance(model.tree(3, 'cancer'), str))
self.assertTrue(isinstance(model.tree(4, 'cancer'), str))
self.assertTrue(isinstance(model.tree(5, 'cancer'), str))
self.assertTrue(isinstance(model.tree(6, 'cancer'), str))
self.assertTrue(isinstance(model.tree(7, 'cancer'), str))
self.assertTrue(isinstance(model.tree(8, 'cancer'), str))
self.assertTrue(isinstance(model.tree(9, 'cancer'), str))
self.assertTrue('cancer' in model.tree(0, 'cancer'))
# Can the tree be converted to an image?
#import graphviz
self.assertTrue(isinstance(model.tree(0, 'cancer', image=True), graphviz.files.Source))
self.assertTrue(isinstance(model.tree(1, 'cancer', image=True), graphviz.files.Source))
self.assertTrue(isinstance(model.tree(2, 'cancer', image=True), graphviz.files.Source))
self.assertTrue(isinstance(model.tree(3, 'cancer', image=True), graphviz.files.Source))
self.assertTrue(isinstance(model.tree(9, 'cancer', image=True), graphviz.files.Source))
# Does training time return either a float or an int?
self.assertTrue(isinstance(model.traintime(), float))
self.assertEqual(model._training_time_to_float(['1', 'milliseconds']), 0.001)
self.assertEqual(model._training_time_to_float(['1', 'days', '981', 'milliseconds']), 86400.981)
self.assertEqual(model._training_time_to_float(['2', 'hours', '1', 'minutes', '25', 'seconds', '120', 'milliseconds']), 7285.12)
'--dot-directory',
'-d',
help="Where to write out .dot files.",
default=".h2_visualize"
)
argument_parser.add_argument(
'--image-directory',
'-i',
help="Where to write out image files.",
default=".h2_visualize"
)
argument_parser.add_argument(
'--image-type',
'-t',
help="The image format.",
choices=graphviz.files.FORMATS,
default='png'
)
argument_parser.add_argument(
'--view',
'-v',
help="View rendered graphs with default image viewer",
default=False,
action="store_true"
)
args = argument_parser.parse_args(argv)
explicitly_save_dot = (
args.dot_directory and (
not args.image_directory or
args.image_directory != args.dot_directory
)
def __init__(self, name=None, comment=None,
filename=None, directory=None,
format=None, engine=None, encoding=files.ENCODING,
graph_attr=None, node_attr=None, edge_attr=None, body=None,
strict=False):
self.name = name
self.comment = comment
super(Dot, self).__init__(filename, directory, format, engine, encoding)
self.graph_attr = dict(graph_attr) if graph_attr is not None else {}
self.node_attr = dict(node_attr) if node_attr is not None else {}
self.edge_attr = dict(edge_attr) if edge_attr is not None else {}
self.body = list(body) if body is not None else []
self.strict = strict
argumentParser.add_argument('fqpn',
help="A Fully Qualified Path name"
" representing where to find machines.")
argumentParser.add_argument('--quiet', '-q',
help="suppress output",
default=False,
action="store_true")
argumentParser.add_argument('--dot-directory', '-d',
help="Where to write out .dot files.",
default=".automat_visualize")
argumentParser.add_argument('--image-directory', '-i',
help="Where to write out image files.",
default=".automat_visualize")
argumentParser.add_argument('--image-type', '-t',
help="The image format.",
choices=graphviz.files.FORMATS,
default='png')
argumentParser.add_argument('--view', '-v',
help="View rendered graphs with"
" default image viewer",
default=False,
action="store_true")
args = argumentParser.parse_args(_argv)
explicitlySaveDot = (args.dot_directory
and (not args.image_directory
or args.image_directory != args.dot_directory))
if args.quiet:
def _print(*args):
pass
for fqpn, machine in _findMachines(args.fqpn):