"vscode:/vscode.git/clone" did not exist on "a1818616117f4a90b5c3c7e7ef538c37588fea68"
test_build.py 2.53 KB
Newer Older
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
1
2
3
4
5
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import unittest
from collections import Counter
from pathlib import Path

6

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# This file groups together tests which look at the code without running it.


class TestBuild(unittest.TestCase):
    def test_name_clash(self):
        # For setup.py, all translation units need distinct names, so we
        # cannot have foo.cu and foo.cpp, even in different directories.
        test_dir = Path(__file__).resolve().parent
        source_dir = test_dir.parent / "pytorch3d"

        stems = []
        for extension in [".cu", ".cpp"]:
            files = source_dir.glob(f"**/*{extension}")
            stems.extend(f.stem for f in files)

        counter = Counter(stems)
        for k, v in counter.items():
            self.assertEqual(v, 1, f"Too many files with stem {k}.")

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    def test_deprecated_usage(self):
        # Check certain expressions do not occur in the csrc code
        test_dir = Path(__file__).resolve().parent
        source_dir = test_dir.parent / "pytorch3d" / "csrc"

        files = sorted(source_dir.glob("**/*.*"))
        self.assertGreater(len(files), 4)

        patterns = [".type()", ".data()"]

        for file in files:
            with open(file) as f:
                text = f.read()
                for pattern in patterns:
                    found = pattern in text
                    msg = (
                        f"{pattern} found in {file.name}"
                        + ", this has been deprecated."
                    )
                    self.assertFalse(found, msg)

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
47
48
49
50
51
52
53
54
55
56
57
    def test_copyright(self):
        test_dir = Path(__file__).resolve().parent
        root_dir = test_dir.parent

        extensions = ("py", "cu", "cuh", "cpp", "h", "hpp", "sh")

        expect = (
            "Copyright (c) Facebook, Inc. and its affiliates."
            + " All rights reserved.\n"
        )

58
59
60
61
62
63
64
        conda_generated_files = [
            "run_test.py",
            "run_test.sh",
            "conda_test_runner.sh",
            "conda_test_env_vars.sh",
        ]

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
65
66
        for extension in extensions:
            for i in root_dir.glob(f"**/*.{extension}"):
67
68
                if i.name in conda_generated_files:
                    continue
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
69
70
71
72
73
                with open(i) as f:
                    firstline = f.readline()
                    if firstline.startswith(("# -*-", "#!")):
                        firstline = f.readline()
                    self.assertTrue(
74
                        firstline.endswith(expect), f"{i} missing copyright header."
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
75
                    )