vndk-def: Cleanup import pylint errors

Test: ./tests/run.sh
Change-Id: I6fc9fcef8164fb1f795f5902d900f34e99b1228d
This commit is contained in:
Logan Chien
2019-01-03 18:43:26 +08:00
parent c7bf9936da
commit eaacaac29d
17 changed files with 46 additions and 180 deletions

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os # pylint: disable=unused-import,import-error
import sys import sys
@@ -37,6 +38,7 @@ except ImportError:
if sys.version_info >= (3, 0): if sys.version_info >= (3, 0):
from os import makedirs from os import makedirs
else: else:
import os
def makedirs(path, exist_ok): def makedirs(path, exist_ok):
if exist_ok and os.path.exists(path): if exist_ok and os.path.exists(path):
return return

24
vndk/tools/definition-tool/tests/ndk_toolchain.py Executable file → Normal file
View File

@@ -2,7 +2,6 @@
from __future__ import print_function from __future__ import print_function
import argparse
import collections import collections
import os import os
import re 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'])) get_platform_dir(ndk_dir, api, ['arch-mips64', 'usr', 'lib64']))
return targets 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()

View File

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

View File

@@ -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 "$@"

View File

@@ -2,16 +2,13 @@
from __future__ import print_function from __future__ import print_function
import os
import sys
import unittest 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 ( from vndk_definition_tool import (
DepsInsightCommand, ModuleInfo, PT_SYSTEM, PT_VENDOR) DepsInsightCommand, ModuleInfo, PT_SYSTEM, PT_VENDOR)
from utils import GraphBuilder
from .compat import StringIO, patch
from .utils import GraphBuilder
class DepsInsightCommandTest(unittest.TestCase): class DepsInsightCommandTest(unittest.TestCase):
@@ -82,7 +79,3 @@ class DepsInsightCommandTest(unittest.TestCase):
users = self._get_module_users(strs, mods, libvnd_bad.path) users = self._get_module_users(strs, mods, libvnd_bad.path)
self.assertIn(libvndk.path, users) self.assertIn(libvndk.path, users)
self.assertIn(libvndk_sp.path, users) self.assertIn(libvndk_sp.path, users)
if __name__ == '__main__':
unittest.main()

10
vndk/tools/definition-tool/tests/test_dex_file.py Executable file → Normal file
View File

@@ -4,15 +4,13 @@ from __future__ import print_function
import os import os
import subprocess import subprocess
import sys
import unittest import unittest
import zipfile 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 vndk_definition_tool import DexFileReader, UnicodeSurrogateDecodeError
from .compat import TemporaryDirectory
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
INPUT_DIR = os.path.join(SCRIPT_DIR, 'testdata', 'test_dex_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'world', strs)
self.assertIn(b'foo', strs) self.assertIn(b'foo', strs)
self.assertIn(b'bar', strs) self.assertIn(b'bar', strs)
if __name__ == '__main__':
unittest.main()

11
vndk/tools/definition-tool/tests/test_elf.py Executable file → Normal file
View File

@@ -2,16 +2,13 @@
from __future__ import print_function 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 tempfile
import unittest import unittest
from compat import StringIO
from vndk_definition_tool import Elf_Sym, ELF from vndk_definition_tool import Elf_Sym, ELF
from .compat import StringIO
class ElfSymTest(unittest.TestCase): class ElfSymTest(unittest.TestCase):
def setUp(self): def setUp(self):
@@ -223,7 +220,3 @@ class ELFJniLibTest(unittest.TestCase):
elf = ELF(exported_symbols={'printf'}) elf = ELF(exported_symbols={'printf'})
self.assertFalse(elf.is_jni_lib()) self.assertFalse(elf.is_jni_lib())
if __name__ == '__main__':
unittest.main()

8
vndk/tools/definition-tool/tests/test_elf_link_data.py Executable file → Normal file
View File

@@ -2,10 +2,6 @@
from __future__ import print_function from __future__ import print_function
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import unittest import unittest
from vndk_definition_tool import ELFLinkData, PT_SYSTEM, PT_VENDOR 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.assertEqual(['w', 'x', 'y', 'z'],
self.x.get_dep_linked_symbols(self.z)) self.x.get_dep_linked_symbols(self.z))
if __name__ == '__main__':
unittest.main()

