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 #5 #36

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.DS_Store
*/target/
*.iml
*.pyc
Python/.codeseminar
82 changes: 81 additions & 1 deletion Python/fitnesse/html_util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,86 @@
from io import StringIO

from fitnesse.context import SuiteResponder, PageCrawlerImpl, PageData, PathParser, WikiPage, WikiPagePath
from fitnesse.context import (
SuiteResponder,
PageCrawlerImpl,
PageData,
PathParser,
WikiPage,
WikiPagePath,
)


class HtmlProcessData:
page_data: PageData
page_crawler: PageCrawlerImpl
path_parser: PathParser

Copy link
Collaborator

Choose a reason for hiding this comment

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

An additional class of HTML parameters may not be necessary


class HtmlUtil:
@staticmethod
def _suite_action(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This name may not be proper to understand what the function is doing

Copy link
Collaborator

Choose a reason for hiding this comment

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

Overall, I would say that this refactor does not necessarily improve the readability, it only gets rid of the code duplication

wiki_page: WikiPage,
string_io: StringIO,
html_data: HtmlProcessData,
action="SetUp",
):
actions = {
SuiteResponder.SUITE_TEARDOWN_NAME: "teardown",
SuiteResponder.SUITE_SETUP_NAME: "setup",
"SetUp": "setup",
"TearDown": "teardown",
}

action_performed = actions[action]

suite_action: WikiPage = html_data.page_crawler.get_inherited_page(
action_performed, wiki_page
)

if suite_action is not None:
page_path: WikiPagePath = wiki_page.get_page_crawler().get_full_path(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe factor out these few lines into their own function to improve readability, for example "write_page" or similar

suite_action
)
page_path_name: str = html_data.path_parser.render(page_path)
string_io.writelines(
[f"!include -{action_performed} .", page_path_name, "\n"]
)

@staticmethod
def testable_html(html_data: HtmlProcessData, include_suite_setup: bool = True):
wiki_page: WikiPage = html_data.page_data.get_wiki_page()
string_io: StringIO = StringIO()

if html_data.page_data.has_attribute("Test"):
if include_suite_setup:
HtmlUtil._suite_action(
wiki_page,
string_io,
html_data,
action=SuiteResponder.SUITE_SETUP_NAME,
)

HtmlUtil._suite_action(wiki_page, string_io, html_data, action="SetUp")

string_io.writelines([html_data.page_data.get_content()])
Copy link
Author

Choose a reason for hiding this comment

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

Unsure if this writelines needs to be executed here


if html_data.page_data.has_attribute("Test"):
HtmlUtil._suite_action(
wiki_page,
string_io,
html_data,
action=SuiteResponder.SUITE_TEARDOWN_NAME,
)

if include_suite_setup:
HtmlUtil._suite_action(
wiki_page, string_io, html_data, action="TearDown"
)

html_data.page_data.set_content(string_io.getvalue())
return html_data.page_data.get_html()

"""
@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()
Expand Down Expand Up @@ -40,3 +116,7 @@ def testable_html(page_data: PageData, include_suite_setup: bool, page_crawler:

page_data.set_content(string_io.getvalue())
return page_data.get_html()



"""