Commit dd656cc0 authored by Brian Sheedy's avatar Brian Sheedy Committed by Commit Bot

Switch NaCL Python tests to use vpython mock

Switches the NaCL Python tests to use the version of mock/pymock
provided by vpython instead of manually importing the version from
//third_party/pymock. This is so that the //third_party version can
eventually be removed.

Also drive-by fixes some unidiomatic-typecheck PyLint warnings that
presubmit complained about.

Bug: 1094489
Change-Id: I886a9eaa9130c8babbefc40281c0de7f984026c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2254583
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Commit-Queue: Sam Clegg <sbc@chromium.org>
Reviewed-by: default avatarSam Clegg <sbc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780408}
parent d13ce126
......@@ -113,14 +113,14 @@ class Archive(object):
buildbot_common.MakeDir(self.dirname)
def Copy(self, src_root, file_list):
if type(file_list) is not list:
if not isinstance(file_list, list):
file_list = [file_list]
for file_spec in file_list:
# The list of files to install can be a simple list of
# strings or a list of pairs, where each pair corresponds
# to a mapping from source to destination names.
if type(file_spec) is str:
if isinstance(file_spec, str):
src_file = dest_file = file_spec
else:
src_file, dest_file = file_spec
......@@ -192,7 +192,7 @@ def MakeNinjaRelPath(path):
def NinjaBuild(targets, out_dir):
if type(targets) is not list:
if not isinstance(targets, list):
targets = [targets]
out_config_dir = os.path.join(out_dir, 'Release')
buildbot_common.Run(['ninja', '-C', out_config_dir] + targets, cwd=SRC_DIR)
......
......@@ -284,7 +284,7 @@ def InstallFiles(src_root, dest_root, file_list):
# The list of files to install can be a simple list of
# strings or a list of pairs, where each pair corresponds
# to a mapping from source to destination names.
if type(file_spec) == str:
if isinstance(file_spec, str):
src_file = dest_file = file_spec
else:
src_file, dest_file = file_spec
......
......@@ -91,7 +91,7 @@ def ExtractArchive(archive_path, destdirs):
Untar(archive_path, EXTRACT_ARCHIVE_DIR)
basename = RemoveExt(os.path.basename(archive_path))
srcdir = os.path.join(EXTRACT_ARCHIVE_DIR, basename)
if type(destdirs) is not list:
if not isinstance(destdirs, list):
destdirs = [destdirs]
for destdir in destdirs:
......@@ -106,7 +106,7 @@ def ExtractAll(archive_dict, archive_dir, destroot):
for archive_part, rel_destdirs in archive_dict:
archive_name = '%s_%s.tar.bz2' % (PLATFORM, archive_part)
archive_path = os.path.join(archive_dir, archive_name)
if type(rel_destdirs) is not list:
if not isinstance(rel_destdirs, list):
rel_destdirs = [rel_destdirs]
destdirs = [os.path.join(destroot, d) for d in rel_destdirs]
ExtractArchive(archive_path, destdirs)
......
......@@ -102,12 +102,12 @@ def ValidateFormat(src, dsc_format):
# then the list applies to all keys of the dictionary, so we reset
# the expected type and value.
if exp_type is dict:
if type(value) is list:
if isinstance(value, list):
exp_type = list
exp_value = ''
# Verify the key is of the expected type
if exp_type != type(value):
if not isinstance(value, exp_type):
raise ValidationError('Key %s expects %s not %s.' % (
key, exp_type.__name__.upper(), type(value).__name__.upper()))
......@@ -117,7 +117,7 @@ def ValidateFormat(src, dsc_format):
# If it's a string and there are expected values, make sure it matches
if exp_type is str:
if type(exp_value) is list and exp_value:
if isinstance(exp_value, list) and exp_value:
if value not in exp_value:
raise ValidationError("Value '%s' not expected for %s." %
(value, key))
......@@ -126,19 +126,19 @@ def ValidateFormat(src, dsc_format):
# if it's a list, then we need to validate the values
if exp_type is list:
# If we expect a dictionary, then call this recursively
if type(exp_value) is dict:
if isinstance(exp_value, dict):
for val in value:
ValidateFormat(val, exp_value)
continue
# If we expect a list of strings
if type(exp_value) is str:
if isinstance(exp_value, str):
for val in value:
if type(val) is not str:
if not isinstance(val, str):
raise ValidationError('Value %s in %s is not a string.' %
(val, key))
continue
# if we expect a particular string
if type(exp_value) is list:
if isinstance(exp_value, list):
for val in value:
if val not in exp_value:
raise ValidationError('Value %s not expected in %s.' %
......@@ -228,9 +228,9 @@ def DescMatchesFilter(desc, filters):
value = desc.get(key, False)
# If we provide an expected list, match at least one
if type(expected) not in (list, tuple):
if not isinstance(expected, (list, tuple)):
expected = set([expected])
if type(value) != list:
if not isinstance(value, list):
value = set([value])
if not set(expected) & set(value):
......
......@@ -222,7 +222,7 @@ def GetTestName(desc, toolchain, config):
def IsTestDisabled(desc, toolchain, config):
def AsList(value):
if type(value) not in (list, tuple):
if not isinstance(value, (list, tuple)):
return [value]
return value
......
#!/usr/bin/env python
#!/usr/bin/env vpython
# Copyright (c) 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -13,10 +13,7 @@ import unittest
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(BUILD_TOOLS_DIR)))
MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
# For the mock library
sys.path.append(MOCK_DIR)
from mock import call, patch, Mock
sys.path.append(BUILD_TOOLS_DIR)
......
#!/usr/bin/env python
#!/usr/bin/env vpython
# Copyright (c) 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -11,10 +11,7 @@ import unittest
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(BUILD_TOOLS_DIR)))
MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
# For the mock library
sys.path.append(MOCK_DIR)
import mock
sys.path.append(BUILD_TOOLS_DIR)
......
#!/usr/bin/env python
#!/usr/bin/env vpython
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -12,11 +12,9 @@ import unittest
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR)))
MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
sys.path.append(BUILD_TOOLS_DIR)
sys.path.append(MOCK_DIR)
import easy_template
import mock
......
#!/usr/bin/env python
#!/usr/bin/env vpython
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -10,10 +10,8 @@ import unittest
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(BUILD_TOOLS_DIR)))
MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
sys.path.append(BUILD_TOOLS_DIR)
sys.path.append(MOCK_DIR)
import mock
import test_projects
......
#!/usr/bin/env python
#!/usr/bin/env vpython
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -10,10 +10,7 @@ import unittest
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(BUILD_TOOLS_DIR)))
MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
# For the mock library
sys.path.append(MOCK_DIR)
import mock
sys.path.append(BUILD_TOOLS_DIR)
......
#!/usr/bin/env python
#!/usr/bin/env vpython
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......
......@@ -84,7 +84,7 @@ def main(args):
raise Error('%s does not have "platforms" key.' % options.manifest_json)
platforms = data['platforms']
if type(platforms) is not list:
if not isinstance(platforms, list):
raise Error('Expected "platforms" key to be array.')
if options.prefix:
......
#!/usr/bin/env python
#!/usr/bin/env vpython
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -11,10 +11,8 @@ import tempfile
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_DIR = os.path.dirname(SCRIPT_DIR)
CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(PARENT_DIR)))
MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
sys.path.append(PARENT_DIR)
sys.path.append(MOCK_DIR)
import create_html
import mock
......
#!/usr/bin/env python
#!/usr/bin/env vpython
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -16,10 +16,7 @@ TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
DATA_DIR = os.path.join(TOOLS_DIR, 'lib', 'tests', 'data')
BUILD_TOOLS_DIR = os.path.join(os.path.dirname(TOOLS_DIR), 'build_tools')
CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR)))
MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
# For the mock library
sys.path.append(MOCK_DIR)
sys.path.append(TOOLS_DIR)
sys.path.append(BUILD_TOOLS_DIR)
......@@ -287,9 +284,9 @@ class TestNmfUtils(unittest.TestCase):
new_k = StripSo(k)
if isinstance(v, (str, unicode)):
new_v = StripSo(v)
elif type(v) is list:
elif isinstance(v, list):
new_v = v[:]
elif type(v) is dict:
elif isinstance(v, dict):
new_v = StripSoCopyDict(v)
else:
# Assume that anything else can be copied directly.
......
#!/usr/bin/env python
#!/usr/bin/env vpython
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -11,10 +11,7 @@ SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_DIR = os.path.dirname(SCRIPT_DIR)
DATA_DIR = os.path.join(SCRIPT_DIR, 'data')
CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(PARENT_DIR)))
MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
# For the mock library
sys.path.append(MOCK_DIR)
sys.path.append(PARENT_DIR)
import fix_deps
......
#!/usr/bin/env python
#!/usr/bin/env vpython
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -12,10 +12,7 @@ import unittest
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR)))
MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
# For the mock library
sys.path.append(MOCK_DIR)
import mock
# For getos, the module under test
......
#!/usr/bin/env python
#!/usr/bin/env vpython
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -14,10 +14,8 @@ import urllib2
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR)))
MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
sys.path.append(TOOLS_DIR)
sys.path.append(MOCK_DIR)
import httpd
from mock import patch, Mock
......
#!/usr/bin/env python
#!/usr/bin/env vpython
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -10,10 +10,7 @@ import unittest
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR)))
MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
# For the mock library
sys.path.append(MOCK_DIR)
import mock
# For nacl_config, the module under test
......
#!/usr/bin/env python
#!/usr/bin/env vpython
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -11,10 +11,7 @@ SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_DIR = os.path.dirname(SCRIPT_DIR)
DATA_DIR = os.path.join(SCRIPT_DIR, 'data')
CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(PARENT_DIR)))
MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
# For the mock library
sys.path.append(MOCK_DIR)
sys.path.append(PARENT_DIR)
import sel_ldr
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment