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 #2 #39

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
44 changes: 22 additions & 22 deletions Python/fitnesse/html_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@

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


class TestType:
SETUP: "SetUp"
TEARDOWN: "TearDown"
Comment on lines +5 to +7
Copy link
Collaborator

Choose a reason for hiding this comment

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

Strictly speaking, it is not wrong to present the different types of tests using a class. However, the use of a dictionary or an enumeration is more lightweight and appropriate in this context.

class HtmlUtil:

@staticmethod
def get_Path(page_name: str, wiki_page: WikiPage):
Copy link
Collaborator

Choose a reason for hiding this comment

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

get_Path seems to be private. Consider putting it beyond the publicly callable function and indicate the intended access-level by an underscore, i.e., _get_path.

inherit_Page: WikiPage = page_crawler.get_inherited_page(page_name, wiki_page)
if inherit_Page is not None:
path: wiki_page.get_page_crawler().get_full_path(setup)
path_name: str = path_parser.render(page_path)
Comment on lines +14 to +15
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using error catching. In both steps sth. different can go wrong.

return path_name
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please consider not returning NULL in case the "inherit_Page" is None (this condition has not been taken care of). Alternatively, you need to account for this scenario when using the function.


@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"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could calculate page_data.has_attribute("Test") on top of the function body, or in a separate function once, as the boolean information is needed a second time (cf. line 32).

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"])
page_path_name = HtmlUtil.get_Path(wiki_page=wiki_page, page_name=SuiteResponder.SUITE_SETUP_NAME)
string_io.writelines(["!include -setup .", page_path_name, "\n"])

setup_path_name = HtmlUtil.get_Path(wiki_page=wiki_page, page_name=TestType.SETUP)
string_io.writelines(["!include -setup .", page_path_name, "\n"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please rework this copy + paste error: this line uses "page_path_name", while the line before declares "setup_path_name"


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"])
tear_down_path_name: str = HtmlUtil.get_Path(wiki_page=wiki_page, page_name=TestType.TEARDOWN)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The arguments are switched. HtmlUtil.get_Path(page_name=TestType.TEARDOWN, wiki_page=wiki_page)

Copy link
Collaborator

Choose a reason for hiding this comment

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

The same applies to the second get_Path call (cf. line 36)

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_path_name: str = HtmlUtil.get_Path(wiki_page=wiki_page, page_name=SuiteResponder.SUITE_TEARDOWN_NAME)
string_io.writelines(["!include -teardown .", page_path_name, "\n"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

As a suggestion: it might be reasonable to join the functionalities of finding a page name and adding it to the io string under one function "_add_pathname_to_io", as this combination is used 4 times.


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


Copy link
Collaborator

Choose a reason for hiding this comment

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

Add only one additional line at the end of the file. It might help to use a linter.