Exemple #1
0
    def test_invalid_001(self):
        """Fail early because the directory does not exist."""
        directory = tempfile.mkdtemp(suffix="_does_not_exist")
        shutil.rmtree(directory)

        with self.assertRaises(RuntimeError):
            help_manager.get_data(directory)
Exemple #2
0
    def test_invalid_002(self):
        """Fail early because the directory is not in a Rez package."""
        directory = tempfile.mkdtemp(suffix="_does_not_exist")
        atexit.register(functools.partial(shutil.rmtree, directory))

        with self.assertRaises(ValueError):
            help_manager.get_data(directory)
Exemple #3
0
    def test_non_existent_path_002(self):
        """Don't resolve to an absolute path because the user asked not to."""
        directory = tempfile.mkdtemp(
            suffix="_GetHelpData_test_non_existent_path_002")
        os.makedirs(os.path.join(directory, "inner_folder"))

        with open(os.path.join(directory, "package.py"), "w") as handler:
            handler.write(
                textwrap.dedent("""\
                    name = "some_package"

                    help = [
                        ["README", "inner_folder/README.md"]
                    ]
                    """))

        path = os.path.join(directory, "inner_folder", "README.md")
        open(path, "a").close()

        self.assertEqual(
            [["README", path]],
            help_manager.get_data(directory),
        )
        self.assertEqual(
            [["README", "inner_folder/README.md"]],
            help_manager.get_data(directory, resolve=False),
        )
Exemple #4
0
    def test_list_001(self):
        """Get help path data from a list."""
        help_ = [["Some Text", "and/more/things"]]
        package = _make_package(help_=help_)
        items = help_manager.get_data(os.path.dirname(package.filepath))

        self.assertEqual(help_, items)
Exemple #5
0
    def test_empty_string(self):
        """Get `help` from a Rez package with a defined, empty `help` attribute."""
        help_ = ""
        package = _make_package(help_=help_)
        items = help_manager.get_data(os.path.dirname(package.filepath))

        self.assertEqual([], items)
Exemple #6
0
    def test_string_002(self):
        """Get help URL data from a string."""
        help_ = "http://some_place_with_url.com"
        package = _make_package(help_=help_)
        items = help_manager.get_data(os.path.dirname(package.filepath))

        self.assertEqual([["Home Page", help_]], items)
Exemple #7
0
    def test_string_001(self):
        """Get help path data from a string."""
        help_ = tempfile.mkstemp(suffix="_test_string_001")[1]
        package = _make_package(help_=help_)
        items = help_manager.get_data(os.path.dirname(package.filepath))

        self.assertEqual([["Home Page", help_]], items)
Exemple #8
0
    def test_non_existent_path_001(self):
        """Don't resolve to an absolute path because the path doesn't exist."""
        help_ = [["Something", "some/non/existent/path"]]
        package = _make_package(help_=help_)
        items = help_manager.get_data(os.path.dirname(package.filepath))

        self.assertEqual(help_, items)
Exemple #9
0
    def test_matches_empty(self):
        """Match nothing because there were no matches."""
        help_ = [["Blah", "some/non/existent/path"]]
        package = _make_package(help_=help_)
        items = help_manager.get_data(
            os.path.dirname(package.filepath),
            matches="*Thing*",
        )

        self.assertEqual([], items)
Exemple #10
0
    def test_matches_custom(self):
        """Use a custom `matches` argument to get help information."""
        def _matches(key):
            return key.lower() == "blah"

        help_ = [["Blah", "some/non/existent/path"]]
        package = _make_package(help_=help_)
        items = help_manager.get_data(
            os.path.dirname(package.filepath),
            matches=_matches,
        )

        self.assertEqual(help_, items)
Exemple #11
0
    def test_matches_glob_find(self):
        """Get everything, via a glob."""
        help_ = [
            ["Blah", "some/non/existent/path"],
            ["Some Documentation", "foo/bar"],
        ]
        package = _make_package(help_=help_)
        items = help_manager.get_data(
            os.path.dirname(package.filepath),
            matches="*",
        )

        self.assertEqual(help_, items)
Exemple #12
0
    def test_matches_glob_fail(self):
        """Match only one thing."""
        help_ = [
            ["Blah", "some/non/existent/path"],
            ["Some Documentation", "foo/bar"],
        ]
        package = _make_package(help_=help_)
        items = help_manager.get_data(
            os.path.dirname(package.filepath),
            matches="*Documentation",
        )

        self.assertEqual([["Some Documentation", "foo/bar"]], items)
Exemple #13
0
    def test_list_002(self):
        """Get multiple help URLs from a list."""
        help_ = [
            [
                "Some Documentation",
                "http://www.some_path_here_does_not_exist.com"
            ],
            [
                "Another Documentation",
                "http://www.another_path_that_is_not_real.com"
            ],
        ]
        package = _make_package(help_=help_)
        items = help_manager.get_data(os.path.dirname(package.filepath))

        self.assertEqual(help_, items)
Exemple #14
0
    def test_egg(self):
        """Get the directory of an .egg path automatically."""
        root = tempfile.mkdtemp(suffix="_GetHelpDataDirectory_test_egg")
        atexit.register(functools.partial(shutil.rmtree, root))
        fake_directory = os.path.join(root, "some_rez_package", "1.0.0", "and",
                                      "stuff")
        os.makedirs(fake_directory)

        with open(os.path.join(fake_directory, "package.py"), "w") as handler:
            handler.write(
                textwrap.dedent("""
                    name = "some_rez_package"

                    help = [["Some Documentation", "blah here"]]
                    """))

        fake_path = os.path.join(fake_directory, "namespace.file.py")
        # This "build/foo/major.minor.patch" is a really common pattern with Rez .egg packages
        fake_stack_path = "build/some_rez_package/1.0.0/namespace/file.py"

        with _fake_build_environment(fake_path, fake_stack_path):
            help_ = help_manager.get_data()

        self.assertEqual([["Some Documentation", "blah here"]], help_)