Skip to content

Commit fec56e3

Browse files
committed
[chore] format docstrings
Only change the format. The content stay the same and may not be accurate. Part-of: #66
1 parent b41b731 commit fec56e3

File tree

10 files changed

+75
-96
lines changed

10 files changed

+75
-96
lines changed

src/testing.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626

2727
def parametrize(argvalues):
2828
"""
29+
Parametrize a test function.
30+
2931
Decorator for UnitTestCase test functions to parametrize the decorated test.
32+
3033
Usage:
3134
```python
3235
@parametrize([
@@ -251,6 +254,7 @@ def get_previous_major(major, minor):
251254
class UpgradeCase(UpgradeCommon, _create_meta(10, "upgrade_case")):
252255
"""
253256
Test case to modify data in origin version, and assert in target version.
257+
254258
User must define a "prepare" and a "check" method.
255259
- prepare method can write in database, return value will be stored in a dedicated table and
256260
passed as argument to check.
@@ -282,7 +286,8 @@ def test_prepare(self):
282286
# pylint: disable=inherit-non-class
283287
class IntegrityCase(UpgradeCommon, _create_meta(20, "integrity_case")):
284288
"""
285-
Test case to check invariant through any version
289+
Test case to check invariant through any version.
290+
286291
User must define a "invariant" method.
287292
invariant return value will be compared between the two version.
288293

src/util/convert_bootstrap.py

Lines changed: 41 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Convert an XML/HTML document Bootstrap code from an older version to a newer one.
3-
"""
1+
"""Convert an XML/HTML document Bootstrap code from an older version to a newer one."""
42

53
import logging
64
import os.path
@@ -29,7 +27,7 @@
2927

3028

3129
def _xpath_has_class(context, *cls):
32-
"""Extension function for xpath to check if the context node has all the classes passed as arguments"""
30+
"""Extension function for xpath to check if the context node has all the classes passed as arguments."""
3331
node_classes = set(context.context_node.attrib.get("class", "").split())
3432
return node_classes.issuperset(cls)
3533

@@ -49,10 +47,7 @@ def _xpath_has_t_class_inner(attrs_values, classes):
4947

5048

5149
def _xpath_has_t_class(context, *cls):
52-
"""
53-
Extension function for xpath to check if the context node has all the classes passed as arguments
54-
in one of ``class`` or ``t-att(f)-class`` attributes.
55-
"""
50+
"""Extension function for xpath to check if the context node has all the classes passed as arguments in one of ``class`` or ``t-att(f)-class`` attributes."""
5651
return _xpath_has_class(context, *cls) or _xpath_has_t_class_inner(
5752
tuple(map(context.context_node.attrib.get, ("t-att-class", "t-attf-class"))), cls
5853
)
@@ -65,7 +60,7 @@ def _xpath_regex_inner(pattern, item):
6560

6661

6762
def _xpath_regex(context, item, pattern):
68-
"""Extension function for xpath to check if the passed item (attribute or text) matches the passed regex pattern"""
63+
"""Extension function for xpath to check if the passed item (attribute or text) matches the passed regex pattern."""
6964
if not item:
7065
return False
7166
if isinstance(item, list):
@@ -84,7 +79,7 @@ def _xpath_regex(context, item, pattern):
8479

8580
def innerxml(element, is_html=False):
8681
"""
87-
Returns the inner XML of an element as a string.
82+
Return the inner XML of an element as a string.
8883
8984
:param etree.ElementBase element: the element to convert.
9085
:param bool is_html: whether to use HTML for serialization, XML otherwise. Defaults to False.
@@ -96,23 +91,24 @@ def innerxml(element, is_html=False):
9691

9792

9893
def split_classes(*joined_classes):
99-
"""Returns a list of classes given one or more strings of joined classes separated by spaces"""
94+
"""Return a list of classes given one or more strings of joined classes separated by spaces."""
10095
return [c for classes in joined_classes for c in (classes or "").split(" ") if c]
10196

10297

10398
def get_classes(element):
104-
"""Returns the list of classes from the ``class`` attribute of an element"""
99+
"""Return the list of classes from the ``class`` attribute of an element."""
105100
return split_classes(element.get("class", ""))
106101

107102

108103
def join_classes(classes):
109-
"""Returns a string of classes joined by space given a list of classes"""
104+
"""Return a string of classes joined by space given a list of classes."""
110105
return " ".join(classes)
111106

112107

113108
def set_classes(element, classes):
114109
"""
115-
Sets the ``class`` attribute of an element from a list of classes.
110+
Set the ``class`` attribute of an element from a list of classes.
111+
116112
If the list is empty, the attribute is removed.
117113
"""
118114
if classes:
@@ -123,7 +119,7 @@ def set_classes(element, classes):
123119

124120
def edit_classlist(classes, add, remove):
125121
"""
126-
Helper function to edit a class list, adding and removing classes.
122+
Edit a class list, adding and removing classes.
127123
128124
:param str | typing.List[str] classes: the original classes list or str to edit.
129125
:param str | typing.Iterable[str] | None add: if specified, adds the given class(es) to the list.
@@ -161,8 +157,7 @@ def edit_classlist(classes, add, remove):
161157

