@@ -0,0 +1,2335 @@
+from __future__ import division%0Afrom __future__ import print_function%0A%0Aimport glob%0Aimport os%0Aimport subprocess%0Aimport sys%0Afrom hashlib import sha256%0A%0Aimport pydot_ng as pydot%0A%0APY3 = not sys.version_info %3C (3, 0, 0)%0A%0Aif PY3:%0A    NULL_SEP = b''%0A    xrange = range%0Aelse:%0A    NULL_SEP = ''%0A    bytes = str%0A%0ADOT_BINARY_PATH = pydot.find_graphviz()%5B'dot'%5D%0A%0A%0ATEST_DIR = os.path.dirname(__file__)%0AREGRESSION_TESTS_DIR = os.path.join(TEST_DIR, %22graphs%22)%0AMY_REGRESSION_TESTS_DIR = os.path.join(TEST_DIR, %22my_tests%22)%0A%0ATESTS_DIRS = (%0A    (%22regressions%22, REGRESSION_TESTS_DIR),%0A    (%22my_regressions%22, MY_REGRESSION_TESTS_DIR),%0A)%0A%0A%0Adef list_dots(path):%0A    searchpath = os.path.join(path, %22*.dot%22)%0A    return %5Bf for f in glob.glob(searchpath)%5D%0A%0A%0Adef pytest_generate_tests(metafunc):%0A    idlist = %5B%5D%0A    argvalues = %5B%5D%0A    for name, dir in TESTS_DIRS:%0A        for filepath in list_dots(dir):%0A            filename = os.path.basename(filepath)%0A            idlist.append(%22%7B%7D-%7B%7D%22.format(name, filename))%0A            argvalues.append((filepath,))%0A    metafunc.parametrize(%0A        argnames=%5B%22filepath%22%5D,%0A        argvalues=argvalues,%0A        ids=idlist,%0A        scope=%22function%22,%0A    )%0A%0A%0Adef test_render_and_compare_dot_files(filepath):%0A    def _render_with_graphviz(filename):%0A        p = subprocess.Popen(%0A            (DOT_BINARY_PATH, '-Tjpe'),%0A            cwd=os.path.dirname(filename),%0A            stdin=open(filename, 'rt'),%0A            stderr=subprocess.PIPE, stdout=subprocess.PIPE)%0A%0A        stdout = p.stdout%0A%0A        stdout_output = list()%0A        while True:%0A            data = stdout.read()%0A            if not data:%0A                break%0A            stdout_output.append(data)%0A        stdout.close()%0A%0A        if stdout_output:%0A            stdout_output = NULL_SEP.join(stdout_output)%0A%0A        # this returns a status code we should check%0A        p.wait()%0A%0A        return sha256(stdout_output).hexdigest()%0A%0A    def _render_with_pydot(filename):%0A        g = pydot.graph_from_dot_file(filename)%0A        if not isinstance(g, list):%0A            g = %5Bg%5D%0A        jpe_data = NULL_SEP.join(%5B_g.create(format='jpe') for _g in g%5D)%0A        return sha256(jpe_data).hexdigest()%0A    parsed_data_hexdigest = _render_with_pydot(filepath)%0A    original_data_hexdigest = _render_with_graphviz(filepath)%0A%0A    assert original_data_hexdigest == parsed_data_hexdigest%0A

Add testing regressions of pydot vs graphviz