HomeClusterLabs Projects
Diffusion Booth ab2229451827

test: make Python files supported _also_ with Python 3.3+

Description

test: make Python files supported _also_ with Python 3.3+

  • use "print" like a function rather than a statement . where implicit newline is to be suppressed, don't do that and rather strip it from the string to be printed instead
  • use 2+3 compatible convention for parametrizing exceptions
  • Python 3 doesn't recognize "basestring" class, and at the place of use (pre Python 2.7 only), unicode string is really not expected (also re.UNICODE flag is not used...)
  • Python 3 doesn't recognize "xrange" function, but the surrounding code can be reasonably simplified using "enumerate" function
  • arrange dict treatment in a compatible way: . d.has_key(k) -> k in d . d.iteritems() -> custom "iter_items", always efficient wrapper . d.iterkeys(), here incl. lazy mapping and filtering -> rewrite while retaining laziness . optimize UT.merge_dicts in script/unit-test.py along
  • also in three instances, deal with string/uninterpreted bytes proper dichotomy introduced in Python 3, and related to that, "string" module only supports "ascii_lowercase" attribute in Python 3 (as opposed to system-specific plain "lowercase" one)

Note that script/unit-test.py has a pre-existing issue (regardless
of which Python version interpreter is used), so at least document
that in the header for now.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>

Details

Provenance
Jan Pokorný <jpokorny@redhat.com>Authored on Jul 11 2018, 10:18 AM
Parents
rBa642a833e31a: test: do not mix tabs with spaces in Python code
Branches
Unknown
Tags
Unknown

Event Timeline