Exemplo n.º 1
0
    def test_as_descriptor_uri(self):
        """
        Test the descriptor URI method
        """
        empty_path = ShotgunPath()
        self.assertRaises(ValueError, empty_path.as_descriptor_uri)

        mac_only = ShotgunPath(macosx_path="/foo/bar")
        self.assertEqual(mac_only.as_descriptor_uri(),
                         "sgtk:descriptor:path?mac_path=/foo/bar")

        # dev flag
        self.assertEqual(
            mac_only.as_descriptor_uri(for_development=True),
            "sgtk:descriptor:dev?mac_path=/foo/bar",
        )

        # full path and escaping
        full_path = ShotgunPath(
            macosx_path="/foo/bar",
            windows_path="C:\\foo\\bar",
            linux_path="/foo bar/baz",
        )
        self.assertEqual(
            full_path.as_descriptor_uri(),
            "sgtk:descriptor:path?linux_path=/foo%20bar/baz&mac_path=/foo/bar&windows_path=C:\\foo\\bar",
        )
Exemplo n.º 2
0
    def test_truthiness(self):
        """
        Tests that a ShotgunPath that has no path set evaluates to False.
        """

        self.assertFalse(bool(ShotgunPath()))
        self.assertTrue(bool(ShotgunPath(windows_path="abc")))
        self.assertTrue(bool(ShotgunPath(linux_path="abc")))
        self.assertTrue(bool(ShotgunPath(macosx_path="abc")))
Exemplo n.º 3
0
    def test_hashing(self):
        """
        Ensures two ShotgunPath with the same path generate the same hash.
        """
        first = ShotgunPath("/a/b/c", None, None)
        second = ShotgunPath("/a/b/c", None, None)
        self.assertEqual(first, second)
        self.assertEqual(hash(first), hash(second))

        first = ShotgunPath("/a/b/c", None, None)
        second = ShotgunPath("/a/b/d", None, None)
        self.assertNotEqual(first, second)
        self.assertNotEqual(hash(first), hash(second))
Exemplo n.º 4
0
    def test_equality(self):
        """
        Tests site cache root
        """
        p1 = ShotgunPath("C:\\temp", "/tmp", "/tmp2")
        p2 = p1
        p3 = ShotgunPath("C:\\temp", "/tmp", "/tmp2")

        self.assertEqual(p1, p2)
        self.assertEqual(p1, p3)
        self.assertEqual(p3, p2)

        p4 = ShotgunPath("C:\\temp", "/tmp")
        self.assertNotEqual(p1, p4)
Exemplo n.º 5
0
    def test_sanitize(self):
        """
        Tests site cache root
        """
        std_constructor = ShotgunPath("C:\\temp\\", "/tmp/", "/tmp2/")
        self.assertEqual(std_constructor.windows, "C:\\temp")
        self.assertEqual(std_constructor.macosx, "/tmp2")
        self.assertEqual(std_constructor.linux, "/tmp")

        std_constructor = ShotgunPath("C:/temp/", "///tmp//", "//tmp2/")
        self.assertEqual(std_constructor.windows, "C:\\temp")
        self.assertEqual(std_constructor.macosx, "/tmp2")
        self.assertEqual(std_constructor.linux, "/tmp")

        std_constructor = ShotgunPath("C:\\", "///tmp//", "//tmp2/")
        self.assertEqual(std_constructor.windows, "C:\\")
        self.assertEqual(std_constructor.macosx, "/tmp2")
        self.assertEqual(std_constructor.linux, "/tmp")

        # test raw sanitize logic
        sp = std_constructor._sanitize_path
        self.assertEqual(sp("/foo/bar/baz", "/"), "/foo/bar/baz")
        self.assertEqual(sp("/foo/bar/baz/", "/"), "/foo/bar/baz")
        self.assertEqual(sp("//foo//bar//baz", "/"), "/foo/bar/baz")
        self.assertEqual(sp("/foo/bar//baz", "/"), "/foo/bar/baz")
        self.assertEqual(sp("/foo\\bar//baz/////", "/"), "/foo/bar/baz")

        self.assertEqual(sp("/foo/bar/baz", "\\"), "\\foo\\bar\\baz")
        self.assertEqual(sp("c:/foo/bar/baz", "\\"), "c:\\foo\\bar\\baz")
        self.assertEqual(sp("c:/foo///bar\\\\baz//", "\\"),
                         "c:\\foo\\bar\\baz")
        self.assertEqual(sp("/foo///bar\\\\baz//", "\\"), "\\foo\\bar\\baz")

        self.assertEqual(sp("\\\\server\\share\\foo\\bar", "\\"),
                         "\\\\server\\share\\foo\\bar")
        self.assertEqual(sp("\\\\server\\share\\foo\\bar\\", "\\"),
                         "\\\\server\\share\\foo\\bar")
        self.assertEqual(sp("//server/share/foo//bar", "\\"),
                         "\\\\server\\share\\foo\\bar")

        self.assertEqual(sp("z:/", "\\"), "z:\\")
        self.assertEqual(sp("z:\\", "\\"), "z:\\")

        self.assertEqual(sp(None, "/"), None)
