Skip to content

Commit a405449

Browse files
committed
Cached the list of template paths in test_runner.py so we can call it multiple times cheaply.
- Legacy-Id: 11482
1 parent a0414be commit a405449

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

ietf/utils/test_runner.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,29 @@ def exclude(name):
147147
res.append((item.regex.pattern, item))
148148
return res
149149

150-
def get_templates(apps=None):
151-
templates = set()
152-
templatepaths = settings.TEMPLATE_DIRS
153-
for templatepath in templatepaths:
154-
for dirpath, dirs, files in os.walk(templatepath):
155-
if ".svn" in dirs:
156-
dirs.remove(".svn")
157-
relative_path = dirpath[len(templatepath)+1:]
158-
for file in files:
159-
if file.endswith("~") or file.startswith("#"):
160-
continue
161-
if relative_path != "":
162-
file = os.path.join(relative_path, file)
163-
templates.add(file)
164-
if apps:
165-
templates = [ t for t in templates if t.split(os.path.sep)[0] in apps ]
166-
return templates
150+
_all_templates = None
151+
def get_template_paths(apps=None):
152+
global _all_templates
153+
if not _all_templates:
154+
# TODO: Add app templates to the full list, if we are using
155+
# django.template.loaders.app_directories.Loader
156+
templates = set()
157+
templatepaths = settings.TEMPLATE_DIRS
158+
for templatepath in templatepaths:
159+
for dirpath, dirs, files in os.walk(templatepath):
160+
if ".svn" in dirs:
161+
dirs.remove(".svn")
162+
relative_path = dirpath[len(templatepath)+1:]
163+
for file in files:
164+
if file.endswith("~") or file.startswith("#"):
165+
continue
166+
if relative_path != "":
167+
file = os.path.join(relative_path, file)
168+
templates.add(file)
169+
if apps:
170+
templates = [ t for t in templates if t.split(os.path.sep)[0] in apps ]
171+
_all_templates = templates
172+
return _all_templates
167173

168174
def save_test_results(failures, test_labels):
169175
# Record the test result in a file, in order to be able to check the
@@ -252,7 +258,7 @@ def template_coverage_test(self):
252258
global loaded_templates
253259
if self.runner.check_coverage:
254260
apps = [ app.split('.')[-1] for app in self.runner.test_apps ]
255-
all = get_templates(apps)
261+
all = get_template_paths(apps)
256262
# The calculations here are slightly complicated by the situation
257263
# that loaded_templates also contain nomcom page templates loaded
258264
# from the database. However, those don't appear in all

0 commit comments

Comments
 (0)