162158
def edit_element_t_classes(element, add, remove):
163159
"""
164-
Helper function to edit inplace qweb ``t-att-class`` and ``t-attf-class`` attributes of an element,
165-
adding and removing the specified classes.
160+
Edit inplace qweb ``t-att-class`` and ``t-attf-class`` attributes of an element, adding and removing the specified classes.
166161
167162
N.B. adding new classes will not work if neither ``t-att-class`` nor ``t-attf-class`` are present.
168163
@@ -222,7 +217,7 @@ def edit_element_t_classes(element, add, remove):
222217

223218
def edit_element_classes(element, add, remove, is_qweb=False):
224219
"""
225-
Helper function to edit inplace the "class" attribute of an element, adding and removing classes.
220+
Edit inplace the "class" attribute of an element, adding and removing classes.
226221
227222
:param etree.ElementBase element: the element to edit.
228223
:param str | typing.Iterable[str] | None add: if specified, adds the given class(es) to the element.
@@ -243,7 +238,8 @@ def edit_element_classes(element, add, remove, is_qweb=False):
243238

244239
def simple_css_selector_to_xpath(selector, prefix="//"):
245240
"""
246-
Converts a basic CSS selector cases to an XPath expression.
241+
Convert a basic CSS selector cases to an XPath expression.
242+
247243
Supports node names, classes, ``>`` and ``,`` combinators.
248244
249245
:param str selector: the CSS selector to convert.
@@ -313,13 +309,11 @@ def adapt_xpath_for_qweb(xpath):
313309

314310

315311
class ElementOperation:
316-
"""
317-
Abstract base class for defining operations to be applied on etree elements.
318-
"""
312+
"""Abstract base class for defining operations to be applied on etree elements."""
319313

320314
def __call__(self, element, converter):
321315
"""
322-
Performs the operation on the given element.
316+
Perform the operation on the given element.
323317
324318
Abstract method that must be implemented by subclasses.
325319
@@ -343,8 +337,7 @@ def xpath(self, xpath=None):
343337
@classmethod
344338
def op(cls, *args, xpath=None, **kwargs):
345339
"""
346-
Creates a definition of an operation with the given arguments, and returns
347-
a tuple of (xpath, operations list) that can be used in the converter definition list.
340+
Create a definition of an operation with the given arguments, and returns a tuple of (xpath, operations list) that can be used in the converter definition list.
348341
349342
:param typing.Any args: positional arguments to pass to the operation :meth:`~.__init__`.
350343
:param typing.Any kwargs: keyword arguments to pass to the operation :meth:`~.__init__`.
@@ -356,9 +349,7 @@ def op(cls, *args, xpath=None, **kwargs):
356349

357350

358351
class RemoveElement(ElementOperation):
359-
"""
360-
Removes the matched element(s) from the document.
361-
"""
352+
"""Remove the matched element(s) from the document."""
362353

363354
def __call__(self, element, converter):
364355
parent = element.getparent()
@@ -369,7 +360,7 @@ def __call__(self, element, converter):
369360

370361
class EditClasses(ElementOperation):
371362
"""
372-
Adds and/or removes classes.
363+
Add and/or remove classes.
373364
374365
:param str | typing.Iterable[str] | None add: classes to add to the elements.
375366
:param str | typing.Iterable[str] | ALL | None remove: classes to remove from the elements.
@@ -411,10 +402,6 @@ def xpath(self, xpath=None):
411402

412403

413404
class AddClasses(EditClasses):
414-
"""
415-
Adds classes.
416-
"""
417-
418405
def __init__(self, *classes):
419406
super().__init__(add=classes)
420407

@@ -423,7 +410,7 @@ def __init__(self, *classes):
423410