Exemplo n.º 6
0
 def test_property_access(self):
     """
     Test getters and setters
     """
     # check that setters sanitize the input
     std_constructor = ShotgunPath()
     std_constructor.windows = "C:\\temp\\"
     std_constructor.macosx = "/tmp/"
     std_constructor.linux = "/tmp2/"
     self.assertEqual(std_constructor.windows, "C:\\temp")
     self.assertEqual(std_constructor.macosx, "/tmp")
     self.assertEqual(std_constructor.linux, "/tmp2")
Exemplo n.º 7
0
 def test_shotgun(self):
     """
     Tests site cache root
     """
     p1 = ShotgunPath("C:\\temp", "/tmp")
     self.assertEqual(p1.as_shotgun_dict(), {
         "windows_path": "C:\\temp",
         "linux_path": "/tmp",
         "mac_path": None
     })
     self.assertEqual(p1.as_shotgun_dict(include_empty=False), {
         "windows_path": "C:\\temp",
         "linux_path": "/tmp"
     })
Exemplo n.º 8
0
    def test_join(self):
        """
        Tests site cache root
        """
        p1 = ShotgunPath("C:\\temp", "/linux", "/mac")
        p2 = p1.join("foo")
        p3 = p2.join("bar")

        self.assertEqual(p1.windows, "C:\\temp")
        self.assertEqual(p1.macosx, "/mac")
        self.assertEqual(p1.linux, "/linux")

        self.assertEqual(p2.windows, "C:\\temp\\foo")
        self.assertEqual(p2.macosx, "/mac/foo")
        self.assertEqual(p2.linux, "/linux/foo")

        self.assertEqual(p3.windows, "C:\\temp\\foo\\bar")
        self.assertEqual(p3.macosx, "/mac/foo/bar")
        self.assertEqual(p3.linux, "/linux/foo/bar")
Exemplo n.º 9
0
    def test_construction(self):
        """
        Tests get_cache_root
        """
        self.assertEqual(ShotgunPath.SHOTGUN_PATH_FIELDS,
                         ["windows_path", "linux_path", "mac_path"])

        sg = ShotgunPath.from_shotgun_dict({
            "windows_path": "C:\\temp",
            "mac_path": "/tmp",
            "linux_path": "/tmp2",
            "foo": "bar"
        })

        self.assertEqual(sg.windows, "C:\\temp")
        self.assertEqual(sg.macosx, "/tmp")
        self.assertEqual(sg.linux, "/tmp2")

        sg = ShotgunPath.from_shotgun_dict({
            "windows_path": "C:\\temp",
            "mac_path": None,
            "foo": "bar"
        })

        self.assertEqual(sg.windows, "C:\\temp")
        self.assertEqual(sg.macosx, None)
        self.assertEqual(sg.linux, None)

        sys_paths = ShotgunPath.from_system_dict({
            "win32": "C:\\temp",
            "darwin": "/tmp",
            "linux2": "/tmp2",
            "foo": "bar"
        })

        self.assertEqual(sys_paths.windows, "C:\\temp")
        self.assertEqual(sys_paths.macosx, "/tmp")
        self.assertEqual(sys_paths.linux, "/tmp2")

        sys_paths = ShotgunPath.from_system_dict({
            "win32": "C:\\temp",
            "darwin": None,
            "foo": "bar"
        })

        self.assertEqual(sys_paths.windows, "C:\\temp")
        self.assertEqual(sys_paths.macosx, None)
        self.assertEqual(sys_paths.linux, None)

        if sys.platform == "win32":
            curr = ShotgunPath.from_current_os_path("\\\\server\\mount\\path")
            self.assertEqual(curr.windows, "\\\\server\\mount\\path")
            self.assertEqual(curr.macosx, None)
            self.assertEqual(curr.linux, None)
            self.assertEqual(curr.current_os, curr.windows)

        if sys.platform == "linux2":
            curr = ShotgunPath.from_current_os_path("/tmp/foo/bar")
            self.assertEqual(curr.windows, None)
            self.assertEqual(curr.macosx, None)
            self.assertEqual(curr.linux, "/tmp/foo/bar")
            self.assertEqual(curr.current_os, curr.linux)

        if sys.platform == "darwin":
            curr = ShotgunPath.from_current_os_path("/tmp/foo/bar")
            self.assertEqual(curr.windows, None)
            self.assertEqual(curr.macosx, "/tmp/foo/bar")
            self.assertEqual(curr.linux, None)
            self.assertEqual(curr.current_os, curr.macosx)

        std_constructor = ShotgunPath("C:\\temp", "/tmp", "/tmp2")
        self.assertEqual(std_constructor.windows, "C:\\temp")
        self.assertEqual(std_constructor.macosx, "/tmp2")
        self.assertEqual(std_constructor.linux, "/tmp")