File: test_scraper.py

package info (click to toggle)
python-pygraphviz 1.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 732 kB
  • sloc: ansic: 5,100; python: 2,669; makefile: 57
file content (36 lines) | stat: -rw-r--r-- 1,024 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import pytest

import pygraphviz as pgv
from pygraphviz.scraper import _get_sg_image_scraper


def test_scraper(tmpdir):
    pytest.importorskip("sphinx_gallery")
    scraper = _get_sg_image_scraper()

    ### Source
    src_dir = str(tmpdir)
    src_file = os.path.join(src_dir, "simple.py")  # no need for this to exist
    # Create source PNG
    A = pgv.AGraph()
    A.add_edge(1, 2)
    A.layout()
    A.draw(os.path.join(src_dir, "simple.png"))

    ### Target
    out_dir = os.path.join(src_dir, "build", "html")
    os.makedirs(out_dir)
    out_file = os.path.join(out_dir, "simple.png")
    # Target should **not** exist
    assert not os.path.isfile(out_file)
    # Copy source PNG to target location
    block = None
    block_vars = {
        "image_path_iterator": (img for img in [out_file]),
        "src_file": src_file,
    }
    gallery_conf = {"src_dir": src_dir, "builder_name": "html"}
    scraper(block, block_vars, gallery_conf)
    # Target should exist
    assert os.path.isfile(out_file)