How to use the graphviz.files.Source function in graphviz

To help you get started, we’ve selected a few graphviz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xflr6 / graphviz / tests / test_files.py View on Github external
def test_save(mocker, py2, filename='nonfilename', directory='nondirectory'):
    source = Source(**SOURCE)
    makedirs = mocker.patch('os.makedirs', autospec=True)
    open_ = mocker.patch('io.open', mocker.mock_open())

    assert source.save(filename, directory) == source.filepath

    assert source.filename == filename and source.directory == directory
    if py2:
        makedirs.assert_called_once_with(source.directory, 0o777)
    else:
        makedirs.assert_called_once_with(source.directory, 0o777, exist_ok=True)
    open_.assert_called_once_with(source.filepath, 'w',
                                  encoding=source.encoding)
    assert open_.return_value.write.call_args_list == [mocker.call(source.source),
                                                       mocker.call(u'\n')]
github xflr6 / graphviz / tests / test_files.py View on Github external
def source():
    return Source(**SOURCE)
github hayesall / srlearn / tests / tests.py View on Github external
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)
github xflr6 / graphviz / tests / test_files.py View on Github external
def test_init_filename():
    assert Source('').filename == 'Source.gv'
    assert type('Named', (Source,), {'name': 'name'})('').filename == 'name.gv'
github xflr6 / graphviz / graphviz / files.py View on Github external
def __init__(self, source, filename=None, directory=None,
                 format=None, engine=None, encoding=ENCODING):
        super(Source, self).__init__(filename, directory,
                                     format, engine, encoding)
        self.source = source  #: The verbatim DOT source code string.