424411
class RemoveClasses(EditClasses):
425412
"""
426-
Removes classes.
413+
Remove classes.
427414
428415
N.B. no checks are made to ensure the class(es) to remove are actually present on the elements.
429416
"""
@@ -434,7 +421,7 @@ def __init__(self, *classes):
434421

435422
class ReplaceClasses(EditClasses):
436423
"""
437-
Replaces old classes with new ones.
424+
Replace old classes with new ones.
438425
439426
:param str | typing.Iterable[str] | ALL old: classes to remove from the elements.
440427
:param str | typing.Iterable[str] | None new: classes to add to the elements.
@@ -448,10 +435,10 @@ def __init__(self, old, new):
448435

449436
class PullUp(ElementOperation):
450437
"""
451-
Pulls up the element's children to the parent element, then removes the original element.
438+
Pull up the element's children to the parent element, then removes the original element.
452439
453440
Example:
454-
441+
-------
455442
before::
456443
.. code-block:: html
457444
@@ -484,9 +471,7 @@ def __call__(self, element, converter):
484471

485472

486473
class RenameAttribute(ElementOperation):
487-
"""
488-
Renames an attribute. Silently ignores elements that do not have the attribute.
489-
"""
474+
"""Rename an attribute. Silently ignores elements that do not have the attribute."""
490475

491476
def __init__(self, old_name, new_name, extra_xpath=""):
492477
self.old_name = old_name
@@ -567,9 +552,7 @@ def __init__(self, pattern, sub, attr="class"):
567552

568553

569554
class BS3to4ConvertBlockquote(ElementOperation):
570-
"""
571-
Converts a BS3 ``<blockquote>`` element to a BS4 ``<div>`` element with the ``blockquote`` class.
572-
"""
555+
"""Convert a BS3 ``<blockquote>`` element to a BS4 ``<div>`` element with the ``blockquote`` class."""
573556

574557
def __call__(self, element, converter):
575558
blockquote = converter.copy_element(element, tag="div", add_classes="blockquote", copy_attrs=False)
@@ -581,7 +564,8 @@ def __call__(self, element, converter):
581564
# TODO abt: merge MakeCard and ConvertCard into one operation class
582565
class BS3to4MakeCard(ElementOperation):
583566
"""
584-
Pre-processes a BS3 panel, thumbnail, or well element to be converted to a BS4 card.
567+
Pre-processe a BS3 panel, thumbnail, or well element to be converted to a BS4 card.
568+
585569
Card components conversion is then handled by the ``ConvertCard`` operation class.
586570
"""
587571

@@ -598,9 +582,7 @@ def __call__(self, element, converter):
598582

599583
# TODO abt: refactor code
600584
class BS3to4ConvertCard(ElementOperation):
601-
"""
602-
Fully converts a BS3 panel, thumbnail, or well element and their contents to a BS4 card.
603-
"""
585+
"""Fully convert a BS3 panel, thumbnail, or well element and their contents to a BS4 card."""
604586

605587
POST_CONVERSIONS = {
606588
"title": ["card-title"],
@@ -682,7 +664,8 @@ def __call__(self, element, converter):
682664

683665
class BS4to5ConvertCloseButton(ElementOperation):
684666
"""
685-
Converts BS4 ``button.close`` elements to BS5 ``button.btn-close``.
667+
Convert BS4 ``button.close`` elements to BS5 ``button.btn-close``.
668+
686669
Also fixes the ``data-dismiss`` attribute to ``data-bs-dismiss``, and removes any inner contents.
687670
"""
688671

@@ -700,9 +683,7 @@ def __call__(self, element, converter):
700683

701684

702685
class BS4to5ConvertCardDeck(ElementOperation):
703-
"""
704-
Converts BS4 ``.card-deck`` elements to grid components (``.row``, ``.col``, etc.).
705-
"""
686+
"""Convert BS4 ``.card-deck`` elements to grid components (``.row``, ``.col``, etc.)."""
706687

707688
def __call__(self, element, converter):
708689
cards = element.xpath(converter.adapt_xpath("./*[hasclass('card')]"))
@@ -719,9 +700,7 @@ def __call__(self, element, converter):
719700

720701

721702
class BS4to5ConvertFormInline(ElementOperation):
722-
"""
723-
Converts BS4 ``.form-inline`` elements to grid components (``.row``, ``.col``, etc.).
724-
"""
703+
"""Convert BS4 ``.form-inline`` elements to grid components (``.row``, ``.col``, etc.)."""
725704

726705
def __call__(self, element, converter):
727706
edit_element_classes(element, add="row row-cols-lg-auto", remove="form-inline", is_qweb=converter.is_qweb)
@@ -990,8 +969,7 @@ def get_conversions(cls, src_ver, dst_ver, is_qweb=False):
990969

991970
def convert(self, src_version, dst_version):
992971
"""
993-
Converts the loaded document inplace from the source version to the destination,
994-
returning the converted document and the number of conversion operations applied.
972+
Convert the loaded document inplace from the source version to the destination, returning the converted document and the number of conversion operations applied.
995973
996974
:param str src_version: the source Bootstrap version.
997975
:param str dst_version: the destination Bootstrap version.
@@ -1064,7 +1042,8 @@ def convert_file(cls, path, src_version, dst_version, is_html=None, **converter_
10641042

10651043
def element_factory(self, *args, **kwargs):
10661044
"""
1067-
Helper method to be used by operation for creating new elements using the correct document type.
1045+
Create new elements using the correct document type.
1046+
10681047
Basically a wrapper for either etree.XML or etree.HTML depending on the type of document loaded.
10691048
10701049
:param args: positional arguments to pass to the etree.XML or etree.HTML function.
@@ -1075,7 +1054,8 @@ def element_factory(self, *args, **kwargs):
10751054

10761055
def build_element(self, tag, classes=None, contents=None, **attributes):
10771056
"""
1078-
Helper method to create a new element with the given tag, classes, contents and attributes.
1057+
Create a new element with the given tag, classes, contents and attributes.
1058+
10791059
Like :meth:`~.element_factory`, can be used by operations to create elements abstracting away the document type.
10801060
10811061
:param str tag: the tag of the element to create.
@@ -1103,7 +1083,8 @@ def copy_element(
11031083
**attributes,
11041084
):
11051085
"""
1106-
Helper method that creates a copy of an element, optionally changing the tag, classes, contents and attributes.
1086+
Create a copy of an element, optionally changing the tag, classes, contents and attributes.
1087+
11071088
Like :meth:`~.element_factory`, can be used by operations to copy elements abstracting away the document type.
11081089
11091090
:param etree.ElementBase element: the element to copy.
@@ -1133,7 +1114,7 @@ def adapt_xpath(self, xpath):
11331114

11341115
def convert_tree(tree, src_version, dst_version, **converter_kwargs):
11351116
"""
1136-
Converts an already parsed lxml tree from Bootstrap v3 to v4 inplace.
1117+
Convert an already parsed lxml tree from Bootstrap v3 to v4 inplace.
11371118
11381119
:param etree.ElementTree tree: the lxml tree to convert.
11391120
:param str src_version: the version of Bootstrap the document is currently using.

src/util/data.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
def uniq_tags(cr, model, uniq_column="name", order="id"):
1818
"""
19-
Deduplicated "tag" models entries.
19+
Deduplicate "tag" models entries.
20+
2021
In standard, should only be referenced as many2many
2122
But with a customization, could be referenced as many2one
2223
@@ -98,7 +99,7 @@ def uniq_tags(cr, model, uniq_column="name", order="id"):
9899

99100

100101
def split_group(cr, from_groups, to_group):
101-
"""Users have all `from_groups` will be added into `to_group`"""
102+
"""Users have all `from_groups` will be added into `to_group`."""
102103

103104
def check_group(g):
104105
if isinstance(g, basestring):

src/util/helpers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ def _ir_values_value(cr, prefix=None):
172172

173173

174174
def _dashboard_actions(cr, arch_match, *models):
175-
"""Yield (dashboard_id, action) of dashboards that match `arch_match` and apply on `models` (if specified)"""
176-
175+
"""Yield (dashboard_id, action) of dashboards that match `arch_match` and apply on `models` (if specified)."""
177176
q = """
178177
SELECT id, arch
179178
FROM ir_ui_view_custom

src/util/inconsistencies.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def verify_companies(
110110
def verify_uoms(cr, model, uom_field="product_uom_id", product_field="product_id", ids=None):
111111
"""
112112
Check if the category of uom on `model` is the same as the category of uom on `product.template`.
113+
113114
When `ids` is not provided, every ids would be verified.
114115
115116
Returns list of ids if inconsistencies found, else []
@@ -264,6 +265,7 @@ def verify_products(
264265
):
265266
"""
266267
Check if the product on the `foreign_model` is the same as the product on the `model`.
268+
267269
When `ids` is not provided, every ids would be verified.
268270
269271
The `foreign_model` should be the one that have a reference to the `model` using this

0 commit comments

Comments
 (0)