| 533 | strict=False, |
| 534 | ) |
| 535 | def test_visualize(): |
| 536 | pytest.importorskip("graphviz") |
| 537 | pytest.importorskip("ipycytoscape") |
| 538 | with tmpdir() as d: |
| 539 | x = da.arange(5, chunks=2) |
| 540 | x.visualize(filename=os.path.join(d, "mydask")) |
| 541 | assert os.path.exists(os.path.join(d, "mydask.png")) |
| 542 | |
| 543 | x.visualize(filename=os.path.join(d, "mydask.pdf")) |
| 544 | assert os.path.exists(os.path.join(d, "mydask.pdf")) |
| 545 | |
| 546 | visualize(x, 1, 2, filename=os.path.join(d, "mydask.png")) |
| 547 | assert os.path.exists(os.path.join(d, "mydask.png")) |
| 548 | |
| 549 | dsk = {"a": 1, "b": (add, "a", 2), "c": (mul, "a", 1)} |
| 550 | visualize(x, dsk, filename=os.path.join(d, "mydask.png")) |
| 551 | assert os.path.exists(os.path.join(d, "mydask.png")) |
| 552 | |
| 553 | x = Tuple(dsk, ["a", "b", "c"]) |
| 554 | visualize(x, filename=os.path.join(d, "mydask.png")) |
| 555 | assert os.path.exists(os.path.join(d, "mydask.png")) |
| 556 | |
| 557 | x = Tuple(dsk, ["a", "b", "c"]) |
| 558 | visualize(x, filename=os.path.join(d, "cyt"), engine="cytoscape") |
| 559 | assert os.path.exists(os.path.join(d, "cyt.html")) |
| 560 | |
| 561 | visualize(x, filename=os.path.join(d, "cyt2.html"), engine="ipycytoscape") |
| 562 | assert os.path.exists(os.path.join(d, "cyt2.html")) |
| 563 | |
| 564 | with dask.config.set(visualization__engine="cytoscape"): |
| 565 | visualize(x, filename=os.path.join(d, "cyt3.html")) |
| 566 | assert os.path.exists(os.path.join(d, "cyt3.html")) |
| 567 | |
| 568 | with pytest.raises(ValueError, match="not-real"): |
| 569 | visualize(x, engine="not-real") |
| 570 | |
| 571 | # To see if visualize() works when the filename parameter is set to None |
| 572 | # If the function raises an error, the test will fail |
| 573 | x.visualize(filename=None) |
| 574 | |
| 575 | |
| 576 | @pytest.mark.skipif("not da") |