Ejemplo n.º 1
0
 def test_error_on_loading_from_nonexistent_section(self):
     assert_raises_with_given_cause(
         MissingConfigSection,
         configparser.NoSectionError,
         NonexistentSectionConfig.from_cfg_file,
         PATH_TO_TEST_CONFIG,
     )
Ejemplo n.º 2
0
 def test_error_on_loading_from_nonexistent_file(self):
     assert_raises_with_given_cause(
         MissingConfig,
         FileNotFoundError,
         BasicConfig.from_cfg_file,
         "./n/o/f/i/l/e/h.ere",
     )
Ejemplo n.º 3
0
    def test_directory_lookup(self):
        """test that hitting an existent directory still raises
        LookupError."""

        assert_raises_with_given_cause(
            exceptions.TopLevelLookupException,
            KeyError,
            tl.get_template,
            "/subdir",
        )
Ejemplo n.º 4
0
 def test_check_not_found(self):
     tl = lookup.TemplateLookup()
     tl.put_string("foo", "this is a template")
     f = tl.get_template("foo")
     assert f.uri in tl._collection
     f.filename = "nonexistent"
     assert_raises_with_given_cause(
         exceptions.TemplateLookupException,
         FileNotFoundError,
         tl.get_template,
         "foo",
     )
     assert f.uri not in tl._collection
Ejemplo n.º 5
0
    def test_checking_against_bad_filetype(self):
        with tempfile.TemporaryDirectory() as tempdir:
            tl = lookup.TemplateLookup(directories=[tempdir])
            index_file = file_with_template_code(
                os.path.join(tempdir, "index.html"))

            with rewind_compile_time():
                tmpl = Template(filename=index_file)

            tl.put_template("index.html", tmpl)

            replace_file_with_dir(index_file)

            assert_raises_with_given_cause(
                exceptions.TemplateLookupException,
                OSError,
                tl._check,
                "index.html",
                tl._collection["index.html"],
            )