Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pytype/pytd/pytd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ def match(self, t1, t2, *args, **kwargs):
if f:
return f(t1, t2, *args, **kwargs)
else:
# TODO(b/117657518): Remove the disable once the pytype bug is fixed
return self.default_match(t1, t2, *args, **kwargs) # pytype: disable=wrong-arg-count
return self.default_match(t1, t2, *args, **kwargs)


def CanonicalOrdering(n, sort_signatures=False):
Expand Down
11 changes: 6 additions & 5 deletions pytype/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class BaseTest(unittest.TestCase):

@classmethod
def setUpClass(cls):
super(BaseTest, cls).setUpClass()
# We use class-wide loader to avoid creating a new loader for every test
# method if not required.
cls._loader = None
Expand Down Expand Up @@ -156,6 +157,7 @@ def t(name): # pylint: disable=invalid-name
(cls.nothing, cls.nothing))

def setUp(self):
super(BaseTest, self).setUp()
# The test class (type of |self|) constructor is required to initialize the
# 'python_version' attribute.
assert hasattr(self, "python_version")
Expand Down Expand Up @@ -284,11 +286,10 @@ def assertHasOnlySignatures(self, func, *sigs):
format(name=func.name,
sig=self.PrintSignature(parameter_types, return_type),
func=pytd.Print(func)))
self.assertEqual(len(func.signatures), len(sigs),
"{func} has the wrong number of signatures ({has}), "
"expected {expect}".
format(func=func,
has=len(func.signatures), expect=len(sigs)))
msg = ("{func} has the wrong number of signatures ({has}), "
"expected {expect}".format(
func=func, has=len(func.signatures), expect=len(sigs)))
self.assertEqual(len(func.signatures), len(sigs), msg)

def assertHasSignature(self, func, parameter_types, return_type):
if not self.HasSignature(func, parameter_types, return_type):
Expand Down
10 changes: 7 additions & 3 deletions pytype/tools/analyze_project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ def main():
import_graph = importlab.graph.ImportGraph.create(
env, conf.inputs, trim=True)
unreadable_inputs = conf.inputs & import_graph.unreadable_files
assert not unreadable_inputs, '\n '.join(
unreadable_python_inputs = {
filename for filename in unreadable_inputs if filename.endswith('.py')}
assert not unreadable_python_inputs, '\n '.join(
['Unparseable in Python %s:' % conf.python_version] +
sorted(unreadable_inputs))
sorted(unreadable_python_inputs))
except Exception as e: # pylint: disable=broad-except
logging.critical('Cannot parse input files:\n%s', str(e))
logging.critical('Cannot parse input files:\n%s', e)
sys.exit(1)

conf.inputs -= unreadable_inputs

if args.tree:
print('Source tree:')
importlab.output.print_tree(import_graph)
Expand Down
4 changes: 4 additions & 0 deletions pytype/tools/analyze_project/pytype_runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class TestDepsFromImportGraph(unittest.TestCase):
"""Test deps_from_import_graph."""

def setUp(self):
super(TestDepsFromImportGraph, self).setUp()
init = ImportlabModule('/foo/bar/__init__.py', 'bar/__init__.py', 'bar')
a = ImportlabModule('/foo/bar/a.py', 'bar/a.py', 'bar.a')
b = ImportlabModule('/foo/bar/b.py', 'bar/b.py', 'bar.b')
Expand Down Expand Up @@ -104,13 +105,15 @@ class TestBase(unittest.TestCase):

@classmethod
def setUpClass(cls):
super(TestBase, cls).setUpClass()
cls.parser = parse_args.make_parser()


class TestCustomOptions(TestBase):
"""Test PytypeRunner.set_custom_options."""

def setUp(self):
super(TestCustomOptions, self).setUp()
self.conf = self.parser.config_from_defaults()

# --disable tests a flag with a string value.
Expand Down Expand Up @@ -180,6 +183,7 @@ class TestGetRunCmd(TestBase):
"""Test PytypeRunner.get_pytype_command_for_ninja()."""

def setUp(self):
super(TestGetRunCmd, self).setUp()
self.runner = make_runner([], [], self.parser.config_from_defaults())

def get_options(self, args):
Expand Down
4 changes: 2 additions & 2 deletions pytype/typegraph/cfg_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def testSimpleGraph(self):
self.assertEqual(0, n1.id)
self.assertEqual("foo", n1.name)
self.assertEqual(len(n1.outgoing), 2)
self.assertEqual(len(n2.outgoing), 0)
self.assertEqual(len(n2.outgoing), 0) # pylint: disable=g-generic-assert
self.assertEqual(len(n3.outgoing), 1)
self.assertEqual(len(n2.incoming), 1)
self.assertEqual(len(n3.incoming), 1)
Expand Down Expand Up @@ -763,7 +763,7 @@ def testPruneTwoOrigins(self):
b = x.AddBinding(1)
b.AddOrigin(source_set=[], where=n1)
b.AddOrigin(source_set=[], where=n2)
self.assertEqual(1, len([v.data for v in x.Bindings(n3)]))
self.assertEqual(len([v.data for v in x.Bindings(n3)]), 1)

def testHiddenConflict3(self):
p = cfg.Program()
Expand Down