From eaacaac29de8cd22a4a1d4227a9f4f84b718e1fd Mon Sep 17 00:00:00 2001 From: Logan Chien Date: Thu, 3 Jan 2019 18:43:26 +0800 Subject: [PATCH] vndk-def: Cleanup import pylint errors Test: ./tests/run.sh Change-Id: I6fc9fcef8164fb1f795f5902d900f34e99b1228d --- vndk/tools/definition-tool/tests/compat.py | 4 ++- .../definition-tool/tests/ndk_toolchain.py | 24 -------------- vndk/tools/definition-tool/tests/run.py | 21 ------------ vndk/tools/definition-tool/tests/run.sh | 22 +++++++++++++ .../tests/test_command_deps_insight.py | 13 ++------ .../definition-tool/tests/test_dex_file.py | 10 ++---- vndk/tools/definition-tool/tests/test_elf.py | 11 ++----- .../tests/test_elf_link_data.py | 8 ----- .../definition-tool/tests/test_elf_linker.py | 16 ++-------- .../tests/test_elf_resolver.py | 8 ----- .../definition-tool/tests/test_elfdump.py | 32 ++----------------- .../tests/test_generic_refs.py | 9 ------ .../definition-tool/tests/test_module_info.py | 7 ---- .../definition-tool/tests/test_tagged_dict.py | 11 ++----- vndk/tools/definition-tool/tests/test_vndk.py | 13 ++------ .../tests/test_vndk_lib_dir.py | 10 ++---- vndk/tools/definition-tool/tests/utils.py | 7 +--- 17 files changed, 46 insertions(+), 180 deletions(-) mode change 100755 => 100644 vndk/tools/definition-tool/tests/ndk_toolchain.py delete mode 100755 vndk/tools/definition-tool/tests/run.py create mode 100755 vndk/tools/definition-tool/tests/run.sh mode change 100755 => 100644 vndk/tools/definition-tool/tests/test_command_deps_insight.py mode change 100755 => 100644 vndk/tools/definition-tool/tests/test_dex_file.py mode change 100755 => 100644 vndk/tools/definition-tool/tests/test_elf.py mode change 100755 => 100644 vndk/tools/definition-tool/tests/test_elf_link_data.py mode change 100755 => 100644 vndk/tools/definition-tool/tests/test_elf_linker.py mode change 100755 => 100644 vndk/tools/definition-tool/tests/test_elf_resolver.py mode change 100755 => 100644 vndk/tools/definition-tool/tests/test_elfdump.py mode change 100755 => 100644 vndk/tools/definition-tool/tests/test_generic_refs.py mode change 100755 => 100644 vndk/tools/definition-tool/tests/test_module_info.py mode change 100755 => 100644 vndk/tools/definition-tool/tests/test_tagged_dict.py mode change 100755 => 100644 vndk/tools/definition-tool/tests/test_vndk.py mode change 100755 => 100644 vndk/tools/definition-tool/tests/test_vndk_lib_dir.py diff --git a/vndk/tools/definition-tool/tests/compat.py b/vndk/tools/definition-tool/tests/compat.py index 7fcbc2e93..71841ecf7 100644 --- a/vndk/tools/definition-tool/tests/compat.py +++ b/vndk/tools/definition-tool/tests/compat.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 -import os +# pylint: disable=unused-import,import-error + import sys @@ -37,6 +38,7 @@ except ImportError: if sys.version_info >= (3, 0): from os import makedirs else: + import os def makedirs(path, exist_ok): if exist_ok and os.path.exists(path): return diff --git a/vndk/tools/definition-tool/tests/ndk_toolchain.py b/vndk/tools/definition-tool/tests/ndk_toolchain.py old mode 100755 new mode 100644 index 3411e4c85..e040787dd --- a/vndk/tools/definition-tool/tests/ndk_toolchain.py +++ b/vndk/tools/definition-tool/tests/ndk_toolchain.py @@ -2,7 +2,6 @@ from __future__ import print_function -import argparse import collections import os import re @@ -190,26 +189,3 @@ def create_targets(ndk_dir=None, api=None, host=None): get_platform_dir(ndk_dir, api, ['arch-mips64', 'usr', 'lib64'])) return targets - - -def main(): - parser = argparse.ArgumentParser( - description='Dry-run NDK toolchain detection') - parser.add_argument('--ndk-dir') - parser.add_argument('--api-level') - parser.add_argument('--host') - args = parser.parse_args() - - targets = create_targets(args.ndk_dir, args.api_level, args.host) - - success = True - for name, target in targets.items(): - success &= target.check_paths() - if not success: - sys.exit(1) - - print('succeed') - - -if __name__ == '__main__': - main() diff --git a/vndk/tools/definition-tool/tests/run.py b/vndk/tools/definition-tool/tests/run.py deleted file mode 100755 index 2837d5cef..000000000 --- a/vndk/tools/definition-tool/tests/run.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import os -import unittest - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--verbose', '-v', action='store_true') - args = parser.parse_args() - - verbosity = 2 if args.verbose else 1 - - loader = unittest.TestLoader() - tests = loader.discover(os.path.dirname(__file__), 'test_*.py') - runner = unittest.runner.TextTestRunner(verbosity=verbosity) - runner.run(tests) - -if __name__ == '__main__': - main() diff --git a/vndk/tools/definition-tool/tests/run.sh b/vndk/tools/definition-tool/tests/run.sh new file mode 100755 index 000000000..3a3114567 --- /dev/null +++ b/vndk/tools/definition-tool/tests/run.sh @@ -0,0 +1,22 @@ +#!/bin/bash -ex + +# +# Copyright (C) 2018 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +cd "$(dirname "$0")/.." + +python3 -m unittest discover "$@" +python -m unittest discover "$@" diff --git a/vndk/tools/definition-tool/tests/test_command_deps_insight.py b/vndk/tools/definition-tool/tests/test_command_deps_insight.py old mode 100755 new mode 100644 index 7777826ff..9e8332a55 --- a/vndk/tools/definition-tool/tests/test_command_deps_insight.py +++ b/vndk/tools/definition-tool/tests/test_command_deps_insight.py @@ -2,16 +2,13 @@ from __future__ import print_function -import os -import sys import unittest -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - -from compat import StringIO, patch from vndk_definition_tool import ( DepsInsightCommand, ModuleInfo, PT_SYSTEM, PT_VENDOR) -from utils import GraphBuilder + +from .compat import StringIO, patch +from .utils import GraphBuilder class DepsInsightCommandTest(unittest.TestCase): @@ -82,7 +79,3 @@ class DepsInsightCommandTest(unittest.TestCase): users = self._get_module_users(strs, mods, libvnd_bad.path) self.assertIn(libvndk.path, users) self.assertIn(libvndk_sp.path, users) - - -if __name__ == '__main__': - unittest.main() diff --git a/vndk/tools/definition-tool/tests/test_dex_file.py b/vndk/tools/definition-tool/tests/test_dex_file.py old mode 100755 new mode 100644 index fe2644fef..c558fa9ab --- a/vndk/tools/definition-tool/tests/test_dex_file.py +++ b/vndk/tools/definition-tool/tests/test_dex_file.py @@ -4,15 +4,13 @@ from __future__ import print_function import os import subprocess -import sys import unittest import zipfile -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - -from compat import TemporaryDirectory from vndk_definition_tool import DexFileReader, UnicodeSurrogateDecodeError +from .compat import TemporaryDirectory + SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) INPUT_DIR = os.path.join(SCRIPT_DIR, 'testdata', 'test_dex_file') @@ -122,7 +120,3 @@ class DexFileTest(unittest.TestCase): self.assertIn(b'world', strs) self.assertIn(b'foo', strs) self.assertIn(b'bar', strs) - - -if __name__ == '__main__': - unittest.main() diff --git a/vndk/tools/definition-tool/tests/test_elf.py b/vndk/tools/definition-tool/tests/test_elf.py old mode 100755 new mode 100644 index 160911d0e..035a1af54 --- a/vndk/tools/definition-tool/tests/test_elf.py +++ b/vndk/tools/definition-tool/tests/test_elf.py @@ -2,16 +2,13 @@ from __future__ import print_function -import os -import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - import tempfile import unittest -from compat import StringIO from vndk_definition_tool import Elf_Sym, ELF +from .compat import StringIO + class ElfSymTest(unittest.TestCase): def setUp(self): @@ -223,7 +220,3 @@ class ELFJniLibTest(unittest.TestCase): elf = ELF(exported_symbols={'printf'}) self.assertFalse(elf.is_jni_lib()) - - -if __name__ == '__main__': - unittest.main() diff --git a/vndk/tools/definition-tool/tests/test_elf_link_data.py b/vndk/tools/definition-tool/tests/test_elf_link_data.py old mode 100755 new mode 100644 index 98ae69243..7191919aa --- a/vndk/tools/definition-tool/tests/test_elf_link_data.py +++ b/vndk/tools/definition-tool/tests/test_elf_link_data.py @@ -2,10 +2,6 @@ from __future__ import print_function -import os -import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - import unittest from vndk_definition_tool import ELFLinkData, PT_SYSTEM, PT_VENDOR @@ -108,7 +104,3 @@ class ELFLinkDataTest(unittest.TestCase): self.assertEqual(['w', 'x', 'y', 'z'], self.x.get_dep_linked_symbols(self.z)) - - -if __name__ == '__main__': - unittest.main() diff --git a/vndk/tools/definition-tool/tests/test_elf_linker.py b/vndk/tools/definition-tool/tests/test_elf_linker.py old mode 100755 new mode 100644 index 52f4a9145..c553705d8 --- a/vndk/tools/definition-tool/tests/test_elf_linker.py +++ b/vndk/tools/definition-tool/tests/test_elf_linker.py @@ -1,20 +1,14 @@ #!/usr/bin/env python3 -import os import re -import sys import tempfile import unittest -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - -from compat import StringIO, patch -from utils import GraphBuilder from vndk_definition_tool import ( - ELF, ELFLinker, GenericRefs, PT_SYSTEM, PT_VENDOR, VNDKLibDir) + ELF, GenericRefs, PT_SYSTEM, PT_VENDOR, VNDKLibDir) - -SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) +from .compat import StringIO, patch +from .utils import GraphBuilder class ELFLinkerTest(unittest.TestCase): @@ -564,7 +558,3 @@ class ELFLinkerDlopenDepsTest(unittest.TestCase): stderr.getvalue(), 'error:' + re.escape(tmp_file.name) + ':1: ' + 'Failed to add dlopen dependency from .* to .*\\.\n') - - -if __name__ == '__main__': - unittest.main() diff --git a/vndk/tools/definition-tool/tests/test_elf_resolver.py b/vndk/tools/definition-tool/tests/test_elf_resolver.py old mode 100755 new mode 100644 index 9ca0fd538..f6257f5fb --- a/vndk/tools/definition-tool/tests/test_elf_resolver.py +++ b/vndk/tools/definition-tool/tests/test_elf_resolver.py @@ -2,10 +2,6 @@ from __future__ import print_function -import os -import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - import unittest from vndk_definition_tool import ELFResolver @@ -94,7 +90,3 @@ class ELFResolverTest(unittest.TestCase): 'a2', r.resolve('/system/lib/libreq.so', 'liba.so', dt_runpath=['/vendor/lib'])) - - -if __name__ == '__main__': - unittest.main() diff --git a/vndk/tools/definition-tool/tests/test_elfdump.py b/vndk/tools/definition-tool/tests/test_elfdump.py old mode 100755 new mode 100644 index 888c2d246..18db2fd96 --- a/vndk/tools/definition-tool/tests/test_elfdump.py +++ b/vndk/tools/definition-tool/tests/test_elfdump.py @@ -2,17 +2,14 @@ from __future__ import print_function -import argparse -import collections -import difflib import os import re import subprocess import sys import unittest -from compat import TemporaryDirectory, makedirs -import ndk_toolchain +from .compat import TemporaryDirectory, makedirs +from .ndk_toolchain import create_targets SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -31,7 +28,7 @@ def run_elf_dump(path): class ELFDumpTest(unittest.TestCase): @classmethod def setUpClass(cls): - cls.targets = ndk_toolchain.create_targets() + cls.targets = create_targets() if test_dir_base: cls.test_dir_base = test_dir_base @@ -167,26 +164,3 @@ def create_target_test(target_name): for target in ('arm', 'arm64', 'mips', 'mips64', 'x86', 'x86_64'): create_target_test(target) - - -def main(): - # Parse command line arguments. - parser = argparse.ArgumentParser() - parser.add_argument('--test-dir', help='directory for temporary files') - parser.add_argument('--expected-dir', help='directory with expected output') - args, unittest_args = parser.parse_known_args() - - # Convert command line options. - global expected_dir - global test_dir_base - - if args.expected_dir: - expected_dir = args.expected_dir - if args.test_dir: - test_dir_base = args.test_dir - - # Run unit test. - unittest.main(argv=[sys.argv[0]] + unittest_args) - -if __name__ == '__main__': - main() diff --git a/vndk/tools/definition-tool/tests/test_generic_refs.py b/vndk/tools/definition-tool/tests/test_generic_refs.py old mode 100755 new mode 100644 index 349debca5..c3afeaecc --- a/vndk/tools/definition-tool/tests/test_generic_refs.py +++ b/vndk/tools/definition-tool/tests/test_generic_refs.py @@ -3,13 +3,8 @@ from __future__ import print_function import os -import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - -import argparse import unittest -from compat import TemporaryDirectory, makedirs from vndk_definition_tool import GenericRefs @@ -96,7 +91,3 @@ class GenericRefsTest(unittest.TestCase): MockLib('/vendor/lib/libc.so', {}))) self.assertFalse(self.ref.has_same_name_lib( MockLib('/vendor/lib/lib_does_not_exist.so', {}))) - - -if __name__ == '__main__': - unittest.main() diff --git a/vndk/tools/definition-tool/tests/test_module_info.py b/vndk/tools/definition-tool/tests/test_module_info.py old mode 100755 new mode 100644 index d44a9eb6f..b9a7cdddd --- a/vndk/tools/definition-tool/tests/test_module_info.py +++ b/vndk/tools/definition-tool/tests/test_module_info.py @@ -3,9 +3,6 @@ from __future__ import print_function import os -import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - import unittest from vndk_definition_tool import ModuleInfo @@ -35,7 +32,3 @@ class ModuleInfoTest(unittest.TestCase): self.assertEqual( [], m.get_module_path('/system/lib64/libdoes_not_exist.so')) - - -if __name__ == '__main__': - unittest.main() diff --git a/vndk/tools/definition-tool/tests/test_tagged_dict.py b/vndk/tools/definition-tool/tests/test_tagged_dict.py old mode 100755 new mode 100644 index 9ca027141..1dce19b80 --- a/vndk/tools/definition-tool/tests/test_tagged_dict.py +++ b/vndk/tools/definition-tool/tests/test_tagged_dict.py @@ -2,17 +2,14 @@ from __future__ import print_function -import os -import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - import tempfile import unittest -from compat import StringIO from vndk_definition_tool import TaggedDict, TaggedPathDict, TaggedLibDict, \ NUM_PARTITIONS, PT_SYSTEM, PT_VENDOR +from .compat import StringIO + _TEST_DATA = '''Path,Tag /system/lib/lib_ll_ndk.so,ll-ndk @@ -459,7 +456,3 @@ class TaggedLibDictTest(unittest.TestCase): self.assertEqual('fwk_only', tag) tag = d.get_path_tag(MockELFLinkData('/vendor/lib/unknown.so')) self.assertEqual('vnd_only', tag) - - -if __name__ == '__main__': - unittest.main() diff --git a/vndk/tools/definition-tool/tests/test_vndk.py b/vndk/tools/definition-tool/tests/test_vndk.py old mode 100755 new mode 100644 index f8fafa51c..d85e2a2ed --- a/vndk/tools/definition-tool/tests/test_vndk.py +++ b/vndk/tools/definition-tool/tests/test_vndk.py @@ -2,15 +2,12 @@ from __future__ import print_function -import os -import sys import unittest -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from vndk_definition_tool import (PT_SYSTEM, PT_VENDOR) -from compat import StringIO, patch -from vndk_definition_tool import (ELF, ELFLinker, PT_SYSTEM, PT_VENDOR) -from utils import GraphBuilder +from .compat import StringIO, patch +from .utils import GraphBuilder class ELFLinkerVNDKTest(unittest.TestCase): @@ -136,7 +133,3 @@ class ELFLinkerVNDKTest(unittest.TestCase): self.assertIn(libEGL_chipset, vndk_sets.sp_hal) self.assertNotIn(libEGL_chipset, vndk_sets.ll_ndk_indirect) - - -if __name__ == '__main__': - unittest.main() diff --git a/vndk/tools/definition-tool/tests/test_vndk_lib_dir.py b/vndk/tools/definition-tool/tests/test_vndk_lib_dir.py old mode 100755 new mode 100644 index 6eb1e5fc7..a1a2a8c29 --- a/vndk/tools/definition-tool/tests/test_vndk_lib_dir.py +++ b/vndk/tools/definition-tool/tests/test_vndk_lib_dir.py @@ -2,13 +2,11 @@ import os import posixpath -import sys import unittest -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from vndk_definition_tool import VNDKLibDir -from compat import StringIO -from vndk_definition_tool import ELF, VNDKLibDir +from .compat import StringIO SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -219,7 +217,3 @@ class VNDKLibDirTest(unittest.TestCase): self.assertEqual( ['current', 'd', 'a', '10', '1'], VNDKLibDir.sorted_version(['1', '10', 'a', 'd', 'current'])) - - -if __name__ == '__main__': - unittest.main() diff --git a/vndk/tools/definition-tool/tests/utils.py b/vndk/tools/definition-tool/tests/utils.py index c241dc577..6f7d751f2 100644 --- a/vndk/tools/definition-tool/tests/utils.py +++ b/vndk/tools/definition-tool/tests/utils.py @@ -1,13 +1,8 @@ #!/usr/bin/env python3 import os -import sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - -from compat import StringIO -from vndk_definition_tool import ( - ELF, ELFLinker, PT_SYSTEM, PT_VENDOR, VNDKLibDir) +from vndk_definition_tool import (ELF, ELFLinker, PT_SYSTEM, PT_VENDOR) class GraphBuilder(object):