Implement a XML Review UI that allow user to perform actions on XML files
Review Request #9615 — Created Feb. 10, 2018 and discarded
XML files is handled as an uneditble attachments in the current
version.
I implemented a new classXMLReviewUI
that
enhence Review board's ability to process XML file.Features:
- Smart indentation for the file
- Diff for the file will be shown in render and source formatKnown issues:
- Due to the parser library issue, the XML Render cannot render
the text of an element that are after a child element.
(e.g. <parent>
<child>
</child>
info
</parent> )
info cannot be render in the example above.
Added and ran unit test with:
- Properly formatted XML files (attributes/children).
- Handle Highly-nested XML files.Tested the development environment with:
- File diff system.
- Properly formatted XML files (attributes/children).
- Handle Highly-nested XML files.
Description | From | Last Updated |
---|---|---|
Unlike JSON files, order matters in XML files. For example, imagine this: <h1>This is a section</h1> <p>Some content.</p> <h1>Here's another … |
chipx86 | |
These blank lines should remain. Check our style guide on Notion for where blank lines should go. |
chipx86 | |
Can you add a comment about why the score is 1 here, based on what we've diagnosed? |
chipx86 | |
os is a Python Standard Library module, so it should go in an import group after __future__ but before django. … |
chipx86 | |
"XMLReviewUITests" |
chipx86 | |
No blank line between class and the docstring. We also tend to include the full module path in the docstring … |
chipx86 | |
Helper functions in unit tests should be private (prefix with a _) and put at the end of the class. |
chipx86 | |
Typo, and this doesn't follow our documentation guidelines. |
chipx86 | |
Ideally, we wouldn't include data files, since that makes it harder to have self-contained tests and to provide variations on … |
chipx86 | |
Each component of os.path.join should be a single path entry. No . or /. file_diretory must also be its own … |
chipx86 | |
Blank line between these. |
chipx86 | |
You want as little as possible in this with block. Confine it to the SimpleUploadedFile creation. |
chipx86 | |
Docstrings should be in the form of: """Testing <class>.<method> <condition>""" Like: """Testing XMLReviewUI.get_rendered_lines orders tag results""" Same in other tests. |
chipx86 | |
This is all part of the Python Standard Library, so it should be in the same import group. |
chipx86 | |
Alphabetical order. This would be: from django.utils import six from django.utils.six.moves import ... from django.utils.translation import ... |
chipx86 | |
This is part of the Python Standard Library, and should go in the appropriate import group. |
chipx86 | |
Lines are wrapping way too soon. |
chipx86 | |
This must describe the results of the method (a Yields section). See Notion for info on writing docs. |
chipx86 | |
Blank line between these. |
chipx86 | |
We don't use the inline if .. else .. form. This should be expanded into a standard if/else. |
chipx86 | |
Blank line here. |
chipx86 | |
Blank line here. |
chipx86 | |
Blank line here. |
chipx86 | |
Blank line here. |
chipx86 | |
Blank line here. |
chipx86 | |
Blank line here. |
chipx86 | |
Blank line here. |
chipx86 | |
Blank line here. |
chipx86 | |
Blank line here. |
chipx86 | |
Docstrings must have a single-line summary. IT cnanot wrap. Others are wrapping too soon. |
chipx86 | |
This is going to show up wrong in the docs. If you want to show inline code, use double backticks … |
chipx86 | |
This will need a docstring in our standard format. So will other methods in this class. |
chipx86 | |
Double prefixes should never be used in Python, except for operators (like __eq__) or other special methods (__str__, __repr__). Private … |
chipx86 | |
This needs a docstring. It's also in the wrong casing format. find_attributes would be more correct. |
chipx86 | |
Blank line here. |
chipx86 | |
These can be combined into one conditional. |
chipx86 | |
Blank line here. |
chipx86 | |
This also needs a docstring and should be add_indent. |
chipx86 | |
W291 trailing whitespace |
reviewbot | |
All your testing happens in the get xml file function, but base on the nasme, that should be returning an … |
RO rodgerwa | |
You don't verify if any exceptions are thrown here. Rather than waiting for a KeyError or TypeError when in etree_to_dict, … |
RO rodgerwa | |
I think some of your variable names (like t, dc and dc) could be more descriptive. For example, I'm assuming … |
JT jtrang | |
This docstring should explain the inputs expected and return values. You also need to say what type is expected for … |
RO rodgerwa | |
Add a comment for why len(value) ==1: is important. |
RO rodgerwa | |
Is it possible for strip() to return none? |
RO rodgerwa | |
You have attrib and attrib_in, both of these side by side are a little confusing. Better names are required. |
RO rodgerwa | |
You should add a comment to explain what is happening here. |
RO rodgerwa | |
Similar comment to above. The variable o could have a more descriptive name. |
JT jtrang | |
Along with providing a better name for the variable, you should add what args and kwargs are representing in your … |
RO rodgerwa | |
Considering this is an IO Stream, is there possibility of not having a value by the end or have a … |
RO rodgerwa | |
You'll need to document the expected results and inputs. |
RO rodgerwa | |
Should say Add indention on new line with an indent of the current depth plus one. |
RO rodgerwa | |
what if the wrong type is passed in? |
RO rodgerwa | |
I understand the _ is for localization? How exactly does that lookup work? |
rpolyano | |
Perhaps consider using enums for this and text |
rpolyano | |
Not sure this is needed. Why not call self._fixname directly? |
rpolyano | |
W291 trailing whitespace |
reviewbot | |
It may be more clear if you put key[0] == "text" (or better yet use an enum) and add this … |
rpolyano | |
%s may round things (is this what you want?). Consider using %r if you don't want rounding. Have a look … |
rpolyano |
- Change Summary:
-
I implemented the tag sorting functionality
- Description:
-
XML files is handled as an uneditble attachments in the current
version. I implemented a new class XMLReviewUI
thatenhence Review board's ability to process XML file. + Features:
+ - Attributes will be sorted alphabetically + - Tags from the same parent tag will be sorted alphabetically + - Smart indentation for the file + TODO :
~ sort keys ~ write test files - write test files - handle attribute and message with nested tags
Checks run (2 succeeded)
- Summary:
-
[WIP] Implement a XML Review UI that allow user to perform actions on XML filesImplement a XML Review UI that allow user to perform actions on XML files
- Description:
-
XML files is handled as an uneditble attachments in the current
version. I implemented a new class XMLReviewUI
thatenhence Review board's ability to process XML file. Features:
- Attributes will be sorted alphabetically - Tags from the same parent tag will be sorted alphabetically ~ - Smart indentation for the file ~ ~ - Smart indentation for the file ~ - Diff for the file implemented - TODO :
- write test files - Testing Done:
-
+ Added and ran unit test with:
+ - Properly formatted XML files (attributes/children). + - Handle Highly-nested XML files. + + Tested the development environment with:
+ - File diff system. + - Properly formatted XML files (attributes/children). + - Handle Highly-nested XML files. - Diff:
-
Revision 4 (+220 -4)
Checks run (2 succeeded)
-
-
Unlike JSON files, order matters in XML files. For example, imagine this:
<h1>This is a section</h1> <p>Some content.</p> <h1>Here's another section</h1> <p>More content.</p> <code>Some sample code.</code>
If you order them, then you get:
<code>Some sample code.</code> <h1>This is a section</h1> <h1>Here's another section</h1> <p>Some content.</p> <p>More content.</p>
That doesn't make any sense.
We also shouldn't order attributes. There may be a reason the author has put them that way.
When working with XML, it's good to show the XML in a form that makes it easier to read the document, in a tree form, but we don't want to otherwise alter that content.
-
-
-
os
is a Python Standard Library module, so it should go in an import group after__future__
but beforedjango
. See the style guideline on Notion for import groups. -
-
No blank line between
class
and the docstring.We also tend to include the full module path in the docstring for unit tests, so the full one for XMLReviewUI.
The blank line should go after.
-
-
-
Ideally, we wouldn't include data files, since that makes it harder to have self-contained tests and to provide variations on the tests. It's not even needed in this case, since
SimpleUploadedFile
takes the data directly. This function should take the data, and that should be provided in calls to the method instead of opening a file. -
Each component of
os.path.join
should be a single path entry. No.
or/
.file_diretory
must also be its own parameter -- no concatenation, since that's the point ofos.path.join
. -
-
-
Docstrings should be in the form of:
"""Testing <class>.<method> <condition>"""
Like:
"""Testing XMLReviewUI.get_rendered_lines orders tag results"""
Same in other tests.
-
-
Alphabetical order. This would be:
from django.utils import six from django.utils.six.moves import ... from django.utils.translation import ...
-
-
-
This must describe the results of the method (a
Yields
section). See Notion for info on writing docs. -
-
-
-
-
-
-
-
-
-
-
-
-
This is going to show up wrong in the docs. If you want to show inline code, use double backticks around it.
This format being shown here, though, is a bit confusing, and seems more like an implementation detail. It's better to describe this and then provide an example of a value separately.
-
-
Double prefixes should never be used in Python, except for operators (like
__eq__
) or other special methods (__str__
,__repr__
).Private methods should also go after all public methods.
-
This needs a docstring.
It's also in the wrong casing format.
find_attributes
would be more correct. -
-
-
-
- Description:
-
XML files is handled as an uneditble attachments in the current
version. I implemented a new class XMLReviewUI
thatenhence Review board's ability to process XML file. Features:
- - Attributes will be sorted alphabetically - - Tags from the same parent tag will be sorted alphabetically - Smart indentation for the file ~ - Diff for the file implemented ~ - Diff for the file will be shown in render and source format
- Description:
-
XML files is handled as an uneditble attachments in the current
version. I implemented a new class XMLReviewUI
thatenhence Review board's ability to process XML file. Features:
- Smart indentation for the file - Diff for the file will be shown in render and source format + + Known issues:
+ - Due to the parser library issue, the XML Render cannot render + the text of an element that are after a child element. + (e.g. <parent> + <child> + </child> + info + </parent> ) + info cannot be render in the example above.
Checks run (2 succeeded)
-
I don't have to much insight on what you are working on but I feel that there are a few things you can do to make this part of the code more maintainable and readable for others.
-
All your testing happens in the
get xml file
function, but base on the nasme, that should be returning an xml file of sorts, not testing for nested XML. -
You don't verify if any exceptions are thrown here. Rather than waiting for a
KeyError
orTypeError
when inetree_to_dict
, you should get anIOError
and handle that. -
-
flow is really odd and there are no comments to explain what is happening in each block.
You could use intermediate functions to make it obvious too.
-
This docstring should explain the inputs expected and return values.
You also need to say what type is expected for
t
because it makes the rest of this code a little unclear as we don't know what attributes are guaranteed to exist. -
-
-
-
Why are you creating a new dict and adding t.tag to it? Is there any benefit over adding text to t.tag?
-
-
confusing operation. You are reassigning an input to the return value of a function to which its intial input was the value you are reassigning.
Maybe use an intermediate?
-
You have
attrib
andattrib_in
, both of these side by side are a little confusing. Better names are required. -
-
Along with providing a better name for the variable, you should add what
args
andkwargs
are representing in your docstring. -
Considering this is an IO Stream, is there possibility of not having a value by the end or have a possible IO error?
-
-
-
-
-
-
-
-
-
-
It may be more clear if you put
key[0] == "text"
(or better yet use an enum) and add this as anand
clause to theif
above it to reduce nesting -
%s
may round things (is this what you want?). Consider using%r
if you don't want rounding. Have a look at this blog post for some more info.