Exemple #1
0
    def test_invalid(self):
        """Make sure invalid values fail execution."""
        with self.assertRaises(ValueError):
            list(iterbot.make_chains(None, size=1))

        with self.assertRaises(ValueError):
            list(iterbot.make_chains([], size=-1))
Exemple #2
0
 def test_default(self):
     """Get the default size output."""
     self.assertEqual(
         [range(0, 2), range(1, 3),
          range(2, 4), range(3, 5)],
         list(iterbot.make_chains(range(5))),
     )
Exemple #3
0
 def test_too_high(self):
     """Get no list back because the minimum size is too high."""
     length = 5
     self.assertEqual(
         [],
         list(iterbot.make_chains(range(length), size=length + 1)),
     )
Exemple #4
0
def _resolve_rez_path(path):
    """Find the first path in :attr:`sys.path` which represents some given `path`.

    Python .egg paths tend to be incomprehensible, like
    "build/some_rez_package/1.0.0/namespace/file.py". So this function's
    job is to find the "real", location of the egg where file.py came
    from. This function is only an approximation. After all, file.py
    isn't actually a literal file on disk. It's a resource, within a
    .egg file.

    This function assumes that the .egg comes from another Rez package.
    And installed Rez packages are always named after the Rez package
    family + version. So we split the path up and use that name +
    version pair to find the real .egg path.

    Args:
        path (str): Some raw stack line to the contents of a Python .egg file.

    Returns:
        str: The found real path, if any.

    """
    parts = pathrip.split_os_path_asunder(path)

    if not parts:
        return ""

    if parts[0] == "build":
        parts[:] = parts[1:]

    all_sys_parts = [(sys_path, pathrip.split_os_path_asunder(sys_path))
                     for sys_path in sys.path]

    for name, version in iterbot.make_chains(parts):
        for sys_path, sys_parts in all_sys_parts:
            try:
                next(iterbot.iter_sub_finder([name, version], sys_parts))
            except StopIteration:
                # Nothing was found. Just ignore the path.
                continue

            return sys_path

    return ""
Exemple #5
0
 def test_custom(self):
     """Get a custom size output."""
     self.assertEqual(
         [range(0, 4), range(1, 5)],
         list(iterbot.make_chains(range(5), size=4)),
     )
Exemple #6
0
 def test_string(self):
     """Operate on other iterable types as expected."""
     self.assertEqual(
         ["abc", "bcd", "cde", "def", "efg"],
         list(iterbot.make_chains("abcdefg", size=3)),
     )
Exemple #7
0
 def test_one(self):
     """Get one chain."""
     self.assertEqual(
         [range(0, 1)],
         list(iterbot.make_chains(range(1), size=1)),
     )
Exemple #8
0
 def test_empty(self):
     """Get no chains."""
     self.assertEqual(
         [],
         list(iterbot.make_chains([], size=4)),
     )