16
vndk/tools/definition-tool/tests/test_elf_linker.py Executable file → Normal file
View File

@@ -1,20 +1,14 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
import re import re
import sys
import tempfile import tempfile
import unittest 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 ( from vndk_definition_tool import (
ELF, ELFLinker, GenericRefs, PT_SYSTEM, PT_VENDOR, VNDKLibDir) ELF, GenericRefs, PT_SYSTEM, PT_VENDOR, VNDKLibDir)
from .compat import StringIO, patch
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) from .utils import GraphBuilder
class ELFLinkerTest(unittest.TestCase): class ELFLinkerTest(unittest.TestCase):
@@ -564,7 +558,3 @@ class ELFLinkerDlopenDepsTest(unittest.TestCase):
stderr.getvalue(), stderr.getvalue(),
'error:' + re.escape(tmp_file.name) + ':1: ' + 'error:' + re.escape(tmp_file.name) + ':1: ' +
'Failed to add dlopen dependency from .* to .*\\.\n') 'Failed to add dlopen dependency from .* to .*\\.\n')
if __name__ == '__main__':
unittest.main()

8
vndk/tools/definition-tool/tests/test_elf_resolver.py Executable file → Normal file
View File

@@ -2,10 +2,6 @@
from __future__ import print_function from __future__ import print_function
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import unittest import unittest
from vndk_definition_tool import ELFResolver from vndk_definition_tool import ELFResolver
@@ -94,7 +90,3 @@ class ELFResolverTest(unittest.TestCase):
'a2', 'a2',
r.resolve('/system/lib/libreq.so', 'liba.so', r.resolve('/system/lib/libreq.so', 'liba.so',
dt_runpath=['/vendor/lib'])) dt_runpath=['/vendor/lib']))
if __name__ == '__main__':
unittest.main()

32
vndk/tools/definition-tool/tests/test_elfdump.py Executable file → Normal file
View File

@@ -2,17 +2,14 @@
from __future__ import print_function from __future__ import print_function
import argparse
import collections
import difflib
import os import os
import re import re
import subprocess import subprocess
import sys import sys
import unittest import unittest
from compat import TemporaryDirectory, makedirs from .compat import TemporaryDirectory, makedirs
import ndk_toolchain from .ndk_toolchain import create_targets
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -31,7 +28,7 @@ def run_elf_dump(path):
class ELFDumpTest(unittest.TestCase): class ELFDumpTest(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
cls.targets = ndk_toolchain.create_targets() cls.targets = create_targets()
if test_dir_base: if test_dir_base:
cls.test_dir_base = 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'): for target in ('arm', 'arm64', 'mips', 'mips64', 'x86', 'x86_64'):
create_target_test(target) 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()

9
vndk/tools/definition-tool/tests/test_generic_refs.py Executable file → Normal file
View File

@@ -3,13 +3,8 @@
from __future__ import print_function from __future__ import print_function
import os import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import argparse
import unittest import unittest
from compat import TemporaryDirectory, makedirs
from vndk_definition_tool import GenericRefs from vndk_definition_tool import GenericRefs
@@ -96,7 +91,3 @@ class GenericRefsTest(unittest.TestCase):
MockLib('/vendor/lib/libc.so', {}))) MockLib('/vendor/lib/libc.so', {})))
self.assertFalse(self.ref.has_same_name_lib( self.assertFalse(self.ref.has_same_name_lib(
MockLib('/vendor/lib/lib_does_not_exist.so', {}))) MockLib('/vendor/lib/lib_does_not_exist.so', {})))
if __name__ == '__main__':
unittest.main()

7
vndk/tools/definition-tool/tests/test_module_info.py Executable file → Normal file
View File

