Skip to content

Commit e332f9f

Browse files
bottlerfacebook-github-bot
authored andcommitted
test_build for implicitron
Summary: To ensure that tests outside implicitron/ don't use implicitron, split the test for recursive includes in to two. License header checking is not needed here any more. Reviewed By: shapovalov Differential Revision: D35077830 fbshipit-source-id: 2ebe7436a6dcc5d21a116434f6ddd08705dfab34
1 parent 0c3bed5 commit e332f9f

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

tests/implicitron/test_build.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
import importlib
8+
import os
9+
import sys
10+
import unittest
11+
import unittest.mock
12+
13+
if os.environ.get("FB_TEST", False):
14+
from common_testing import get_pytorch3d_dir
15+
else:
16+
from tests.common_testing import get_pytorch3d_dir
17+
18+
19+
# This file groups together tests which look at the code without running it.
20+
class TestBuild(unittest.TestCase):
21+
def test_no_import_cycles(self):
22+
# Check each module of pytorch3d imports cleanly,
23+
# which may fail if there are import cycles.
24+
25+
with unittest.mock.patch.dict(sys.modules):
26+
for module in list(sys.modules):
27+
# If any of pytorch3d is already imported,
28+
# the test would be pointless.
29+
if module.startswith("pytorch3d"):
30+
sys.modules.pop(module, None)
31+
32+
root_dir = get_pytorch3d_dir() / "pytorch3d"
33+
for module_file in root_dir.glob("**/*.py"):
34+
if module_file.stem in ("__init__", "plotly_vis"):
35+
continue
36+
relative_module = str(module_file.relative_to(root_dir))[:-3]
37+
module = "pytorch3d." + relative_module.replace("/", ".")
38+
with self.subTest(name=module):
39+
with unittest.mock.patch.dict(sys.modules):
40+
importlib.import_module(module)

tests/test_build.py

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,6 @@ def test_name_clash(self):
3535
for k, v in counter.items():
3636
self.assertEqual(v, 1, f"Too many files with stem {k}.")
3737

38-
@unittest.skipIf(in_re_worker, "In RE worker")
39-
def test_copyright(self):
40-
root_dir = get_pytorch3d_dir()
41-
42-
extensions = ("py", "cu", "cuh", "cpp", "h", "hpp", "sh")
43-
44-
expect = "Copyright (c) Meta Platforms, Inc. and affiliates.\n"
45-
46-
files_missing_copyright_header = []
47-
48-
for extension in extensions:
49-
for path in root_dir.glob(f"**/*.{extension}"):
50-
excluded_files = (
51-
"pytorch3d/transforms/external/kornia_angle_axis_to_rotation_matrix.py",
52-
"pytorch3d/csrc/pulsar/include/fastermath.h",
53-
)
54-
if in_conda_build:
55-
excluded_files += (
56-
"run_test.py",
57-
"run_test.sh",
58-
"conda_test_runner.sh",
59-
"conda_test_env_vars.sh",
60-
)
61-
62-
if str(path).endswith(excluded_files):
63-
continue
64-
with open(path) as f:
65-
firstline = f.readline()
66-
if firstline.startswith(("# -*-", "#!", "/*")):
67-
firstline = f.readline()
68-
if not firstline.endswith(expect):
69-
files_missing_copyright_header.append(str(path))
70-
71-
if len(files_missing_copyright_header) != 0:
72-
self.fail("\n".join(files_missing_copyright_header))
73-
7438
@unittest.skipIf(in_re_worker, "In RE worker")
7539
def test_valid_ipynbs(self):
7640
# Check that the ipython notebooks are valid json
@@ -129,6 +93,8 @@ def test_no_import_cycles(self):
12993
for module_file in root_dir.glob("**/*.py"):
13094
if module_file.stem in ("__init__", "plotly_vis"):
13195
continue
96+
if "implicitron" in str(module_file):
97+
continue
13298
relative_module = str(module_file.relative_to(root_dir))[:-3]
13399
module = "pytorch3d." + relative_module.replace("/", ".")
134100
with self.subTest(name=module):

0 commit comments

Comments
 (0)