[
https://issues.apache.org/jira/browse/PROTON-2320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17266022#comment-17266022
]
ASF GitHub Bot commented on PROTON-2320:
----------------------------------------
jiridanek commented on a change in pull request #285:
URL: https://github.com/apache/qpid-proton/pull/285#discussion_r558288356
##########
File path: python/tests/proton_tests/main.py
##########
@@ -330,382 +356,401 @@ def filter(self, record):
SKIP = "skip"
FAIL = "fail"
+
class Runner:
- def __init__(self):
- self.exception = None
- self.exception_phase_name = None
- self.skip = False
-
- def passed(self):
- return not self.exception
-
- def skipped(self):
- return self.skip
-
- def failed(self):
- return self.exception and not self.skip
-
- def halt(self):
- """determines if the overall test execution should be allowed to continue
to the next phase"""
- return self.exception or self.skip
-
- def run(self, phase_name, phase):
- """invokes a test-phase method (which can be the test method itself or a
setUp/tearDown
- method). If the method raises an exception the exception is examined
to see if the
- exception should be classified as a 'skipped' test"""
- # we don't try to catch exceptions for jython because currently a
- # jython bug will prevent the java portion of the stack being
- # stored with the exception info in the sys module
- if opts.bare:
- phase()
- else:
- try:
- phase()
- except KeyboardInterrupt:
- raise
- except:
- self.exception_phase_name = phase_name
- self.exception = sys.exc_info()
- exception_type = self.exception[0]
- self.skip = getattr(exception_type, "skipped", False) or
issubclass(exception_type, SkipTest)
-
- def status(self):
- if self.passed():
- return PASS
- elif self.skipped():
- return SKIP
- elif self.failed():
- return FAIL
- else:
- return None
-
- def get_formatted_exception_trace(self):
- if self.exception:
- if self.skip:
- # format skipped tests without a traceback
- output =
indent("".join(traceback.format_exception_only(*self.exception[:2]))).rstrip()
- else:
- output = "Error during %s:" % self.exception_phase_name
- lines = traceback.format_exception(*self.exception)
- val = self.exception[1]
- reflect = False
- if val and hasattr(val, "getStackTrace"):
- jlines = []
- for frame in val.getStackTrace():
- if reflect and frame.getClassName().startswith("org.python."):
- # this is a heuristic to eliminate the jython portion of
- # the java stack trace
- if not opts.javatrace:
- break
- jlines.append(" %s\n" % frame.toString())
- if frame.getClassName().startswith("java.lang.reflect"):
- reflect = True
+ def __init__(self):
+ self.exception = None
+ self.exception_phase_name = None
+ self.skip = False
+
+ def passed(self):
+ return not self.exception
+
+ def skipped(self):
+ return self.skip
+
+ def failed(self):
+ return self.exception and not self.skip
+
+ def halt(self):
+ """determines if the overall test execution should be allowed to
continue to the next phase"""
+ return self.exception or self.skip
+
+ def run(self, phase_name, phase):
+ """invokes a test-phase method (which can be the test method itself or
a setUp/tearDown
+ method). If the method raises an exception the exception is
examined to see if the
+ exception should be classified as a 'skipped' test"""
+ # we don't try to catch exceptions for jython because currently a
+ # jython bug will prevent the java portion of the stack being
+ # stored with the exception info in the sys module
+ if opts.bare:
+ phase()
+ else:
+ try:
+ phase()
+ except KeyboardInterrupt:
+ raise
+ except:
+ self.exception_phase_name = phase_name
+ self.exception = sys.exc_info()
+ exception_type = self.exception[0]
+ self.skip = getattr(exception_type, "skipped", False) or
issubclass(exception_type, SkipTest)
+
+ def status(self):
+ if self.passed():
+ return PASS
+ elif self.skipped():
+ return SKIP
+ elif self.failed():
+ return FAIL
+ else:
+ return None
+
+ def get_formatted_exception_trace(self):
+ if self.exception:
+ if self.skip:
+ # format skipped tests without a traceback
+ output =
indent("".join(traceback.format_exception_only(*self.exception[:2]))).rstrip()
else:
- reflect = False
- lines.extend(jlines)
- output += indent("".join(lines)).rstrip()
- return output
-
- def get_exception_type(self):
- if self.exception:
- return self.exception[0]
- else:
- return None
+ output = "Error during %s:" % self.exception_phase_name
+ lines = traceback.format_exception(*self.exception)
+ val = self.exception[1]
+ reflect = False
+ if val and hasattr(val, "getStackTrace"):
+ jlines = []
+ for frame in val.getStackTrace():
+ if reflect and
frame.getClassName().startswith("org.python."):
+ # this is a heuristic to eliminate the jython
portion of
+ # the java stack trace
+ if not opts.javatrace:
+ break
+ jlines.append(" %s\n" % frame.toString())
+ if
frame.getClassName().startswith("java.lang.reflect"):
+ reflect = True
+ else:
+ reflect = False
+ lines.extend(jlines)
+ output += indent("".join(lines)).rstrip()
+ return output
+
+ def get_exception_type(self):
+ if self.exception:
+ return self.exception[0]
+ else:
+ return None
+
+ def get_exception_message(self):
+ if self.exception:
+ return self.exception[1]
+ else:
+ return None
- def get_exception_message(self):
- if self.exception:
- return self.exception[1]
- else:
- return None
ST_WIDTH = 8
+
def run_test(name, test, config):
- patterns = filter.patterns
- level = root.level
- filter.patterns = config.log_categories
- root.setLevel(config.log_level)
-
- parts = name.split(".")
- line = None
- output = ""
- for part in parts:
+ patterns = filter.patterns
+ level = root.level
+ filter.patterns = config.log_categories
+ root.setLevel(config.log_level)
+
+ parts = name.split(".")
+ line = None
+ output = ""
+ for part in parts:
+ if line:
+ if len(line) + len(part) >= (WIDTH - ST_WIDTH - 1):
+ output += "%s. \\\n" % line
+ line = " %s" % part
+ else:
+ line = "%s.%s" % (line, part)
+ else:
+ line = part
+
if line:
- if len(line) + len(part) >= (WIDTH - ST_WIDTH - 1):
- output += "%s. \\\n" % line
- line = " %s" % part
- else:
- line = "%s.%s" % (line, part)
- else:
- line = part
-
- if line:
- output += "%s %s" % (line, (((WIDTH - ST_WIDTH) - len(line))*"."))
- sys.stdout.write(output)
- sys.stdout.flush()
- interceptor.begin()
- start = time.time()
- try:
- runner = test()
- finally:
- interceptor.reset()
- end = time.time()
- if interceptor.dirty:
- if interceptor.last != "\n":
- sys.stdout.write("\n")
+ output += "%s %s" % (line, (((WIDTH - ST_WIDTH) - len(line))*"."))
sys.stdout.write(output)
- print(" %s" % colorize_word(runner.status()))
- if runner.failed() or runner.skipped():
- print(runner.get_formatted_exception_trace())
- root.setLevel(level)
- filter.patterns = patterns
- return TestResult(end - start,
- runner.passed(),
- runner.skipped(),
- runner.failed(),
- runner.get_exception_type(),
- runner.get_exception_message(),
- runner.get_formatted_exception_trace())
+ sys.stdout.flush()
+ interceptor.begin()
+ start = time.time()
+ try:
+ runner = test()
+ finally:
+ interceptor.reset()
+ end = time.time()
+ if interceptor.dirty:
+ if interceptor.last != "\n":
+ sys.stdout.write("\n")
+ sys.stdout.write(output)
+ print(" %s" % colorize_word(runner.status()))
+ if runner.failed() or runner.skipped():
+ print(runner.get_formatted_exception_trace())
+ root.setLevel(level)
+ filter.patterns = patterns
+ return TestResult(end - start,
+ runner.passed(),
+ runner.skipped(),
+ runner.failed(),
+ runner.get_exception_type(),
+ runner.get_exception_message(),
+ runner.get_formatted_exception_trace())
+
class TestResult:
- def __init__(self, time, passed, skipped, failed, exception_type,
exception_message, formatted_exception_trace):
- self.time = time
- self.passed = passed
- self.skipped = skipped
- self.failed = failed
- self.exception_type = exception_type
- self.exception_message = exception_message
- self.formatted_exception_trace = formatted_exception_trace
+ def __init__(self, time, passed, skipped, failed, exception_type,
exception_message, formatted_exception_trace):
+ self.time = time
+ self.passed = passed
+ self.skipped = skipped
+ self.failed = failed
+ self.exception_type = exception_type
+ self.exception_message = exception_message
+ self.formatted_exception_trace = formatted_exception_trace
+
class FunctionTest:
- def __init__(self, test):
- self.test = test
+ def __init__(self, test):
+ self.test = test
+
+ def name(self):
+ return "%s.%s" % (self.test.__module__, self.test.__name__)
- def name(self):
- return "%s.%s" % (self.test.__module__, self.test.__name__)
+ def run(self):
+ return run_test(self.name(), self._run, config)
- def run(self):
- return run_test(self.name(), self._run, config)
+ def _run(self):
+ runner = Runner()
+ runner.run("test", lambda: self.test(config))
+ return runner
- def _run(self):
- runner = Runner()
- runner.run("test", lambda: self.test(config))
- return runner
+ def __repr__(self):
+ return "FunctionTest(%r)" % self.test
- def __repr__(self):
- return "FunctionTest(%r)" % self.test
class MethodTest:
- def __init__(self, cls, method):
- self.cls = cls
- self.method = method
+ def __init__(self, cls, method):
+ self.cls = cls
+ self.method = method
- def name(self):
- return "%s.%s.%s" % (self.cls.__module__, self.cls.__name__, self.method)
+ def name(self):
+ return "%s.%s.%s" % (self.cls.__module__, self.cls.__name__,
self.method)
- def run(self):
- return run_test(self.name(), self._run, config)
+ def run(self):
+ return run_test(self.name(), self._run, config)
- def _run(self):
- runner = Runner()
- inst = self.cls(self.method)
- test = getattr(inst, self.method)
+ def _run(self):
+ runner = Runner()
+ inst = self.cls(self.method)
+ test = getattr(inst, self.method)
- if hasattr(inst, "configure"):
- runner.run("configure", lambda: inst.configure(config))
- if runner.halt(): return runner
- if hasattr(inst, "setUp"):
- runner.run("setup", inst.setUp)
- if runner.halt(): return runner
+ if hasattr(inst, "configure"):
+ runner.run("configure", lambda: inst.configure(config))
+ if runner.halt():
+ return runner
+ if hasattr(inst, "setUp"):
+ runner.run("setup", inst.setUp)
+ if runner.halt():
+ return runner
- runner.run("test", test)
+ runner.run("test", test)
- if hasattr(inst, "tearDown"):
- runner.run("teardown", inst.tearDown)
+ if hasattr(inst, "tearDown"):
+ runner.run("teardown", inst.tearDown)
- return runner
+ return runner
+
+ def __repr__(self):
+ return "MethodTest(%r, %r)" % (self.cls, self.method)
- def __repr__(self):
- return "MethodTest(%r, %r)" % (self.cls, self.method)
class PatternMatcher:
- def __init__(self, *patterns):
- self.patterns = patterns
+ def __init__(self, *patterns):
+ self.patterns = patterns
+
+ def matches(self, name):
+ for p in self.patterns:
+ if match(name, p):
+ return True
+ return False
- def matches(self, name):
- for p in self.patterns:
- if match(name, p):
- return True
- return False
class FunctionScanner(PatternMatcher):
- def inspect(self, obj):
- return type(obj) == types.FunctionType and self.matches(obj.__name__)
+ def inspect(self, obj):
+ return type(obj) == types.FunctionType and self.matches(obj.__name__)
+
+ def descend(self, func):
+ # the None is required for older versions of python
+ return
+ yield None
Review comment:
No idea. Yield was added in Python 2.5 and yield without that `None`
works for me in Python 2.7. So the "older versions" was either 2.5 or 2.6, or
both, or maybe Jython?
Anyways, it is trying to create an empty generator function. After some
googling, I think that this code can be replaced with
```python
def extract(self, obj):
return ()
```
or, if we want to maintain the precise type,
```python
def extract(self, obj):
return iter(())
```
This is better because return; yield can trigger warnings about unreachable
code in some tooling.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Apply autofixes to resolve some flake8 code formatting issues
> -------------------------------------------------------------
>
> Key: PROTON-2320
> URL: https://issues.apache.org/jira/browse/PROTON-2320
> Project: Qpid Proton
> Issue Type: Task
> Components: python-binding
> Affects Versions: proton-c-0.33.0
> Reporter: Jiri Daněk
> Assignee: Jiri Daněk
> Priority: Major
> Fix For: proton-c-0.34.0
>
>
> Python code in Proton does not follow PEP8. There are automated tools which
> can reformat the code to be more compliant (fix indentation, add spaces
> around operators, ...).
> {noformat}
> pip install autopep8
> for f in `find -name "*.py"`; do autopep8 --in-place $f; done
> {noformat}
> Autopep8 has several level of "aggressiveness". The least aggressive setting
> only changes whitespace. At a more aggressive setting, autopep8 will also
> rewrite some code constructs.
> My plan is to commit this in several stages. Avoid mixing manual changes and
> automatically generated changes in a single commit. Push the whitespace
> changes first and only then let autopep8 to be more creative; otherwise the
> rewrites get drowned in the huge initial diff.
> I don't want to add flake8 to CI jobs just yet; I want to wait a few days
> with that.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]