Skip to content

Commit

Permalink
fix: lint with autopep8
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjinkun committed Dec 28, 2020
1 parent bed71db commit d2b6b0e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 19 deletions.
8 changes: 5 additions & 3 deletions launchable/commands/record/case_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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)

Expand All @@ -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 (
Expand Down
6 changes: 4 additions & 2 deletions launchable/commands/record/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 9 additions & 5 deletions launchable/commands/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# TODO: rename files and function accordingly once the PR landscape


@click.group(help="Subsetting tests")
@click.option(
'--target',
Expand All @@ -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',
Expand All @@ -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 = []
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
}

Expand Down
6 changes: 4 additions & 2 deletions launchable/test_runners/bazel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion launchable/test_runners/launchable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 4 additions & 3 deletions launchable/test_runners/minitest.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion launchable/testpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions launchable/utils/click.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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()

0 comments on commit d2b6b0e

Please sign in to comment.