Commit 814badbc authored by Yanghan Wang's avatar Yanghan Wang Committed by Facebook GitHub Bot
Browse files

use the mobile_cv's SubPackageInitFileTestMixin

Summary:
Pull Request resolved: https://github.com/facebookresearch/d2go/pull/263

Re-use the code in D36651241

Reviewed By: tglik

Differential Revision: D36682041

fbshipit-source-id: 1bf30afbbb69d10fc11f9161e29319f180c65e2f
parent 4f5548a1
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import glob
import os
import unittest import unittest
import pkg_resources from mobile_cv.common.misc.test_utils import SubPackageInitFileTestMixin
class TestSubPackageInitFile(unittest.TestCase): class TestSubPackageInitFile(SubPackageInitFileTestMixin, unittest.TestCase):
def test_has_init_files(self): def get_pacakge_name(self) -> str:
"""We require every subpackage has an __init__.py file""" return "d2go"
root = pkg_resources.resource_filename("d2go", "")
all_py_files = glob.glob(f"{root}/**/*.py", recursive=True)
all_package_dirs = [os.path.dirname(f) for f in all_py_files]
all_package_dirs = sorted(set(all_package_dirs)) # dedup
init_files = [
os.path.join(os.path.relpath(d, root), "__init__.py")
for d in all_package_dirs
]
print("Checking following files ...\n{}".format("\n".join(init_files)))
missing_init_files = [
f for f in init_files if not os.path.isfile(os.path.join(root, f))
]
self.assertTrue(
len(missing_init_files) == 0,
"Missing following __init__.py files:\n{}".format(
"\n".join(missing_init_files)
),
)
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