From d2b6b0eebb33dd6bcc050aa65c69ae08d4f93178 Mon Sep 17 00:00:00 2001 From: ninjinkun Date: Mon, 28 Dec 2020 17:21:40 +0900 Subject: [PATCH] fix: lint with autopep8 --- launchable/commands/record/case_event.py | 8 +++++--- launchable/commands/record/tests.py | 6 ++++-- launchable/commands/subset.py | 14 +++++++++----- launchable/test_runners/bazel.py | 6 ++++-- launchable/test_runners/launchable.py | 3 ++- launchable/test_runners/minitest.py | 7 ++++--- launchable/testpath.py | 2 +- launchable/utils/click.py | 6 ++++-- 8 files changed, 33 insertions(+), 19 deletions(-) diff --git a/launchable/commands/record/case_event.py b/launchable/commands/record/case_event.py index 985b9c3ed..22f7f7db5 100644 --- a/launchable/commands/record/case_event.py +++ b/launchable/commands/record/case_event.py @@ -4,6 +4,7 @@ from junitparser import JUnitXml, Failure, Error, Skipped, TestCase, TestSuite from ...testpath import TestPath + class CaseEvent: EVENT_TYPE = "case" TEST_SKIPPED = 2 @@ -12,7 +13,7 @@ class CaseEvent: # function that computes TestPath from a test case # The 3rd argument is the report file path - TestPathBuilder = Callable[[TestCase,TestSuite,str], TestPath] + TestPathBuilder = Callable[[TestCase, TestSuite, str], TestPath] @staticmethod def default_path_builder(base_path) -> TestPathBuilder: @@ -22,7 +23,8 @@ def default_path_builder(base_path) -> TestPathBuilder: def f(case: TestCase, suite: TestSuite, report_file: str) -> TestPath: classname = case.classname or suite._elem.attrib.get("classname") - filepath = case._elem.attrib.get("file") or suite._elem.attrib.get("filepath") + filepath = case._elem.attrib.get( + "file") or suite._elem.attrib.get("filepath") if filepath: filepath = os.path.relpath(filepath, start=base_path) @@ -39,7 +41,7 @@ def f(case: TestCase, suite: TestSuite, report_file: str) -> TestPath: return f @classmethod - def from_case_and_suite(cls, path_builder: TestPathBuilder, case: TestCase, suite: TestSuite, report_file:str, data: Dict = None) -> Dict: + def from_case_and_suite(cls, path_builder: TestPathBuilder, case: TestCase, suite: TestSuite, report_file: str, data: Dict = None) -> Dict: "Builds a JSON representation of CaseEvent" status = CaseEvent.TEST_FAILED if case.result and any(isinstance(case.result, s) for s in ( diff --git a/launchable/commands/record/tests.py b/launchable/commands/record/tests.py index 1be24d52e..e59fd69dd 100644 --- a/launchable/commands/record/tests.py +++ b/launchable/commands/record/tests.py @@ -23,13 +23,15 @@ '--session', 'session_id', help='Test session ID', - required=os.getenv(REPORT_ERROR_KEY), # validate session_id under debug mode, + # validate session_id under debug mode, + required=os.getenv(REPORT_ERROR_KEY), type=str, ) @click.pass_context def tests(context, source, session_id: str): if not session_id: - click.echo("Session ID in --session is missing. It might be caused by Launchable API errors.", err=True) + click.echo( + "Session ID in --session is missing. It might be caused by Launchable API errors.", err=True) # intentionally exiting with zero return diff --git a/launchable/commands/subset.py b/launchable/commands/subset.py index a3af32732..8fe4db706 100644 --- a/launchable/commands/subset.py +++ b/launchable/commands/subset.py @@ -12,6 +12,7 @@ # TODO: rename files and function accordingly once the PR landscape + @click.group(help="Subsetting tests") @click.option( '--target', @@ -26,7 +27,8 @@ 'session_id', help='Test session ID', type=str, - required=os.getenv(REPORT_ERROR_KEY), # validate session_id under debug mode + # validate session_id under debug mode + required=os.getenv(REPORT_ERROR_KEY), ) @click.option( '--base', @@ -44,7 +46,7 @@ class Optimize: # test_paths: List[TestPath] # doesn't work with Python 3.5 # Where we take TestPath, we also accept a path name as a string. - TestPathLike = Union[str,TestPath] + TestPathLike = Union[str, TestPath] def __init__(self): self.test_paths = [] @@ -100,14 +102,15 @@ def scan(self, base: str, pattern: str, path_builder: Callable[[str], Union[Test - if a TestPath is returned, that's added as is """ - if path_builder==None: + if path_builder == None: # default implementation of path_builder creates a file name relative to `source` so as not # to be affected by the path def default_path_builder(file_name): file_name = join(base, file_name) if base_path: # relativize against `base_path` to make the path name portable - file_name = normpath(relpath(file_name, start=base_path)) + file_name = normpath( + relpath(file_name, start=base_path)) return file_name path_builder = default_path_builder @@ -135,7 +138,8 @@ def run(self): "testPaths": self.test_paths, "target": target, "session": { - "id": os.path.basename(session_id) # expecting just the last component, not the whole path + # expecting just the last component, not the whole path + "id": os.path.basename(session_id) } } diff --git a/launchable/test_runners/bazel.py b/launchable/test_runners/bazel.py index 3967892cc..ab63bbf7c 100644 --- a/launchable/test_runners/bazel.py +++ b/launchable/test_runners/bazel.py @@ -12,13 +12,14 @@ def make_test_path(pkg, target) -> TestPath: return [{'type': 'package', 'name': pkg}, {'type': 'target', 'name': target}] + @launchable.subset def subset(client): # Read targets from stdin, which generally looks like //foo/bar:zot for label in sys.stdin: # //foo/bar:zot -> //foo/bar & zot if label.startswith('//'): - pkg,target = label.rstrip('\n').split(':') + pkg, target = label.rstrip('\n').split(':') # TODO: error checks and more robustness client.test_path(make_test_path(pkg, target)) @@ -46,7 +47,8 @@ def f(case: TestCase, suite: TestSuite, report_file: str) -> TestPath: # last path component is the target, the rest is package # TODO: does this work correctly when on Windows? - path = make_test_path(os.path.dirname(pkgNtarget), os.path.basename(pkgNtarget)) + path = make_test_path(os.path.dirname(pkgNtarget), + os.path.basename(pkgNtarget)) # let the normal path building kicks in path.extend(default_path_builder(case, suite, report_file)) diff --git a/launchable/test_runners/launchable.py b/launchable/test_runners/launchable.py index f891a2412..fa8933e3f 100644 --- a/launchable/test_runners/launchable.py +++ b/launchable/test_runners/launchable.py @@ -24,7 +24,8 @@ def wrap(f, group): return cmd -subset = lambda f: wrap(f, subset_cmd) +def subset(f): return wrap(f, subset_cmd) + record = types.SimpleNamespace() record.tests = lambda f: wrap(f, record_tests_cmd) diff --git a/launchable/test_runners/minitest.py b/launchable/test_runners/minitest.py index dc1e0b15c..3e66c30d6 100644 --- a/launchable/test_runners/minitest.py +++ b/launchable/test_runners/minitest.py @@ -1,18 +1,19 @@ import click -import os, sys +import os +import sys from . import launchable @click.argument('files', required=True, nargs=-1) @launchable.subset def subset(client, files): - def parse(fname:str): + def parse(fname: str): ''' Scan a file, directory full of *.rb, or @FILE ''' if os.path.isdir(fname): client.scan(fname, '**/*_test.rb') - elif fname=='@-': + elif fname == '@-': # read stdin for l in sys.stdin: parse(l) diff --git a/launchable/testpath.py b/launchable/testpath.py index 04b39c876..a5791a4ec 100644 --- a/launchable/testpath.py +++ b/launchable/testpath.py @@ -3,7 +3,7 @@ # Path component is a node in a tree. # It's the equivalent of a short file/directory name in a file system. # In our abstraction, it's represented as arbitrary bag of attributes -TestPathComponent = Dict[str,str] +TestPathComponent = Dict[str, str] # TestPath is a full path to a node in a tree from the root # It's the equivalent of an absolute file name in a file system diff --git a/launchable/utils/click.py b/launchable/utils/click.py index 3cb7e8746..29db6cdb2 100644 --- a/launchable/utils/click.py +++ b/launchable/utils/click.py @@ -15,6 +15,7 @@ def get_command(self, ctx, cmd_name): def add_alias(self, name, cmd): self.aliases[name] = cmd + class PercentageType(click.ParamType): name = "percentage" @@ -27,7 +28,8 @@ def convert(self, value: str, param, ctx): except ValueError: pass - self.fail("Expected percentage like 50% but got '{}'".format(value), param, ctx) + self.fail("Expected percentage like 50% but got '{}'".format( + value), param, ctx) -PERCENTAGE = PercentageType() +PERCENTAGE = PercentageType()