File: test_utils_template.py

package info (click to toggle)
python-scrapy 2.13.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,664 kB
  • sloc: python: 52,028; xml: 199; makefile: 25; sh: 7
file content (22 lines) | stat: -rw-r--r-- 839 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from scrapy.utils.template import render_templatefile


class TestUtilsRenderTemplateFile:
    def test_simple_render(self, tmp_path):
        context = {"project_name": "proj", "name": "spi", "classname": "TheSpider"}
        template = "from ${project_name}.spiders.${name} import ${classname}"
        rendered = "from proj.spiders.spi import TheSpider"

        template_path = tmp_path / "templ.py.tmpl"
        render_path = tmp_path / "templ.py"

        template_path.write_text(template, encoding="utf8")
        assert template_path.is_file()  # Failure of test itself

        render_templatefile(template_path, **context)

        assert not template_path.exists()
        assert render_path.read_text(encoding="utf8") == rendered

        render_path.unlink()
        assert not render_path.exists()  # Failure of test itself