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

Group #3 #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
75 changes: 42 additions & 33 deletions Python/fitnesse/html_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,47 @@

class HtmlUtil:

# Should everything remain static?
_wiki_page = WikiPage # Temp
_page_data = PageData() # Cannot instantiate abstract class... needed for exercise...
_string_io = StringIO() # Temp

# string_io and wiki_page could be attributes of the class...
@staticmethod
def whatever_this_does(page_crawler, suit_responder, path_parser, phase_type):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more suitable method name would be appropriate 😛

suite_setup: WikiPage = page_crawler.get_inherited_page(suit_responder, HtmlUtil._wiki_page)
if (suite_setup is not None):
page_path: WikiPagePath = HtmlUtil._wiki_page.get_page_crawler().get_full_path(suite_setup)
page_path_name: str = path_parser.render(page_path)
HtmlUtil._string_io.writelines([f"!include -{phase_type} .", page_path_name, "\n"])


@staticmethod
def setup_phase(include_suite_setup, page_crawler, path_parser):
if (HtmlUtil._page_data.has_attribute("Test")):
if (include_suite_setup):
HtmlUtil.whatever_this_does(page_crawler, SuiteResponder.SUITE_SETUP_NAME, path_parser, "setup")
HtmlUtil.whatever_this_does(page_crawler, "SetUp", path_parser, "setup")


@staticmethod
def teardown_phase(include_suite_setup, page_crawler, path_parser):
if (HtmlUtil._page_data.has_attribute("Test")):
HtmlUtil.whatever_this_does(page_crawler, "TearDown", path_parser, "teardown")
if (include_suite_setup):
HtmlUtil.whatever_this_does(page_crawler, SuiteResponder.SUITE_TEARDOWN_NAME, path_parser, "teardown")


@staticmethod
def testable_html(page_data: PageData, include_suite_setup: bool, page_crawler: PageCrawlerImpl, path_parser: PathParser) -> str:
wiki_page: WikiPage = page_data.get_wiki_page()
string_io: StringIO = StringIO()

if page_data.has_attribute("Test"):
if include_suite_setup:
suite_setup: WikiPage = page_crawler.get_inherited_page(SuiteResponder.SUITE_SETUP_NAME, wiki_page)
if suite_setup is not None:
page_path: WikiPagePath = wiki_page.get_page_crawler().get_full_path(suite_setup)
page_path_name: str = path_parser.render(page_path)
string_io.writelines(["!include -setup .", page_path_name, "\n"])

setup: WikiPage = page_crawler.get_inherited_page("SetUp", wiki_page)
if setup is not None:
setup_path: WikiPagePath = wiki_page.get_page_crawler().get_full_path(setup)
setup_path_name: str = path_parser.render(setup_path)
string_io.writelines(["!include -setup .", setup_path_name, "\n"])

string_io.writelines([page_data.get_content()])
if page_data.has_attribute("Test"):
teardown: WikiPage = page_crawler.get_inherited_page("TearDown", wiki_page)
if teardown is not None:
tear_down_path: WikiPagePath = wiki_page.get_page_crawler().get_full_path(teardown)
tear_down_path_name: str = path_parser.render(tear_down_path)
string_io.writelines(["!include -teardown .", tear_down_path_name, "\n"])
if include_suite_setup:
suite_teardown: WikiPage = page_crawler.get_inherited_page(SuiteResponder.SUITE_TEARDOWN_NAME, wiki_page)
if suite_teardown is not None:
page_path: WikiPagePath = wiki_page.get_page_crawler().get_full_path(suite_teardown)
page_path_name: str = path_parser.render(page_path)
string_io.writelines(["!include -teardown .", page_path_name, "\n"])

page_data.set_content(string_io.getvalue())
return page_data.get_html()
# Temporarily setup static varilables (assumed overwritten each time)
HtmlUtil._wiki_page = page_data.get_wiki_page()
HtmlUtil._page_data = page_data
HtmlUtil._string_io = StringIO()

HtmlUtil.setup_phase(include_suite_setup, page_crawler, path_parser)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

HtmlUtil._string_io.writelines([HtmlUtil._page_data.get_content()])
HtmlUtil.teardown_phase(include_suite_setup, page_crawler, path_parser)

HtmlUtil._page_data.set_content(HtmlUtil._string_io.getvalue())
return HtmlUtil._page_data.get_html()