@@ -3,9 +3,6 @@
from __future__ import print_function from __future__ import print_function
import os import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import unittest import unittest
from vndk_definition_tool import ModuleInfo from vndk_definition_tool import ModuleInfo
@@ -35,7 +32,3 @@ class ModuleInfoTest(unittest.TestCase):
self.assertEqual( self.assertEqual(
[], m.get_module_path('/system/lib64/libdoes_not_exist.so')) [], m.get_module_path('/system/lib64/libdoes_not_exist.so'))
if __name__ == '__main__':
unittest.main()

11
vndk/tools/definition-tool/tests/test_tagged_dict.py Executable file → Normal file
View File

@@ -2,17 +2,14 @@
from __future__ import print_function 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 tempfile
import unittest import unittest
from compat import StringIO
from vndk_definition_tool import TaggedDict, TaggedPathDict, TaggedLibDict, \ from vndk_definition_tool import TaggedDict, TaggedPathDict, TaggedLibDict, \
NUM_PARTITIONS, PT_SYSTEM, PT_VENDOR NUM_PARTITIONS, PT_SYSTEM, PT_VENDOR
from .compat import StringIO
_TEST_DATA = '''Path,Tag _TEST_DATA = '''Path,Tag
/system/lib/lib_ll_ndk.so,ll-ndk /system/lib/lib_ll_ndk.so,ll-ndk
@@ -459,7 +456,3 @@ class TaggedLibDictTest(unittest.TestCase):
self.assertEqual('fwk_only', tag) self.assertEqual('fwk_only', tag)
tag = d.get_path_tag(MockELFLinkData('/vendor/lib/unknown.so')) tag = d.get_path_tag(MockELFLinkData('/vendor/lib/unknown.so'))
self.assertEqual('vnd_only', tag) self.assertEqual('vnd_only', tag)
if __name__ == '__main__':
unittest.main()

13
vndk/tools/definition-tool/tests/test_vndk.py Executable file → Normal file
View File

@@ -2,15 +2,12 @@
from __future__ import print_function from __future__ import print_function
import os
import sys
import unittest 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 .compat import StringIO, patch
from vndk_definition_tool import (ELF, ELFLinker, PT_SYSTEM, PT_VENDOR) from .utils import GraphBuilder
from utils import GraphBuilder
class ELFLinkerVNDKTest(unittest.TestCase): class ELFLinkerVNDKTest(unittest.TestCase):
@@ -136,7 +133,3 @@ class ELFLinkerVNDKTest(unittest.TestCase):
self.assertIn(libEGL_chipset, vndk_sets.sp_hal) self.assertIn(libEGL_chipset, vndk_sets.sp_hal)
self.assertNotIn(libEGL_chipset, vndk_sets.ll_ndk_indirect) self.assertNotIn(libEGL_chipset, vndk_sets.ll_ndk_indirect)
if __name__ == '__main__':
unittest.main()

10
vndk/tools/definition-tool/tests/test_vndk_lib_dir.py Executable file → Normal file
View File

@@ -2,13 +2,11 @@
import os import os
import posixpath import posixpath
import sys
import unittest 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 .compat import StringIO
from vndk_definition_tool import ELF, VNDKLibDir
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -219,7 +217,3 @@ class VNDKLibDirTest(unittest.TestCase):
self.assertEqual( self.assertEqual(
['current', 'd', 'a', '10', '1'], ['current', 'd', 'a', '10', '1'],
VNDKLibDir.sorted_version(['1', '10', 'a', 'd', 'current'])) VNDKLibDir.sorted_version(['1', '10', 'a', 'd', 'current']))
if __name__ == '__main__':
unittest.main()

View File

@@ -1,13 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from vndk_definition_tool import (ELF, ELFLinker, PT_SYSTEM, PT_VENDOR)
from compat import StringIO
from vndk_definition_tool import (
ELF, ELFLinker, PT_SYSTEM, PT_VENDOR, VNDKLibDir)
class GraphBuilder(object): class GraphBuilder(object):