示例#1
0
 def test_invalid_argument_count(self):
     with self.assertRaises(TypeError):
         cquery.first_match(
             root="not exist",
             selector=".Asset",
             direction=cquery.DOWN,
             notexist=10)
示例#2
0
    def test_invalid_direction(self):
        with self.assertRaises(AssertionError):
            # direction expects an integer, not passing an integer is a bug
            cquery.first_match(self.root_path, '.Test', direction='invalid')

        with self.assertRaises(ValueError):
            # cquery.UP, cquery.DOWN and cquery.NONE use flags between 0-2
            cquery.first_match(self.root_path, '.Test', direction=1 << 3)
示例#3
0
    def test_up_direction(self):
        """Query asset for its associated project"""
        asset = os.path.join(self.project_path, 'assets', 'Peter')
        match = cquery.first_match(asset, '.Project', direction=cquery.UP)
        self.assertEquals(match, self.project_path)

        # With insufficient depth, a match should not be found
        match = cquery.first_match(asset, '.Project',
                                   direction=cquery.UP,
                                   depth=1)
        self.assertEquals(match, None)
    def compute_conform_dir(self, root, instance):
        # Look in other instances first
        for instance in instance.context:
            if instance.has_data("conform_dir"):
                return instance.data("conform_dir")

        parent_asset_dir = cquery.first_match(root,
                                              selector=".Shot",
                                              direction=cquery.UP)
        if not parent_asset_dir:
            raise pyblish.api.ConformError(
                "Could not locate parent "
                "shot of commit: %s" % root)

        self.log.info("Parent shot: %s" % parent_asset_dir)
        public_dir = napoleon.pipeline.public_dir(parent_asset_dir)

        name = instance.data("name")

        try:
            # Use namespace as name of instance by default
            namespace, name = name.rsplit(":", 1)
            name = namespace.strip("_")
        except ValueError:
            pass

        family = instance.data("family")
        assert family

        instance_dir = os.path.join(public_dir, name, family)
        conform_dir = napoleon.pipeline.version_dir(instance_dir)

        return conform_dir
示例#5
0
    def compute_conform_dir(self, root, instance):
        # Look in other instances first
        for instance in instance.context:
            if instance.has_data("conform_dir"):
                return instance.data("conform_dir")

        parent_asset_dir = cquery.first_match(root,
                                              selector=".Shot",
                                              direction=cquery.UP)
        if not parent_asset_dir:
            raise pyblish.api.ConformError("Could not locate parent "
                                           "shot of commit: %s" % root)

        self.log.info("Parent shot: %s" % parent_asset_dir)
        public_dir = napoleon.pipeline.public_dir(parent_asset_dir)

        name = instance.data("name")

        try:
            # Use namespace as name of instance by default
            namespace, name = name.rsplit(":", 1)
            name = namespace.strip("_")
        except ValueError:
            pass

        family = instance.data("family")
        assert family

        instance_dir = os.path.join(public_dir, name, family)
        conform_dir = napoleon.pipeline.version_dir(instance_dir)

        return conform_dir
示例#6
0
 def test_up_nonexisting(self):
     """Look for a tag that doesn't exist, upwards"""
     match = cquery.first_match(self.root_path, '.NotExist')
     self.assertEquals(match, None)
示例#7
0
 def test_root_as_file(self):
     """Pass in an existing file as `root` argument"""
     with self.assertRaises(OSError):
         cquery.first_match(self.filepath, '.TestRootAsFile')
示例#8
0
 def test_class(self):
     result = cquery.first_match(self.project_path, '.Villain')
     supposed_path = os.path.join(self.project_path, 'assets', 'Goblin')
     self.assertEquals(result, supposed_path)
示例#9
0
 def test_id(self):
     result = cquery.first_match(self.project_path, '#Spidey')
     supposed_path = os.path.join(self.project_path, 'assets', 'Peter')
     self.assertEquals(result, supposed_path)
示例#10
0
 def test_nonexisting_root(self):
     nonexisting_path = "not exist"
     assert not os.path.exists(nonexisting_path)
     result = cquery.first_match(root=nonexisting_path, selector=".Asset")
     assert result is None
示例#11
0
def parent_shot(path):
    if os.path.isfile(path):
        path = os.path.dirname(path)
    return cquery.first_match(path, selector='.Shot', direction=cquery.UP)