Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated --template name and help. #266

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/feditest/cli/commands/convert_transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from feditest.utils import FEDITEST_VERSION

DEFAULT_TEMPLATE = 'default'
DEFAULT_TEMPLATE_PATH = "default"

def run(parser: ArgumentParser, args: Namespace, remaining: list[str]) -> int:
"""
Expand All @@ -32,7 +32,7 @@ def run(parser: ArgumentParser, args: Namespace, remaining: list[str]) -> int:
serializer.write(args.tap)

if isinstance(args.html, str) or args.html:
multifile_serializer = MultifileRunTranscriptSerializer(args.html, args.template)
multifile_serializer = MultifileRunTranscriptSerializer(args.html, args.template_path)
multifile_serializer.write(transcript)

if isinstance(args.json, str) or args.json:
Expand All @@ -59,8 +59,8 @@ def add_sub_parser(parent_parser: _SubParsersAction, cmd_name: str) -> None:
html_group = parser.add_argument_group('html', 'HTML options')
html_group.add_argument('--html',
help="Write results in HTML format to the provided file.")
html_group.add_argument('--template', default=DEFAULT_TEMPLATE,
help=f"When specifying --html, use this template (defaults to '{ DEFAULT_TEMPLATE }').")
html_group.add_argument('--template-path', default=DEFAULT_TEMPLATE_PATH,
help="When specifying --html, use this template path override (comma separated directory names)")
parser.add_argument('--json', nargs="?", const=True, default=False,
help="Write results in JSON format to stdout, or to the provided file (if given).")
parser.add_argument('--summary', nargs="?", const=True, default=False,
Expand Down
41 changes: 25 additions & 16 deletions src/feditest/testruntranscript.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from abc import ABC, abstractmethod
from datetime import datetime
import contextlib
import json
import os
import os.path
import re
import shutil
import sys
import traceback
from abc import ABC, abstractmethod
from datetime import datetime
from typing import IO, Iterator, Optional

import jinja2
Expand Down Expand Up @@ -543,20 +544,28 @@ def session_file_path(plan_session):
len=len
)

with open(self.matrix_file, "w") as fp:
matrix_template = jinja2_env.get_template("test_matrix.jinja2")
fp.write(matrix_template.render(**context))

session_template = jinja2_env.get_template("test_session.jinja2")
for run_session in transcript.sessions:
session_context = dict(context)
session_context.update(
run_session=run_session,
summary=run_session.build_summary(),
)
plan_session = transcript.plan.sessions[run_session.plan_session_index]
with open(os.path.join(dir, session_file_path(plan_session)), "w" ) as fp:
fp.write(session_template.render(**session_context))
try:
with open(self.matrix_file, "w") as fp:
matrix_template = jinja2_env.get_template("test_matrix.jinja2")
fp.write(matrix_template.render(**context))

session_template = jinja2_env.get_template("test_session.jinja2")
for run_session in transcript.sessions:
session_context = dict(context)
session_context.update(
run_session=run_session,
summary=run_session.build_summary(),
)
plan_session = transcript.plan.sessions[run_session.plan_session_index]
with open(os.path.join(dir, session_file_path(plan_session)), "w" ) as fp:
fp.write(session_template.render(**session_context))
except jinja2.exceptions.TemplateNotFound as ex:
with contextlib.redirect_stdout(sys.stderr):
print(f"ERROR: template '{ex}' not found")
print("Searched in the following directories:")
for entry in self.template_path:
print(f" {entry}")
sys.exit(1)


def _init_jinja2_env(self) -> jinja2.Environment:
Expand Down