MCPcopy
hub / github.com/flosch/pongo2 / TestBaseDirectory

Function TestBaseDirectory

pongo2_template_test.go:588–617  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

586}
587
588func TestBaseDirectory(t *testing.T) {
589 mustStr := "Hello from template_tests/base_dir_test/"
590
591 fs := pongo2.MustNewLocalFileSystemLoader("")
592 s := pongo2.NewSet("test set with base directory", fs)
593 s.Globals["base_directory"] = "template_tests/base_dir_test/"
594 if err := fs.SetBaseDir(s.Globals["base_directory"].(string)); err != nil {
595 t.Fatal(err)
596 }
597
598 matches, err := filepath.Glob("./template_tests/base_dir_test/subdir/*")
599 if err != nil {
600 t.Fatal(err)
601 }
602 for _, match := range matches {
603 match = strings.Replace(match, fmt.Sprintf("template_tests%cbase_dir_test%c", filepath.Separator, filepath.Separator), "", -1)
604
605 tpl, err := s.FromFile(match)
606 if err != nil {
607 t.Fatal(err)
608 }
609 out, err := tpl.Execute(nil)
610 if err != nil {
611 t.Fatal(err)
612 }
613 if out != mustStr {
614 t.Errorf("%s: out ('%s') != mustStr ('%s')", match, out, mustStr)
615 }
616 }
617}
618
619func BenchmarkCache(b *testing.B) {
620 cacheSet := pongo2.NewSet("cache set", pongo2.MustNewLocalFileSystemLoader(""))

Callers

nothing calls this directly

Calls 3

SetBaseDirMethod · 0.80
FromFileMethod · 0.80
ExecuteMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…