From 0973661c88e0b2483d6772ba639efcfb8ac16b0d Mon Sep 17 00:00:00 2001 From: denishoornaert Date: Wed, 22 Nov 2023 14:16:44 +0100 Subject: [PATCH] sources: html_util: refactor: worst than before --- Python/fitnesse/html_util.py | 75 ++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/Python/fitnesse/html_util.py b/Python/fitnesse/html_util.py index 38d8590..bd49aca 100644 --- a/Python/fitnesse/html_util.py +++ b/Python/fitnesse/html_util.py @@ -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): + 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) + 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()