Skip to content

Added option to append one or more user-provided style sheets to report's styling. #150

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

Closed

Conversation

i-am-david-fernandez
Copy link
Contributor

Caveat: this is my first pull request, so opening apologies if I've not done things correctly. Constructive criticism on anything is welcome.

I'm not sure if I've approached the error reporting (failure to read user-supplied CSS file) appropriately, so feel free to alter that.

The approach I've taken allows multiple user-supplied CSS files to be added in the order specified. Perhaps this isn't necessary, but the difference is near trivial, and it provides quite a good increase in flexibility for essentially no cost. It may be useful if a team wants to apply something like business and team/project/client styling.

Copy link
Collaborator

@davehunt davehunt left a comment

Choose a reason for hiding this comment

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

I'm really sorry for not looking at this earlier. Thank you so much for submitting this patch! As you suggest in your description, I think the error handling could be improved, but otherwise I think this is awesome! Let me know if I can provide any additional help.

@@ -55,6 +55,9 @@ def pytest_addoption(parser):
'that the report may not render or function where CSP '
'restrictions are in place (see '
'https://developer.mozilla.org/docs/Web/Security/CSP)')
group.addoption('--append-css', action='append', dest='appendcss',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we name this simply '--css' and leave the default dest of 'css'?

@@ -129,7 +135,7 @@ def __init__(self, outcome, report, logfile, config):
if len(cells) > 0:
self.row_table = html.tr(cells)
self.row_extra = html.tr(html.td(self.additional_html,
class_='extra', colspan=len(cells)))
class_='extra', colspan=len(cells)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: This change makes the line too long for PEP8.

@@ -321,6 +327,21 @@ def _generate_report(self, session):
ansi_css.extend([str(r) for r in style.get_styles()])
self.style_css += '\n'.join(ansi_css)

# <DF> Add user-provided CSS
if self.css_append:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe if we're using append, then the default should be an empty list. If so, we shouldn't need this check and could just do for path in self.css:

user_css.extend(css_file.readlines())
user_css.append('/* End CSS from {} */'.format(filename))
except Exception as e:
self.css_errors.append('Warning: Could not read CSS from {}: {}'.format(filename, e))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than gathering bare exceptions for later reporting, I think we should check that the paths are valid before w run any tests. This can be done in pytest_addoption or pytest_configure. Otherwise, a typo in any CSS path would not be known until the test session is complete, which could be frustrating if the tests take a long time to run.

except Exception as e:
self.css_errors.append('Warning: Could not read CSS from {}: {}'.format(filename, e))

self.style_css += '\n'.join(user_css)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it makes sense to keep the CSS files separate instead of appending to a single file. We don't have a choice for the self-contained report, but it might help to keep the assets based report more manageble. We can always revisit this later though.

@davehunt
Copy link
Collaborator

In addition to my review comments, could you look into getting this passing the flake8 checks? You can run them locally using tox -e flake8. Also, if you could add tests and documentation for the new feature that would be great! If not, I can take care of these.

@davehunt
Copy link
Collaborator

davehunt commented Apr 5, 2018

Thanks again @i-am-david-fernandez for kicking this off. I've addressed my comments, and will now close this in favour of #156, which includes your valued contribution!

@davehunt davehunt closed this Apr 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants