From dacd0a6e8be63252f0d6e4a815c64c8d4f25cad4 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Wed, 26 Aug 2020 20:56:36 +0200 Subject: style(black): new black release changed a bunch of stuff --- logilab/common/cache.py | 2 +- logilab/common/changelog.py | 5 +- logilab/common/configuration.py | 31 +++------- logilab/common/date.py | 3 +- logilab/common/debugger.py | 3 +- logilab/common/decorators.py | 5 +- logilab/common/deprecation.py | 3 +- logilab/common/optik_ext.py | 9 +-- logilab/common/proc.py | 6 +- logilab/common/pytest.py | 11 ++-- logilab/common/registry.py | 6 +- logilab/common/shellutils.py | 9 +-- logilab/common/table.py | 108 +++++++++++---------------------- logilab/common/testlib.py | 14 ++--- logilab/common/tree.py | 18 ++---- logilab/common/umessage.py | 3 +- logilab/common/ureports/__init__.py | 3 +- logilab/common/ureports/text_writer.py | 6 +- logilab/common/vcgutils.py | 27 +++------ test/test_cache.py | 6 +- test/test_configuration.py | 4 +- test/test_table.py | 51 ++++++---------- test/test_testlib.py | 15 ++--- 23 files changed, 121 insertions(+), 227 deletions(-) diff --git a/logilab/common/cache.py b/logilab/common/cache.py index 1562111..c0168a8 100644 --- a/logilab/common/cache.py +++ b/logilab/common/cache.py @@ -44,7 +44,7 @@ class Cache(dict): """ def __init__(self, size: int = 100) -> None: - """ Warning : Cache.__init__() != dict.__init__(). + """Warning : Cache.__init__() != dict.__init__(). Constructor does not take any arguments beside size. """ assert size >= 0, "cache size must be >= 0 (0 meaning no caching)" diff --git a/logilab/common/changelog.py b/logilab/common/changelog.py index cec1b5e..d1cba0b 100644 --- a/logilab/common/changelog.py +++ b/logilab/common/changelog.py @@ -117,8 +117,7 @@ class ChangeLogEntry(object): self.messages.append(([msg], [])) def complete_latest_message(self, msg_suite: str) -> None: - """complete the latest added message - """ + """complete the latest added message""" if not self.messages: raise ValueError("unable to complete last message as " "there is no previous message)") if self.messages[-1][1]: # sub messages @@ -171,7 +170,7 @@ class ChangeLog(object): self.entries.append(entry) def get_entry(self, version="", create=None): - """ return a given changelog entry + """return a given changelog entry if version is omitted, return the current entry """ if not self.entries: diff --git a/logilab/common/configuration.py b/logilab/common/configuration.py index 2429297..1e52bca 100644 --- a/logilab/common/configuration.py +++ b/logilab/common/configuration.py @@ -165,8 +165,7 @@ _ValueType = Union[List[str], Tuple[str, ...], str] def choice_validator(optdict: Dict[str, Any], name: str, value: str) -> str: - """validate and return a converted value for option of type 'choice' - """ + """validate and return a converted value for option of type 'choice'""" if value not in optdict["choices"]: msg = "option %s: invalid value: %r, should be in %s" raise optik_ext.OptionValueError(msg % (name, value, optdict["choices"])) @@ -174,8 +173,7 @@ def choice_validator(optdict: Dict[str, Any], name: str, value: str) -> str: def multiple_choice_validator(optdict: Dict[str, Any], name: str, value: _ValueType) -> _ValueType: - """validate and return a converted value for option of type 'choice' - """ + """validate and return a converted value for option of type 'choice'""" choices = optdict["choices"] values = optik_ext.check_csv(None, name, value) for value in values: @@ -186,22 +184,19 @@ def multiple_choice_validator(optdict: Dict[str, Any], name: str, value: _ValueT def csv_validator(optdict: Dict[str, Any], name: str, value: _ValueType) -> _ValueType: - """validate and return a converted value for option of type 'csv' - """ + """validate and return a converted value for option of type 'csv'""" return optik_ext.check_csv(None, name, value) def yn_validator(optdict: Dict[str, Any], name: str, value: Union[bool, str]) -> bool: - """validate and return a converted value for option of type 'yn' - """ + """validate and return a converted value for option of type 'yn'""" return optik_ext.check_yn(None, name, value) def named_validator( optdict: Dict[str, Any], name: str, value: Union[Dict[str, str], str] ) -> Dict[str, str]: - """validate and return a converted value for option of type 'named' - """ + """validate and return a converted value for option of type 'named'""" return optik_ext.check_named(None, name, value) @@ -537,9 +532,7 @@ class OptionsManagerMixIn(object): # mypy: Need type annotation for 'option' # you can't type variable of a list comprehension, right? non_group_spec_options: List = [ - option - for option in provider.options # type: ignore - if "group" not in option[1] + option for option in provider.options if "group" not in option[1] # type: ignore ] # type: ignore groups = getattr(provider, "option_groups", ()) @@ -569,8 +562,7 @@ class OptionsManagerMixIn(object): options: Union[List[Tuple[str, Dict[str, Any]]], List[Tuple[str, Dict[str, str]]]], provider: "ConfigurationMixIn", ) -> None: - """add an option group including the listed options - """ + """add an option group including the listed options""" assert options # add option group to the command line parser if group_name in self._mygroups: @@ -794,8 +786,7 @@ class OptionsManagerMixIn(object): continue def load_configuration(self, **kwargs: Any) -> None: - """override configuration according to given parameters - """ + """override configuration according to given parameters""" for opt, opt_value in kwargs.items(): opt = opt.replace("_", "-") provider = self._all_options[opt] @@ -935,8 +926,7 @@ class OptionsProviderMixIn(object): return default def option_attrname(self, opt, optdict=None): - """get the config attribute corresponding to opt - """ + """get the config attribute corresponding to opt""" if optdict is None: optdict = self.get_option_def(opt) return optdict.get("dest", opt.replace("-", "_")) @@ -950,8 +940,7 @@ class OptionsProviderMixIn(object): return getattr(self.config, self.option_attrname(opt), None) def set_option(self, opt, value, action=None, optdict=None): - """method called to set an option (registered in the options list) - """ + """method called to set an option (registered in the options list)""" if optdict is None: optdict = self.get_option_def(opt) if value is not None: diff --git a/logilab/common/date.py b/logilab/common/date.py index 769ab16..c65c9dd 100644 --- a/logilab/common/date.py +++ b/logilab/common/date.py @@ -344,8 +344,7 @@ def utctime(dt): def datetime_to_seconds(date): - """return the number of seconds since the begining of the day for that date - """ + """return the number of seconds since the begining of the day for that date""" return date.second + 60 * date.minute + 3600 * date.hour diff --git a/logilab/common/debugger.py b/logilab/common/debugger.py index c61b9d5..ee61598 100644 --- a/logilab/common/debugger.py +++ b/logilab/common/debugger.py @@ -113,8 +113,7 @@ class Debugger(Pdb): self._histfile = os.path.expanduser("~/.pdbhist") def setup_history_file(self): - """if readline is available, read pdb history file - """ + """if readline is available, read pdb history file""" if readline is not None: try: # XXX try..except shouldn't be necessary diff --git a/logilab/common/decorators.py b/logilab/common/decorators.py index 3367e16..cff75c9 100644 --- a/logilab/common/decorators.py +++ b/logilab/common/decorators.py @@ -135,7 +135,7 @@ def cached( class cachedproperty(object): - """ Provides a cached property equivalent to the stacking of + """Provides a cached property equivalent to the stacking of @cached and @property, but more efficient. After first usage, the becomes part of the object's @@ -221,8 +221,7 @@ class wproperty(object): class classproperty(object): - """this is a simple property-like class but for class attributes. - """ + """this is a simple property-like class but for class attributes.""" def __init__(self, get): self.get = get diff --git a/logilab/common/deprecation.py b/logilab/common/deprecation.py index 18027d7..22f9aaa 100644 --- a/logilab/common/deprecation.py +++ b/logilab/common/deprecation.py @@ -82,8 +82,7 @@ def lazy_wraps(wrapped): class DeprecationWrapper(object): - """proxy to print a warning on access to any attribute of the wrapped object - """ + """proxy to print a warning on access to any attribute of the wrapped object""" def __init__(self, proxied, msg=None, version=None): self._proxied = proxied diff --git a/logilab/common/optik_ext.py b/logilab/common/optik_ext.py index d044855..0f69884 100644 --- a/logilab/common/optik_ext.py +++ b/logilab/common/optik_ext.py @@ -149,8 +149,7 @@ def check_named( def check_password(option, opt, value): - """check a password value (can't be empty) - """ + """check a password value (can't be empty)""" # no actual checking, monkey patch if you want more return value @@ -208,8 +207,7 @@ def check_bytes(option: Optional["Option"], opt: str, value: Any) -> int: class Option(BaseOption): - """override optik.Option to add some new option types - """ + """override optik.Option to add some new option types""" TYPES = BaseOption.TYPES + ( "regexp", @@ -286,8 +284,7 @@ class Option(BaseOption): class OptionParser(BaseParser): - """override optik.OptionParser to use our Option class - """ + """override optik.OptionParser to use our Option class""" def __init__(self, option_class: type = Option, *args: Any, **kwargs: Any) -> None: # mypy: Argument "option_class" to "__init__" of "OptionParser" has incompatible type diff --git a/logilab/common/proc.py b/logilab/common/proc.py index 49d4d96..0a9ca74 100644 --- a/logilab/common/proc.py +++ b/logilab/common/proc.py @@ -92,13 +92,11 @@ class ProcInfo(Node): return open(self.file).read().split() def name(self): - """return the process name found in /proc//stat - """ + """return the process name found in /proc//stat""" return self.status()[1].strip("()") def age(self): - """return the age of the process - """ + """return the age of the process""" return os.stat(self.file)[stat.ST_MTIME] diff --git a/logilab/common/pytest.py b/logilab/common/pytest.py index 04ad2f4..177d58e 100644 --- a/logilab/common/pytest.py +++ b/logilab/common/pytest.py @@ -258,8 +258,7 @@ class GlobalTestReport(object): self.errmodules.append((filename[:-3], problems, ran)) def failed_to_test_module(self, filename): - """called when the test module could not be imported by unittest - """ + """called when the test module could not be imported by unittest""" self.errors += 1 self.modulescount += 1 self.ran += 1 @@ -580,8 +579,7 @@ class DjangoTester(PyTester): def make_parser(): - """creates the OptionParser instance - """ + """creates the OptionParser instance""" from optparse import OptionParser parser = OptionParser(usage=PYTEST_DOC) @@ -890,7 +888,7 @@ Examples: ) def removeSucceededTests(obj, succTests): - """ Recursive function that removes succTests from + """Recursive function that removes succTests from a TestSuite or TestCase """ if isinstance(obj, unittest.TestSuite): @@ -1331,8 +1329,7 @@ class NonStrictTestLoader(unittest.TestLoader): return any([(pat in testedname) for pat in self.skipped_patterns]) # type: ignore def getTestCaseNames(self, testCaseClass: type) -> List[str]: - """Return a sorted sequence of method names found within testCaseClass - """ + """Return a sorted sequence of method names found within testCaseClass""" is_skipped = self._this_is_skipped classname = testCaseClass.__name__ if classname[0] == "_" or is_skipped(classname): diff --git a/logilab/common/registry.py b/logilab/common/registry.py index 556bffa..1578d70 100644 --- a/logilab/common/registry.py +++ b/logilab/common/registry.py @@ -611,8 +611,7 @@ class Registry(dict): self.warning("can't remove %s, no id %s in the registry", objid, oid) def all_objects(self): - """return a list containing all objects in this registry. - """ + """return a list containing all objects in this registry.""" result = [] for objs in self.values(): result += objs @@ -741,8 +740,7 @@ class Registry(dict): return self.selected(winners[0], args, kwargs) def selected(self, winner, args, kwargs): - """override here if for instance you don't want "instanciation" - """ + """override here if for instance you don't want "instanciation" """ return winner(*args, **kwargs) # these are overridden by set_log_methods below diff --git a/logilab/common/shellutils.py b/logilab/common/shellutils.py index 9950deb..5063ff8 100644 --- a/logilab/common/shellutils.py +++ b/logilab/common/shellutils.py @@ -93,8 +93,7 @@ def chown(path, login=None, group=None): def mv(source, destination, _action=shutil.move): - """A shell-like mv, supporting wildcards. - """ + """A shell-like mv, supporting wildcards.""" sources = glob.glob(source) if len(sources) > 1: assert isdir(destination) @@ -114,8 +113,7 @@ def mv(source, destination, _action=shutil.move): def rm(*files): - """A shell-like rm, supporting wildcards. - """ + """A shell-like rm, supporting wildcards.""" for wfile in files: for filename in glob.glob(wfile): if islink(filename): @@ -127,8 +125,7 @@ def rm(*files): def cp(source, destination): - """A shell-like cp, supporting wildcards. - """ + """A shell-like cp, supporting wildcards.""" mv(source, destination, _action=shutil.copy) diff --git a/logilab/common/table.py b/logilab/common/table.py index 46216d9..cb903ac 100644 --- a/logilab/common/table.py +++ b/logilab/common/table.py @@ -85,36 +85,31 @@ class Table(object): # Rows / Columns creation ################################################# def create_rows(self, row_names: List[str]) -> None: - """Appends row_names to the list of existing rows - """ + """Appends row_names to the list of existing rows""" self.row_names.extend(row_names) for row_name in row_names: self.data.append([self.default_value] * len(self.col_names)) def create_columns(self, col_names: List[str]) -> None: - """Appends col_names to the list of existing columns - """ + """Appends col_names to the list of existing columns""" for col_name in col_names: self.create_column(col_name) def create_row(self, row_name: str = None) -> None: - """Creates a rowname to the row_names list - """ + """Creates a rowname to the row_names list""" row_name = row_name or self._next_row_name() self.row_names.append(row_name) self.data.append([self.default_value] * len(self.col_names)) def create_column(self, col_name: str) -> None: - """Creates a colname to the col_names list - """ + """Creates a colname to the col_names list""" self.col_names.append(col_name) for row in self.data: row.append(self.default_value) # Sort by column ########################################################## def sort_by_column_id(self, col_id: str, method: str = "asc") -> None: - """Sorts the table (in-place) according to data stored in col_id - """ + """Sorts the table (in-place) according to data stored in col_id""" try: col_index = self.col_names.index(col_id) self.sort_by_column_index(col_index, method) @@ -179,8 +174,7 @@ class Table(object): # The 'setter' part ####################################################### def set_cell(self, row_index: int, col_index: int, data: int) -> None: - """sets value of cell 'row_indew', 'col_index' to data - """ + """sets value of cell 'row_indew', 'col_index' to data""" self.data[row_index][col_index] = data def set_cell_by_ids(self, row_id: str, col_id: str, data: Union[int, str]) -> None: @@ -336,8 +330,7 @@ class Table(object): # The 'getter' part ####################################################### def get_shape(self) -> Tuple[int, int]: - """Returns a tuple which represents the table's shape - """ + """Returns a tuple which represents the table's shape""" return len(self.row_names), len(self.col_names) shape = property(get_shape) @@ -412,8 +405,7 @@ class Table(object): return tab.data[0][0] def get_cell_by_ids(self, row_id, col_id): - """Returns the element at [row_id][col_id] - """ + """Returns the element at [row_id][col_id]""" try: row_index = self.row_names.index(row_id) except ValueError: @@ -426,8 +418,7 @@ class Table(object): return self.data[row_index][col_index] def get_row_by_id(self, row_id): - """Returns the 'row_id' row - """ + """Returns the 'row_id' row""" try: row_index = self.row_names.index(row_id) except ValueError: @@ -435,8 +426,7 @@ class Table(object): return self.data[row_index] def get_column_by_id(self, col_id, distinct=False): - """Returns the 'col_id' col - """ + """Returns the 'col_id' col""" try: col_index = self.col_names.index(col_id) except ValueError: @@ -444,8 +434,7 @@ class Table(object): return self.get_column(col_index, distinct) def get_columns(self) -> List[List[int]]: - """Returns all the columns in the table - """ + """Returns all the columns in the table""" return [self[:, index] for index in range(len(self.col_names))] def get_column(self, col_index, distinct=False): @@ -456,8 +445,7 @@ class Table(object): return col def apply_stylesheet(self, stylesheet: "TableStyleSheet") -> None: - """Applies the stylesheet to this table - """ + """Applies the stylesheet to this table""" for instruction in stylesheet.instructions: eval(instruction) @@ -526,8 +514,7 @@ class Table(object): class TableStyle: - """Defines a table's style - """ + """Defines a table's style""" def __init__(self, table: Table) -> None: @@ -546,8 +533,7 @@ class TableStyle: # XXX FIXME : params order should be reversed for all set() methods def set_size(self, value: str, col_id: str) -> None: - """sets the size of the specified col_id to value - """ + """sets the size of the specified col_id to value""" self.size[col_id] = value def set_size_by_index(self, value: str, col_index: int) -> None: @@ -563,8 +549,7 @@ class TableStyle: self.size[col_id] = value def set_alignment(self, value: str, col_id: str) -> None: - """sets the alignment of the specified col_id to value - """ + """sets the alignment of the specified col_id to value""" self.alignment[col_id] = value def set_alignment_by_index(self, value: str, col_index: int) -> None: @@ -580,8 +565,7 @@ class TableStyle: self.alignment[col_id] = value def set_unit(self, value: str, col_id: str) -> None: - """sets the unit of the specified col_id to value - """ + """sets the unit of the specified col_id to value""" self.units[col_id] = value def set_unit_by_index(self, value: str, col_index: int) -> None: @@ -599,8 +583,7 @@ class TableStyle: self.units[col_id] = value def get_size(self, col_id: str) -> str: - """Returns the size of the specified col_id - """ + """Returns the size of the specified col_id""" return self.size[col_id] def get_size_by_index(self, col_index: int) -> str: @@ -616,8 +599,7 @@ class TableStyle: return self.size[col_id] def get_alignment(self, col_id: str) -> str: - """Returns the alignment of the specified col_id - """ + """Returns the alignment of the specified col_id""" return self.alignment[col_id] def get_alignment_by_index(self, col_index: int) -> str: @@ -633,8 +615,7 @@ class TableStyle: return self.alignment[col_id] def get_unit(self, col_id: str) -> str: - """Returns the unit of the specified col_id - """ + """Returns the unit of the specified col_id""" return self.units[col_id] def get_unit_by_index(self, col_index: int) -> str: @@ -678,8 +659,7 @@ class TableStyleSheet: self.add_rule(rule) def add_rule(self, rule: str) -> None: - """Adds a rule to the stylesheet rules - """ + """Adds a rule to the stylesheet rules""" try: source_code = ["from math import *"] source_code.append(CELL_PROG.sub(r"self.data[\1][\2]", rule)) @@ -756,8 +736,7 @@ class TableStyleSheet: class TableCellRenderer: - """Defines a simple text renderer - """ + """Defines a simple text renderer""" def __init__(self, **properties: Any) -> None: """keywords should be properties with an associated boolean as value. @@ -772,8 +751,7 @@ class TableCellRenderer: def render_cell( self, cell_coord: Tuple[int, int], table: Table, table_style: TableStyle ) -> Union[str, int]: - """Renders the cell at 'cell_coord' in the table, using table_style - """ + """Renders the cell at 'cell_coord' in the table, using table_style""" row_index, col_index = cell_coord cell_value = table.data[row_index][col_index] final_content = self._make_cell_content(cell_value, table_style, col_index + 1) @@ -782,16 +760,14 @@ class TableCellRenderer: def render_row_cell( self, row_name: str, table: Table, table_style: TableStyle ) -> Union[str, int]: - """Renders the cell for 'row_id' row - """ + """Renders the cell for 'row_id' row""" cell_value = row_name return self._render_cell_content(cell_value, table_style, 0) def render_col_cell( self, col_name: str, table: Table, table_style: TableStyle ) -> Union[str, int]: - """Renders the cell for 'col_id' row - """ + """Renders the cell for 'col_id' row""" cell_value = col_name col_index = table.col_names.index(col_name) return self._render_cell_content(cell_value, table_style, col_index + 1) @@ -832,19 +808,16 @@ class TableCellRenderer: return final_content def _add_unit(self, cell_content: int, table_style: TableStyle, col_index: int) -> str: - """Adds unit to the cell_content if needed - """ + """Adds unit to the cell_content if needed""" unit = table_style.get_unit_by_index(col_index) return str(cell_content) + " " + unit class DocbookRenderer(TableCellRenderer): - """Defines how to render a cell for a docboook table - """ + """Defines how to render a cell for a docboook table""" def define_col_header(self, col_index: int, table_style: TableStyle) -> str: - """Computes the colspec element according to the style - """ + """Computes the colspec element according to the style""" size = table_style.get_size_by_index(col_index) return '\n' % (col_index, size) @@ -869,8 +842,7 @@ class DocbookRenderer(TableCellRenderer): class TableWriter: - """A class to write tables - """ + """A class to write tables""" def __init__( self, stream: StringIO, table: Table, style: Optional[Any], **properties: Any @@ -882,33 +854,27 @@ class TableWriter: self.renderer: Optional[DocbookRenderer] = None def set_style(self, style): - """sets the table's associated style - """ + """sets the table's associated style""" self.style = style def set_renderer(self, renderer: DocbookRenderer) -> None: - """sets the way to render cell - """ + """sets the way to render cell""" self.renderer = renderer def update_properties(self, **properties): - """Updates writer's properties (for cell rendering) - """ + """Updates writer's properties (for cell rendering)""" self.properties.update(properties) def write_table(self, title: str = "") -> None: - """Writes the table - """ + """Writes the table""" raise NotImplementedError("write_table must be implemented !") class DocbookTableWriter(TableWriter): - """Defines an implementation of TableWriter to write a table in Docbook - """ + """Defines an implementation of TableWriter to write a table in Docbook""" def _write_headers(self) -> None: - """Writes col headers - """ + """Writes col headers""" assert self.renderer is not None # Define col_headers (colstpec elements) @@ -924,8 +890,7 @@ class DocbookTableWriter(TableWriter): self._stream.write("\n\n") def _write_body(self) -> None: - """Writes the table body - """ + """Writes the table body""" assert self.renderer is not None self._stream.write("\n") @@ -946,8 +911,7 @@ class DocbookTableWriter(TableWriter): self._stream.write("\n") def write_table(self, title: str = "") -> None: - """Writes the table - """ + """Writes the table""" self._stream.write("\n%s>\n" % (title)) self._stream.write( '\n' diff --git a/logilab/common/testlib.py b/logilab/common/testlib.py index 4fb3221..c5e4d00 100644 --- a/logilab/common/testlib.py +++ b/logilab/common/testlib.py @@ -132,8 +132,7 @@ def with_tempdir(callable: Callable) -> Callable: def in_tempdir(callable): - """A decorator moving the enclosed function inside the tempfile.tempfdir - """ + """A decorator moving the enclosed function inside the tempfile.tempfdir""" @wraps(callable) def proxy(*args, **kargs): @@ -149,8 +148,7 @@ def in_tempdir(callable): def within_tempdir(callable): - """A decorator run the enclosed function inside a tmpdir removed after execution - """ + """A decorator run the enclosed function inside a tmpdir removed after execution""" proxy = with_tempdir(in_tempdir(callable)) proxy.__name__ = callable.__name__ return proxy @@ -175,8 +173,7 @@ def find_tests(testdir, prefixes=DEFAULT_PREFIXES, suffix=".py", excludes=(), re # PostMortem Debug facilities ##### def start_interactive_mode(result): - """starts an interactive shell so that the user can inspect errors - """ + """starts an interactive shell so that the user can inspect errors""" debuggers = result.debuggers descrs = result.error_descrs + result.fail_descrs if len(debuggers) == 1: @@ -722,7 +719,7 @@ def tag(*args: str, **kwargs: Any) -> Callable: def require_version(version: str) -> Callable: - """ Compare version of python interpreter to the given one. Skip the test + """Compare version of python interpreter to the given one. Skip the test if older. """ @@ -750,8 +747,7 @@ def require_version(version: str) -> Callable: def require_module(module: str) -> Callable: - """ Check if the given module is loaded. Skip the test if not. - """ + """Check if the given module is loaded. Skip the test if not.""" def check_require_module(f: Callable) -> Callable: try: diff --git a/logilab/common/tree.py b/logilab/common/tree.py index 33fb7e2..8303c8a 100644 --- a/logilab/common/tree.py +++ b/logilab/common/tree.py @@ -240,13 +240,11 @@ class Node(object): class VNode(Node, VisitedMixIn): # we should probably merge this VisitedMixIn here because it's only used here - """a visitable node - """ + """a visitable node""" class BinaryNode(VNode): - """a binary node (i.e. only two children - """ + """a binary node (i.e. only two children""" def __init__(self, lhs=None, rhs=None): VNode.__init__(self) @@ -256,8 +254,7 @@ class BinaryNode(VNode): self.append(rhs) def remove(self, child): - """remove the child and replace this node with the other child - """ + """remove the child and replace this node with the other child""" self.children.remove(child) self.parent.replace(self, self.children[0]) @@ -277,8 +274,7 @@ else: class ListNode(VNode, list_class): - """Used to manipulate Nodes as Lists - """ + """Used to manipulate Nodes as Lists""" def __init__(self): list_class.__init__(self) @@ -379,16 +375,14 @@ def pre_order_list(node: Optional[Node], filter_func: Callable = no_filter) -> L class PostfixedDepthFirstIterator(FilteredIterator): - """a postfixed depth first iterator, designed to be used with visitors - """ + """a postfixed depth first iterator, designed to be used with visitors""" def __init__(self, node: Node, filter_func: Optional[Any] = None) -> None: FilteredIterator.__init__(self, node, post_order_list, filter_func) class PrefixedDepthFirstIterator(FilteredIterator): - """a prefixed depth first iterator, designed to be used with visitors - """ + """a prefixed depth first iterator, designed to be used with visitors""" def __init__(self, node: Node, filter_func: Optional[Any] = None) -> None: FilteredIterator.__init__(self, node, pre_order_list, filter_func) diff --git a/logilab/common/umessage.py b/logilab/common/umessage.py index 2117062..3479fd1 100644 --- a/logilab/common/umessage.py +++ b/logilab/common/umessage.py @@ -77,8 +77,7 @@ def message_from_string(string: str) -> Union["UMessage", str]: class UMessage: - """Encapsulates an email.Message instance and returns only unicode objects. - """ + """Encapsulates an email.Message instance and returns only unicode objects.""" def __init__(self, message: Message) -> None: self.message = message diff --git a/logilab/common/ureports/__init__.py b/logilab/common/ureports/__init__.py index bb95223..e19e739 100644 --- a/logilab/common/ureports/__init__.py +++ b/logilab/common/ureports/__init__.py @@ -45,8 +45,7 @@ def get_nodes(node, klass): def layout_title(layout): - """try to return the layout's title as string, return None if not found - """ + """try to return the layout's title as string, return None if not found""" for child in layout.children: if isinstance(child, Title): return " ".join([node.data for node in get_nodes(child, Text)]) diff --git a/logilab/common/ureports/text_writer.py b/logilab/common/ureports/text_writer.py index efe85b7..19a732a 100644 --- a/logilab/common/ureports/text_writer.py +++ b/logilab/common/ureports/text_writer.py @@ -51,8 +51,7 @@ class TextWriter(BaseWriter): self.pending_urls: List[Tuple[str, str]] = [] def visit_section(self, layout: Section) -> None: - """display a section as text - """ + """display a section as text""" self.section += 1 self.writeln() self.format_children(layout) @@ -151,8 +150,7 @@ class TextWriter(BaseWriter): self.write(layout.url) def visit_verbatimtext(self, layout: VerbatimText) -> None: - """display a verbatim layout as text (so difficult ;) - """ + """display a verbatim layout as text (so difficult ;)""" self.writeln("::\n") for line in layout.data.splitlines(): self.writeln(" " + line) diff --git a/logilab/common/vcgutils.py b/logilab/common/vcgutils.py index c2a4e4e..8b45fa8 100644 --- a/logilab/common/vcgutils.py +++ b/logilab/common/vcgutils.py @@ -169,8 +169,7 @@ EDGE_ATTRS = { def latin_to_vcg(st): - """Convert latin characters using vcg escape sequence. - """ + """Convert latin characters using vcg escape sequence.""" for char in st: if char not in string.ascii_letters: try: @@ -183,36 +182,31 @@ def latin_to_vcg(st): class VCGPrinter: - """A vcg graph writer. - """ + """A vcg graph writer.""" def __init__(self, output_stream): self._stream = output_stream self._indent = "" def open_graph(self, **args): - """open a vcg graph - """ + """open a vcg graph""" self._stream.write("%sgraph:{\n" % self._indent) self._inc_indent() self._write_attributes(GRAPH_ATTRS, **args) def close_graph(self): - """close a vcg graph - """ + """close a vcg graph""" self._dec_indent() self._stream.write("%s}\n" % self._indent) def node(self, title, **args): - """draw a node - """ + """draw a node""" self._stream.write('%snode: {title:"%s"' % (self._indent, title)) self._write_attributes(NODE_ATTRS, **args) self._stream.write("}\n") def edge(self, from_node, to_node, edge_type="", **args): - """draw an edge from a node to another. - """ + """draw an edge from a node to another.""" self._stream.write( '%s%sedge: {sourcename:"%s" targetname:"%s"' % (self._indent, edge_type, from_node, to_node) @@ -223,8 +217,7 @@ class VCGPrinter: # private ################################################################## def _write_attributes(self, attributes_dict, **args): - """write graph, node or edge attributes - """ + """write graph, node or edge attributes""" for key, value in args.items(): try: _type = attributes_dict[key] @@ -249,11 +242,9 @@ correct values are %s""" ) def _inc_indent(self): - """increment indentation - """ + """increment indentation""" self._indent = " %s" % self._indent def _dec_indent(self): - """decrement indentation - """ + """decrement indentation""" self._indent = self._indent[:-2] diff --git a/test/test_cache.py b/test/test_cache.py index d094943..41c628e 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -106,8 +106,7 @@ class CacheTestCase(TestCase): ) # usage list and data keys are different def test_nullsize(self): - """Checks that a 'NULL' size cache doesn't store anything - """ + """Checks that a 'NULL' size cache doesn't store anything""" null_cache = Cache(0) null_cache["foo"] = "bar" self.assertEqual(null_cache.size, 0, "Cache size should be O, not %d" % null_cache.size) @@ -118,8 +117,7 @@ class CacheTestCase(TestCase): self.assertRaises(KeyError, null_cache.__delitem__, "foo") def test_getitem(self): - """ Checks that getitem doest not modify the _usage attribute - """ + """Checks that getitem doest not modify the _usage attribute""" try: self.cache["toto"] except KeyError: diff --git a/test/test_configuration.py b/test/test_configuration.py index a4f8ec0..372d787 100644 --- a/test/test_configuration.py +++ b/test/test_configuration.py @@ -192,8 +192,8 @@ diffgroup=zou os.remove(file) def test_option_order(self): - """ Check that options are taken into account in the command line order - and not in the order they are defined in the Configuration object. + """Check that options are taken into account in the command line order + and not in the order they are defined in the Configuration object. """ file = tempfile.mktemp() stream = open(file, "w") diff --git a/test/test_table.py b/test/test_table.py index e3736c1..bf12616 100644 --- a/test/test_table.py +++ b/test/test_table.py @@ -106,16 +106,14 @@ class TableTC(TestCase): self.assertEqual(self.table.shape, (3, 3)) def test_set_column(self): - """Tests that table.set_column() works fine. - """ + """Tests that table.set_column() works fine.""" self.table.set_column(0, range(3)) self.assertEqual(self.table[0, 0], 0) self.assertEqual(self.table[1, 0], 1) self.assertEqual(self.table[2, 0], 2) def test_set_column_by_id(self): - """Tests that table.set_column_by_id() works fine. - """ + """Tests that table.set_column_by_id() works fine.""" self.table.set_column_by_id("col1", range(3)) self.assertEqual(self.table[0, 0], 0) self.assertEqual(self.table[1, 0], 1) @@ -145,30 +143,26 @@ class TableTC(TestCase): self.assertRaises(KeyError, self.table.__getitem__, "tmprow") def test_get_column(self): - """Tests that table.get_column() works fine. - """ + """Tests that table.get_column() works fine.""" self.table.set_cell(0, 1, 12) self.table.set_cell(2, 1, 13) self.assertEqual(self.table[:, 1], [12, 0, 13]) self.assertEqual(self.table[:, "col2"], [12, 0, 13]) def test_get_columns(self): - """Tests if table.get_columns() works fine. - """ + """Tests if table.get_columns() works fine.""" self.table.set_cell(0, 1, 12) self.table.set_cell(2, 1, 13) self.assertEqual(self.table.get_columns(), [[0, 0, 0], [12, 0, 13]]) def test_insert_column(self): - """Tests that table.insert_column() works fine. - """ + """Tests that table.insert_column() works fine.""" self.table.insert_column(1, range(3), "inserted_column") self.assertEqual(self.table[:, 1], [0, 1, 2]) self.assertEqual(self.table.col_names, ["col1", "inserted_column", "col2"]) def test_delete_column(self): - """Tests that table.delete_column() works fine. - """ + """Tests that table.delete_column() works fine.""" self.table.delete_column(1) self.assertEqual(self.table.col_names, ["col1"]) self.assertEqual(self.table[:, 0], [0, 0, 0]) @@ -177,8 +171,7 @@ class TableTC(TestCase): self.assertEqual(self.table.col_names, []) def test_transpose(self): - """Tests that table.transpose() works fine. - """ + """Tests that table.transpose() works fine.""" self.table.append_column(range(5, 8), "col3") ttable = self.table.transpose() self.assertEqual(ttable.row_names, ["col1", "col2", "col3"]) @@ -186,8 +179,7 @@ class TableTC(TestCase): self.assertEqual(ttable.data, [[0, 0, 0], [0, 0, 0], [5, 6, 7]]) def test_sort_table(self): - """Tests the table sort by column - """ + """Tests the table sort by column""" self.table.set_column(0, [3, 1, 2]) self.table.set_column(1, [1, 2, 3]) self.table.sort_by_column_index(0) @@ -246,7 +238,11 @@ class GroupByTC(TestCase): ) self.assertEqual(grouped["date2"], [("date2", "ing3", "task3", 0.3)]) self.assertEqual( - grouped["date3"], [("date3", "ing4", "task2", 0.3), ("date3", "ing1", "task3", 0.3),] + grouped["date3"], + [ + ("date3", "ing4", "task2", 0.3), + ("date3", "ing1", "task3", 0.3), + ], ) def test_multiple_groupby(self): @@ -276,12 +272,10 @@ class GroupByTC(TestCase): class TableStyleSheetTC(TestCase): - """The Stylesheet test case - """ + """The Stylesheet test case""" def setUp(self): - """Builds a simple table to test the stylesheet - """ + """Builds a simple table to test the stylesheet""" self.table = Table() self.table.create_row("row1") self.table.create_columns(["a", "b", "c"]) @@ -294,8 +288,7 @@ class TableStyleSheetTC(TestCase): sys.stdout = self.stdout_backup def test_add_rule(self): - """Tests that the regex pattern works as expected. - """ + """Tests that the regex pattern works as expected.""" rule = "0_2 = sqrt(0_0**2 + 0_1**2)" self.stylesheet.add_rule(rule) self.table.set_row(0, [3, 4, 0]) @@ -314,8 +307,7 @@ class TableStyleSheetTC(TestCase): self.assertEqual(len(sheet.instructions), 1, "Ill-formed rule mustn't be added") def test_rowavg_rule(self): - """Tests that add_rowavg_rule works as expected - """ + """Tests that add_rowavg_rule works as expected""" self.table.set_row(0, [10, 20, 0]) self.stylesheet.add_rowavg_rule((0, 2), 0, 0, 1) self.table.apply_stylesheet(self.stylesheet) @@ -323,8 +315,7 @@ class TableStyleSheetTC(TestCase): self.assertEqual(int(val), 15) def test_rowsum_rule(self): - """Tests that add_rowsum_rule works as expected - """ + """Tests that add_rowsum_rule works as expected""" self.table.set_row(0, [10, 20, 0]) self.stylesheet.add_rowsum_rule((0, 2), 0, 0, 1) self.table.apply_stylesheet(self.stylesheet) @@ -332,8 +323,7 @@ class TableStyleSheetTC(TestCase): self.assertEqual(val, 30) def test_colavg_rule(self): - """Tests that add_colavg_rule works as expected - """ + """Tests that add_colavg_rule works as expected""" self.table.set_row(0, [10, 20, 0]) self.table.append_row([12, 8, 3], "row2") self.table.create_row("row3") @@ -343,8 +333,7 @@ class TableStyleSheetTC(TestCase): self.assertEqual(int(val), 11) def test_colsum_rule(self): - """Tests that add_colsum_rule works as expected - """ + """Tests that add_colsum_rule works as expected""" self.table.set_row(0, [10, 20, 0]) self.table.append_row([12, 8, 3], "row2") self.table.create_row("row3") diff --git a/test/test_testlib.py b/test/test_testlib.py index d2240ae..f906560 100644 --- a/test/test_testlib.py +++ b/test/test_testlib.py @@ -724,8 +724,7 @@ class DecoratorTC(TestCase): sys.version_info = self.pyversion def test_require_version_good(self): - """ should return the same function - """ + """should return the same function""" def func(): pass @@ -744,8 +743,7 @@ class DecoratorTC(TestCase): ) def test_require_version_bad(self): - """ should return a different function : skipping test - """ + """should return a different function : skipping test""" def func(): pass @@ -764,8 +762,7 @@ class DecoratorTC(TestCase): ) def test_require_version_exception(self): - """ should throw a ValueError exception - """ + """should throw a ValueError exception""" def func(): pass @@ -776,8 +773,7 @@ class DecoratorTC(TestCase): self.assertRaises(ValueError, decorator, func) def test_require_module_good(self): - """ should return the same function - """ + """should return the same function""" def func(): pass @@ -793,8 +789,7 @@ class DecoratorTC(TestCase): ) def test_require_module_bad(self): - """ should return a different function : skipping test - """ + """should return a different function : skipping test""" def func(): pass -- cgit v1.2.1