Ejemplo n.º 1
0
    def setUp(self):
        super(TestTemplatePath, self).setUp()

        # Make various types of keys(fields)
        self.keys = {
            "Sequence": StringKey("Sequence"),
            "Shot": StringKey("Shot",
                              default="s1",
                              choices=["s1", "s2", "shot_1"]),
            "Step": StringKey("Step"),
            "branch": StringKey("branch", filter_by="alphanumeric"),
            "name": StringKey("name"),
            "version": IntegerKey("version", format_spec="03"),
            "snapshot": IntegerKey("snapshot", format_spec="03"),
            "ext": StringKey("ext"),
            "seq_num": SequenceKey("seq_num"),
            "frame": SequenceKey("frame", format_spec="04")
        }
        # Make a template
        self.definition = "shots/{Sequence}/{Shot}/{Step}/work/{Shot}.{branch}.v{version}.{snapshot}.ma"
        self.template_path = TemplatePath(self.definition, self.keys,
                                          self.project_root)

        # make template with sequence key
        self.sequence = TemplatePath("/path/to/seq.{frame}.ext", self.keys, "",
                                     "frame")
Ejemplo n.º 2
0
    def setUp(self):
        super(TestTemplate, self).setUp()

        # Make various types of keys(fields)
        self.keys = {
            "Sequence":
            StringKey("Sequence"),
            "Shot":
            StringKey("Shot", default="s1", choices=["s1", "s2", "shot_1"]),
            "Step":
            StringKey("Step"),
            "branch":
            StringKey("branch", filter_by="alphanumeric"),
            "name":
            StringKey("name"),
            "version":
            IntegerKey("version", format_spec="03"),
            "snapshot":
            IntegerKey("snapshot", format_spec="03"),
            "ext":
            StringKey("ext"),
            "seq_num":
            SequenceKey("seq_num"),
            "frame":
            SequenceKey("frame", format_spec="04"),
            "day_month_year":
            TimestampKey("day_month_year", format_spec="%d_%m_%Y")
        }
        # Make a template
        self.definition = "shots/{Sequence}/{Shot}/{Step}/work/{Shot}.{branch}.v{version}.{snapshot}.{day_month_year}.ma"
        self.template = Template(self.definition, self.keys)
Ejemplo n.º 3
0
 def test_override_default_at_runtime(self):
     """
     Makes sure that a key's default can be overriden at runtime.
     """
     sk = SequenceKey("sequencekey", format_spec="04")
     self.assertEqual(sk.default, "%04d")
     sk.default = "%03d"
     self.assertEqual(sk.default, "%03d")
Ejemplo n.º 4
0
 def test_override_default_at_runtime(self):
     """
     Makes sure that a key's default can be overriden at runtime.
     """
     sk = SequenceKey("sequencekey", format_spec="04")
     self.assertEqual(sk.default, "%04d")
     sk.default = "%03d"
     self.assertEqual(sk.default, "%03d")
Ejemplo n.º 5
0
    def setUp(self):
        super(TestTemplatePath, self).setUp(
            parameters={"primary_root_name": "primary_with_a_different_name"})
        # Make various types of keys(fields)
        self.keys = {
            "Sequence": StringKey("Sequence"),
            "Shot": StringKey("Shot",
                              default="s1",
                              choices=["s1", "s2", "shot_1"]),
            "Step": StringKey("Step"),
            "branch": StringKey("branch", filter_by="alphanumeric"),
            "name": StringKey("name"),
            "name_alpha": StringKey("name_alpha", filter_by="alphanumeric"),
            "version": IntegerKey("version", format_spec="03"),
            "snapshot": IntegerKey("snapshot", format_spec="03"),
            "ext": StringKey("ext"),
            "seq_num": SequenceKey("seq_num"),
            "frame": SequenceKey("frame", format_spec="04"),
        }
        # Make a template
        self.definition = "shots/{Sequence}/{Shot}/{Step}/work/{Shot}.{branch}.v{version}.{snapshot}.ma"

        # legacy style template object which only knows about the currently running operating system
        self.template_path_current_os_only = TemplatePath(
            self.definition, self.keys, self.project_root)

        project_root = os.path.join(self.tank_temp, "project_code")
        self._project_roots = {self.primary_root_name: {}}
        # Create the roots.yml like structure. Double down on the key names so it can be used in all scenarios
        # where we require the roots.
        for os_name in [
                "windows_path",
                "linux_path",
                "mac_path",
                "win32",
                "linux2",
                "darwin",
        ]:
            self._project_roots[self.primary_root_name][os_name] = project_root
        self._primary_project_root = project_root

        # new style template object which supports all recognized platforms
        # get all OS roots for primary storage
        all_roots = self._project_roots[self.primary_root_name]

        self.template_path = TemplatePath(self.definition,
                                          self.keys,
                                          self.project_root,
                                          per_platform_roots=all_roots)

        self.project_root_template = TemplatePath("/",
                                                  self.keys,
                                                  self.project_root,
                                                  per_platform_roots=all_roots)

        # make template with sequence key
        self.sequence = TemplatePath("/path/to/seq.{frame}.ext", self.keys, "",
                                     "frame")
Ejemplo n.º 6
0
    def test_str_from_value_default_one(self):
        """
        default frame spec value can be returned, frame spec with
        one place has special cases.
        """
        value = None
        seq_field = SequenceKey("field_name")
        expected = "%d"
        result = seq_field.str_from_value(value="FORMAT:%d")
        self.assertEqual(expected, result)

        expected = "#"
        result = seq_field.str_from_value(value="FORMAT:#")
        self.assertEqual(expected, result)

        expected = "@"
        result = seq_field.str_from_value(value="FORMAT:@")
        self.assertEqual(expected, result)

        expected = "$F"
        result = seq_field.str_from_value(value="FORMAT:$F")
        self.assertEqual(expected, result)

        expected = "<UDIM>"
        result = seq_field.str_from_value(value="FORMAT:<UDIM>")
        self.assertEqual(expected, result)

        expected = "$UDIM"
        result = seq_field.str_from_value(value="FORMAT:$UDIM")
        self.assertEqual(expected, result)

        # no pattern specified
        expected = "%d"
        result = seq_field.str_from_value()
        self.assertEqual(expected, result)
Ejemplo n.º 7
0
    def test_str_from_value_default_three(self):
        """
        Test default frame spec value returned for framespec with more than
        one places.
        """
        seq_field = SequenceKey("field_name", format_spec="03")

        expected = "%03d"
        result = seq_field.str_from_value("FORMAT:%d")
        self.assertEqual(expected, result)

        expected = "###"
        result = seq_field.str_from_value("FORMAT:#")
        self.assertEqual(expected, result)

        expected = "@@@"
        result = seq_field.str_from_value("FORMAT:@")
        self.assertEqual(expected, result)

        expected = "$F3"
        result = seq_field.str_from_value("FORMAT:$F")
        self.assertEqual(expected, result)

        expected = "<UDIM>"
        result = seq_field.str_from_value(value="FORMAT:<UDIM>")
        self.assertEqual(expected, result)

        expected = "$UDIM"
        result = seq_field.str_from_value(value="FORMAT:$UDIM")
        self.assertEqual(expected, result)

        # no pattern specified
        expected = "%03d"
        result = seq_field.str_from_value()
        self.assertEqual(expected, result)
Ejemplo n.º 8
0
    def test_str_from_value_default_three(self):
        """
        Test default frame spec value returned for framespec with more than
        one places.
        """
        seq_field = SequenceKey("field_name", format_spec="03")

        expected = "%03d"
        result = seq_field.str_from_value("FORMAT:%d")
        self.assertEqual(expected, result)

        expected = "###"
        result = seq_field.str_from_value("FORMAT:#")
        self.assertEqual(expected, result)

        expected = "@@@"
        result = seq_field.str_from_value("FORMAT:@")
        self.assertEqual(expected, result)

        expected = "$F3"
        result = seq_field.str_from_value("FORMAT:$F")
        self.assertEqual(expected, result)

        expected = "<UDIM>"
        result = seq_field.str_from_value(value="FORMAT:<UDIM>")
        self.assertEqual(expected, result)

        expected = "$UDIM"
        result = seq_field.str_from_value(value="FORMAT:$UDIM")
        self.assertEqual(expected, result)

        # no pattern specified
        expected = "%03d"
        result = seq_field.str_from_value()
        self.assertEqual(expected, result)
Ejemplo n.º 9
0
    def test_str_from_value_format_whitespace(self):
        """Use of FORMAT: prefix with whitespace."""

        seq_field = SequenceKey("field_name", format_spec="03")

        expected = "%03d"
        result = seq_field.str_from_value("FORMAT: %d")
        self.assertEqual(expected, result)

        expected = "###"
        result = seq_field.str_from_value("FORMAT: #")
        self.assertEqual(expected, result)

        expected = "@@@"
        result = seq_field.str_from_value("FORMAT: @")
        self.assertEqual(expected, result)

        expected = "$F3"
        result = seq_field.str_from_value("FORMAT: $F")
        self.assertEqual(expected, result)

        expected = "<UDIM>"
        result = seq_field.str_from_value(value="FORMAT: <UDIM>")
        self.assertEqual(expected, result)

        expected = "$UDIM"
        result = seq_field.str_from_value(value="FORMAT: $UDIM")
        self.assertEqual(expected, result)
Ejemplo n.º 10
0
    def test_str_from_value_default_one(self):
        """
        default frame spec value can be returned, frame spec with
        one place has special cases.
        """
        value = None
        seq_field = SequenceKey("field_name")
        expected = "%d"
        result = seq_field.str_from_value(value="FORMAT:%d")
        self.assertEqual(expected, result)

        expected = "#"
        result = seq_field.str_from_value(value="FORMAT:#")
        self.assertEqual(expected, result)

        expected = "@"
        result = seq_field.str_from_value(value="FORMAT:@")
        self.assertEqual(expected, result)

        expected = "$F"
        result = seq_field.str_from_value(value="FORMAT:$F")
        self.assertEqual(expected, result)

        expected = "<UDIM>"
        result = seq_field.str_from_value(value="FORMAT:<UDIM>")
        self.assertEqual(expected, result)

        expected = "$UDIM"
        result = seq_field.str_from_value(value="FORMAT:$UDIM")
        self.assertEqual(expected, result)

        # no pattern specified
        expected = "%d"
        result = seq_field.str_from_value()
        self.assertEqual(expected, result)
Ejemplo n.º 11
0
    def setUp(self):
        super(TestPathsFromTemplateGlob, self).setUp()
        keys = {"Shot": StringKey("Shot"),
                "version": IntegerKey("version", format_spec="03"),
                "seq_num": SequenceKey("seq_num", format_spec="05")}

        self.template = TemplatePath("{Shot}/{version}/filename.{seq_num}", keys, root_path=self.project_root)
Ejemplo n.º 12
0
 def test_default_frame_spec_choices(self):
     frame_specs = set(["%d", "#", "@", "$F"])
     for frame_spec in frame_specs:
         seq_frame = SequenceKey("field_name",
                                 default=frame_spec,
                                 choices=[1, 2])
         self.assertEquals(frame_spec, seq_frame.default)
Ejemplo n.º 13
0
    def test_translate_abstract_fields(self):
        # We should get back what we gave since there won't be a matching
        # template for this path.
        self.assertEqual(
            "/jbee/is/awesome.0001.jpg",
            tank.util.shotgun.publish_creation._translate_abstract_fields(
                self.tk,
                "/jbee/is/awesome.0001.jpg",
            ),
        )

        # Build a set of matching templates.
        keys = dict(
            seq=tank.templatekey.SequenceKey(
                "seq",
                format_spec="03",
            ),
            frame=SequenceKey(
                "frame",
                format_spec="04",
            ),
        )
        template = TemplatePath(
            "folder/name_{seq}.{frame}.ext",
            keys,
            self.project_root,
        )
        dup_template = TemplatePath(
            "folder/name_{seq}.{frame}.ext",
            keys,
            self.project_root,
        )

        self.tk.templates["translate_fields_test"] = template

        # We should get back a transformed path since there's a single
        # matching template.
        path = os.path.join(self.project_root, "folder", "name_001.9999.ext")
        t_path = os.path.join(self.project_root, "folder",
                              "name_%03d.%04d.ext")

        self.assertEqual(
            t_path,
            tank.util.shotgun.publish_creation._translate_abstract_fields(
                self.tk,
                path,
            ),
        )

        self.tk.templates["translate_fields_test_dup"] = dup_template

        # We should get back what we gave due to multiple matching templates.
        self.assertEqual(
            path,
            tank.util.shotgun.publish_creation._translate_abstract_fields(
                self.tk,
                path,
            ),
        )
Ejemplo n.º 14
0
    def test_str_from_value_format_whitespace(self):
        """Use of FORMAT: prefix with whitespace."""

        seq_field = SequenceKey("field_name", format_spec="03")

        expected = "%03d"
        result = seq_field.str_from_value("FORMAT: %d")
        self.assertEqual(expected, result)

        expected = "###"
        result = seq_field.str_from_value("FORMAT: #")
        self.assertEqual(expected, result)

        expected = "@@@"
        result = seq_field.str_from_value("FORMAT: @")
        self.assertEqual(expected, result)

        expected = "$F3"
        result = seq_field.str_from_value("FORMAT: $F")
        self.assertEqual(expected, result)

        expected = "<UDIM>"
        result = seq_field.str_from_value(value="FORMAT: <UDIM>")
        self.assertEqual(expected, result)

        expected = "$UDIM"
        result = seq_field.str_from_value(value="FORMAT: $UDIM")
        self.assertEqual(expected, result)
Ejemplo n.º 15
0
    def setUp(self):
        super(TestTemplatePath, self).setUp()

        # Make various types of keys(fields)
        self.keys = {
            "Sequence": StringKey("Sequence"),
            "Shot": StringKey("Shot",
                              default="s1",
                              choices=["s1", "s2", "shot_1"]),
            "Step": StringKey("Step"),
            "branch": StringKey("branch", filter_by="alphanumeric"),
            "name": StringKey("name"),
            "name_alpha": StringKey("name_alpha", filter_by="alphanumeric"),
            "version": IntegerKey("version", format_spec="03"),
            "snapshot": IntegerKey("snapshot", format_spec="03"),
            "ext": StringKey("ext"),
            "seq_num": SequenceKey("seq_num"),
            "frame": SequenceKey("frame", format_spec="04")
        }
        # Make a template
        self.definition = "shots/{Sequence}/{Shot}/{Step}/work/{Shot}.{branch}.v{version}.{snapshot}.ma"

        # legacy style template object which only knows about the currently running operating system
        self.template_path_current_os_only = TemplatePath(
            self.definition, self.keys, self.project_root)

        # new style template object which supports all recognized platforms
        # get all OS roots for primary storage
        all_roots = self.pipeline_configuration.get_all_platform_data_roots(
        )["primary"]

        self.template_path = TemplatePath(self.definition,
                                          self.keys,
                                          self.project_root,
                                          per_platform_roots=all_roots)

        self.project_root_template = TemplatePath("/",
                                                  self.keys,
                                                  self.project_root,
                                                  per_platform_roots=all_roots)

        # make template with sequence key
        self.sequence = TemplatePath("/path/to/seq.{frame}.ext", self.keys, "",
                                     "frame")
Ejemplo n.º 16
0
 def test_abstracted_sequence_path(self):
     # make sequence template matching sequence publish
     keys = {"seq": SequenceKey("seq", format_spec="03")}
     template = TemplatePath("foo/seq_{seq}.ext", keys, self.project_root)
     self.tk.templates["sequence_test"] = template
     paths = [os.path.join(self.project_root, "foo", "seq_%03d.ext")]
     d = tank.util.find_publish(self.tk, paths)
     self.assertEqual(len(d), 1)
     self.assertEqual(set(d.keys()), set((paths[0], )))
     sg_data = d.get(paths[0])
     self.assertEqual(sg_data["id"], self.pub_4["id"])
Ejemplo n.º 17
0
class TestSequenceKey(TankTestBase):
    def setUp(self):
        super(TestSequenceKey, self).setUp()
        self.seq_field = SequenceKey("field_name")

    def test_framespec_no_format(self):
        seq_field = SequenceKey("field_name")
        expected_frame_specs = set(["%d", "#", "@", "$F"])
        self.assertEquals(expected_frame_specs, set(seq_field._frame_specs))

    def test_framspec_short_format(self):
        format_spec = "02"
        expected_frame_specs = set(["%02d", "##", "@@", "$F2"])
        seq_field = SequenceKey("field_name", format_spec=format_spec)
        self.assertEquals(expected_frame_specs, set(seq_field._frame_specs))

    def test_framespec_long_format(self):
        format_spec = "010"
        seq_field = SequenceKey("field_name", format_spec=format_spec)
        expected_frame_specs = set(
            ["%010d", "@@@@@@@@@@", "##########", "$F10"])
        self.assertEquals(expected_frame_specs, set(seq_field._frame_specs))

    def test_validate_good(self):
        good_values = copy.copy(self.seq_field._frame_specs)
        good_values.extend(["FORMAT:%d", "FORMAT:#", "FORMAT:@", "FORMAT:$F"])
        good_values.extend(
            ["FORMAT:  %d", "FORMAT:  #", "FORMAT:  @", "FORMAT:  $F"])
        good_values.extend(["243", "0123"])
        for good_value in good_values:
            self.assertTrue(self.seq_field.validate(good_value))

    def test_validate_bad(self):
        bad_values = ["a", "$G", "23d"]
        for bad_value in bad_values:
            self.assertFalse(self.seq_field.validate(bad_value))

    def test_value_from_str(self):

        # note - default case means frame spec is 01
        valid_str_values = {
            "12": 12,
            "0": 0,
            "%d": "%d",
            "#": "#",
            "@": "@",
            "$F": "$F"
        }
        for str_value, expected_value in valid_str_values.items():
            self.assertEquals(expected_value,
                              self.seq_field.value_from_str(str_value))

    def test_str_from_value_good(self):

        # note - default case means frame spec is 01
        valid_value_strs = {
            12: "12",
            0: "0",
            "%d": "%d",
            "#": "#",
            "@": "@",
            "$F": "$F"
        }
        for value, str_value in valid_value_strs.items():
            self.assertEquals(str_value, self.seq_field.str_from_value(value))

    def test_str_from_value_bad(self):
        value = "a"
        expected = "%s Illegal value '%s', expected an Integer, a frame spec or format spec." % (
            str(self.seq_field), value)
        expected += "\nValid frame specs: ['%d', '#', '@', '$F']"
        expected += "\nValid format strings: ['FORMAT: %d', 'FORMAT: #', 'FORMAT: @', 'FORMAT: $F']\n"

        self.check_error_message(TankError, expected,
                                 self.seq_field.str_from_value, value)

    def test_str_from_value_formatted(self):
        formatted_field = SequenceKey("field_name", format_spec="03")
        value = 3
        expected = "%03d" % value
        result = formatted_field.str_from_value(value)
        self.assertEquals(expected, result)

    def test_str_from_value_ignore_type(self):
        value = "a"
        expected = value
        result = self.seq_field.str_from_value(value, ignore_type=True)
        self.assertEquals(expected, result)

    def test_str_from_value_default_one(self):
        """
        default frame spec value can be returned, frame spec with 
        one place has special cases.
        """
        value = None
        seq_field = SequenceKey("field_name")
        expected = "%d"
        result = seq_field.str_from_value(value="FORMAT:%d")
        self.assertEquals(expected, result)

        expected = "#"
        result = seq_field.str_from_value(value="FORMAT:#")
        self.assertEquals(expected, result)

        expected = "@"
        result = seq_field.str_from_value(value="FORMAT:@")
        self.assertEquals(expected, result)

        expected = "$F"
        result = seq_field.str_from_value(value="FORMAT:$F")
        self.assertEquals(expected, result)

        # no pattern specified
        expected = "%d"
        result = seq_field.str_from_value()
        self.assertEquals(expected, result)

    def test_str_from_value_default_three(self):
        """
        Test default frame spec value returned for framespec with more than
        one places.
        """
        seq_field = SequenceKey("field_name", format_spec="03")

        expected = "%03d"
        result = seq_field.str_from_value("FORMAT:%d")
        self.assertEquals(expected, result)

        expected = "###"
        result = seq_field.str_from_value("FORMAT:#")
        self.assertEquals(expected, result)

        expected = "@@@"
        result = seq_field.str_from_value("FORMAT:@")
        self.assertEquals(expected, result)

        expected = "$F3"
        result = seq_field.str_from_value("FORMAT:$F")
        self.assertEquals(expected, result)

        # no pattern specified
        expected = "%03d"
        result = seq_field.str_from_value()
        self.assertEquals(expected, result)

    def test_str_from_value_format_whitespace(self):
        """Use of FORMAT: prefix with whitespace."""

        seq_field = SequenceKey("field_name", format_spec="03")

        expected = "%03d"
        result = seq_field.str_from_value("FORMAT: %d")
        self.assertEquals(expected, result)

        expected = "###"
        result = seq_field.str_from_value("FORMAT: #")
        self.assertEquals(expected, result)

        expected = "@@@"
        result = seq_field.str_from_value("FORMAT: @")
        self.assertEquals(expected, result)

        expected = "$F3"
        result = seq_field.str_from_value("FORMAT: $F")
        self.assertEquals(expected, result)

    def test_default_int(self):
        default = 13
        seq_frame = SequenceKey("field_name", default=default)
        self.assertEquals(default, seq_frame.default)

    def test_default_frame_spec(self):
        frame_specs = set(["%d", "#", "@", "$F"])
        for frame_spec in frame_specs:
            seq_frame = SequenceKey("field_name", default=frame_spec)
            self.assertEquals(frame_spec, seq_frame.default)

    def test_default_frame_spec_choices(self):
        frame_specs = set(["%d", "#", "@", "$F"])
        for frame_spec in frame_specs:
            seq_frame = SequenceKey("field_name",
                                    default=frame_spec,
                                    choices=[1, 2])
            self.assertEquals(frame_spec, seq_frame.default)

    def test_default_bad(self):
        default = "bad default"
        self.assertRaises(TankError,
                          SequenceKey,
                          "field_name",
                          default=default)

    def test_choices_int(self):
        choices = [1]
        seq_frame = SequenceKey("field_name", choices=choices)
        self.assertEquals(choices, seq_frame.choices)

    def test_choices_frame_spec(self):
        frame_specs = set(["%d", "#", "@", "$F"])
        seq_frame = SequenceKey("field_name", choices=frame_specs)
        self.assertEquals(frame_specs, seq_frame.choices)
Ejemplo n.º 18
0
 def test_default_int(self):
     default = 13
     seq_frame = SequenceKey("field_name", default=default)
     self.assertEquals(default, seq_frame.default)
Ejemplo n.º 19
0
 def test_str_from_value_formatted(self):
     formatted_field = SequenceKey("field_name", format_spec="03")
     value = 3
     expected = "%03d" % value
     result = formatted_field.str_from_value(value)
     self.assertEquals(expected, result)
Ejemplo n.º 20
0
 def test_framespec_long_format(self):
     format_spec = "010"
     seq_field = SequenceKey("field_name", format_spec=format_spec)
     expected_frame_specs = set(
         ["%010d", "@@@@@@@@@@", "##########", "$F10"])
     self.assertEquals(expected_frame_specs, set(seq_field._frame_specs))
Ejemplo n.º 21
0
 def test_framspec_short_format(self):
     format_spec = "02"
     expected_frame_specs = set(["%02d", "##", "@@", "$F2"])
     seq_field = SequenceKey("field_name", format_spec=format_spec)
     self.assertEquals(expected_frame_specs, set(seq_field._frame_specs))
Ejemplo n.º 22
0
 def test_framespec_no_format(self):
     seq_field = SequenceKey("field_name")
     expected_frame_specs = set(["%d", "#", "@", "$F"])
     self.assertEquals(expected_frame_specs, set(seq_field._frame_specs))
Ejemplo n.º 23
0
 def setUp(self):
     super(TestSequenceKey, self).setUp()
     self.seq_field = SequenceKey("field_name")
Ejemplo n.º 24
0
 def test_str_from_value_formatted(self):
     formatted_field = SequenceKey("field_name", format_spec="03")
     value = 3
     expected = "%03d" % value
     result = formatted_field.str_from_value(value)
     self.assertEquals(expected, result)
Ejemplo n.º 25
0
 def test_choices_int(self):
     choices = [1]
     seq_frame = SequenceKey("field_name", choices=choices)
     self.assertEquals(choices, seq_frame.choices)
Ejemplo n.º 26
0
 def test_choices_frame_spec(self):
     frame_specs = set(["%d", "#", "@", "$F", "<UDIM>", "$UDIM"])
     seq_frame = SequenceKey("field_name", choices=frame_specs)
     self.assertEqual(list(frame_specs), seq_frame.choices)
Ejemplo n.º 27
0
class TestSequenceKey(TankTestBase):
    def setUp(self):
        super(TestSequenceKey, self).setUp()
        self.seq_field = SequenceKey("field_name")


    def test_framespec_no_format(self):
        seq_field = SequenceKey("field_name")
        expected_frame_specs = set(["%d", "#", "@", "$F"])
        self.assertEquals(expected_frame_specs, set(seq_field._frame_specs))

    def test_framspec_short_format(self):
        format_spec = "02"
        expected_frame_specs = set(["%02d", "##", "@@", "$F2"])
        seq_field = SequenceKey("field_name", format_spec=format_spec)
        self.assertEquals(expected_frame_specs, set(seq_field._frame_specs))

    def test_framespec_long_format(self):
        format_spec = "010"
        seq_field = SequenceKey("field_name", format_spec=format_spec)
        expected_frame_specs = set(["%010d", "@@@@@@@@@@", "##########", "$F10"])
        self.assertEquals(expected_frame_specs, set(seq_field._frame_specs))

    def test_validate_good(self):
        good_values = copy.copy(self.seq_field._frame_specs)
        good_values.extend(["FORMAT:%d", "FORMAT:#", "FORMAT:@", "FORMAT:$F"])
        good_values.extend(["FORMAT:  %d", "FORMAT:  #", "FORMAT:  @", "FORMAT:  $F"])
        good_values.extend(["243", "0123"])
        for good_value in good_values:
            self.assertTrue(self.seq_field.validate(good_value))

    def test_validate_bad(self):
        bad_values = ["a", "$G", "23d"]
        for bad_value in bad_values:
            self.assertFalse(self.seq_field.validate(bad_value))

    def test_value_from_str(self):
        
        # note - default case means frame spec is 01
        valid_str_values = {"12":12,
                            "0":0,
                            "%d":"%d",
                            "#":"#",
                            "@":"@",
                            "$F":"$F"}
        for str_value, expected_value in valid_str_values.items():
            self.assertEquals(expected_value, self.seq_field.value_from_str(str_value))

    def test_str_from_value_good(self):
        
        # note - default case means frame spec is 01
        valid_value_strs = {12:"12",
                            0:"0",
                            "%d":"%d",
                            "#":"#",
                            "@":"@",
                            "$F":"$F"}
        for value, str_value in valid_value_strs.items():
            self.assertEquals(str_value, self.seq_field.str_from_value(value))
        

    def test_str_from_value_bad(self):
        value = "a"
        expected = "%s Illegal value '%s', expected an Integer, a frame spec or format spec." % (str(self.seq_field), value)
        expected += "\nValid frame specs: ['%d', '#', '@', '$F']"
        expected += "\nValid format strings: ['FORMAT: %d', 'FORMAT: #', 'FORMAT: @', 'FORMAT: $F']\n"

        self.check_error_message(TankError, expected, self.seq_field.str_from_value, value)

    def test_str_from_value_formatted(self):
        formatted_field = SequenceKey("field_name", format_spec="03")
        value = 3
        expected = "%03d" % value
        result = formatted_field.str_from_value(value)
        self.assertEquals(expected, result)

    def test_str_from_value_ignore_type(self):
        value = "a"
        expected = value
        result = self.seq_field.str_from_value(value, ignore_type=True)
        self.assertEquals(expected, result)

    def test_str_from_value_default_one(self):
        """
        default frame spec value can be returned, frame spec with 
        one place has special cases.
        """
        value = None
        seq_field = SequenceKey("field_name")
        expected = "%d"
        result = seq_field.str_from_value(value="FORMAT:%d")
        self.assertEquals(expected, result)

        expected = "#"
        result = seq_field.str_from_value(value="FORMAT:#")
        self.assertEquals(expected, result)

        expected = "@"
        result = seq_field.str_from_value(value="FORMAT:@")
        self.assertEquals(expected, result)

        expected = "$F"
        result = seq_field.str_from_value(value="FORMAT:$F")
        self.assertEquals(expected, result)

        # no pattern specified
        expected = "%d"
        result = seq_field.str_from_value()
        self.assertEquals(expected, result)

    def test_str_from_value_default_three(self):
        """
        Test default frame spec value returned for framespec with more than
        one places.
        """
        seq_field = SequenceKey("field_name", format_spec="03")
        
        expected = "%03d"
        result = seq_field.str_from_value("FORMAT:%d")
        self.assertEquals(expected, result)

        expected = "###"
        result = seq_field.str_from_value("FORMAT:#")
        self.assertEquals(expected, result)

        expected = "@@@"
        result = seq_field.str_from_value("FORMAT:@")
        self.assertEquals(expected, result)

        expected = "$F3"
        result = seq_field.str_from_value("FORMAT:$F")
        self.assertEquals(expected, result)

        # no pattern specified
        expected = "%03d"
        result = seq_field.str_from_value()
        self.assertEquals(expected, result)

    def test_str_from_value_format_whitespace(self):
        """Use of FORMAT: prefix with whitespace."""
        
        seq_field = SequenceKey("field_name", format_spec="03")
        
        expected = "%03d"
        result = seq_field.str_from_value("FORMAT: %d")
        self.assertEquals(expected, result)

        expected = "###"
        result = seq_field.str_from_value("FORMAT: #")
        self.assertEquals(expected, result)

        expected = "@@@"
        result = seq_field.str_from_value("FORMAT: @")
        self.assertEquals(expected, result)

        expected = "$F3"
        result = seq_field.str_from_value("FORMAT: $F")
        self.assertEquals(expected, result)

    def test_default_int(self):
        default = 13
        seq_frame = SequenceKey("field_name", default=default)
        self.assertEquals(default, seq_frame.default)

    def test_default_frame_spec(self):
        frame_specs = set(["%d", "#", "@", "$F"])
        for frame_spec in frame_specs:
            seq_frame = SequenceKey("field_name", default=frame_spec)
            self.assertEquals(frame_spec, seq_frame.default)

    def test_default_frame_spec_choices(self):
        frame_specs = set(["%d", "#", "@", "$F"])
        for frame_spec in frame_specs:
            seq_frame = SequenceKey("field_name", default=frame_spec, choices=[1,2])
            self.assertEquals(frame_spec, seq_frame.default)

    def test_default_bad(self):
        default = "bad default"
        self.assertRaises(TankError, SequenceKey, "field_name", default=default)

    def test_choices_int(self):
        choices = [1]
        seq_frame = SequenceKey("field_name", choices=choices)
        self.assertEquals(choices, seq_frame.choices)

    def test_choices_frame_spec(self):
        frame_specs = set(["%d", "#", "@", "$F"])
        seq_frame = SequenceKey("field_name", choices=frame_specs)
        self.assertEquals(frame_specs, seq_frame.choices)
Ejemplo n.º 28
0
 def test_choices_frame_spec(self):
     frame_specs = set(["%d", "#", "@", "$F"])
     seq_frame = SequenceKey("field_name", choices=frame_specs)
     self.assertEquals(frame_specs, seq_frame.choices)
Ejemplo n.º 29
0
 def setUp(self):
     super(TestSequenceKey, self).setUp()
     self.seq_field = SequenceKey("field_name")
Ejemplo n.º 30
0
    def setUp(self):
        super(TestAbstractPathsFromTemplate, self).setUp()
        self.setup_fixtures()

        keys = {
            "Sequence":
            StringKey("Sequence"),
            "Shot":
            StringKey("Shot"),
            "eye":
            StringKey("eye",
                      default="%V",
                      choices=["left", "right", "%V"],
                      abstract=True),
            "name":
            StringKey("name"),
            "SEQ":
            SequenceKey("SEQ", format_spec="04"),
        }

        definition = "sequences/{Sequence}/{Shot}/{eye}/{name}.{SEQ}.exr"

        self.template = TemplatePath(definition, keys, self.project_root)

        # create fixtures
        seq_path = os.path.join(self.project_root, "sequences", "SEQ_001")
        self.shot_a_path = os.path.join(seq_path, "AAA")
        self.shot_b_path = os.path.join(seq_path, "BBB")

        eye_left_a = os.path.join(self.shot_a_path, "left")

        self.create_file(os.path.join(eye_left_a, "filename.0001.exr"))
        self.create_file(os.path.join(eye_left_a, "filename.0002.exr"))
        self.create_file(os.path.join(eye_left_a, "filename.0003.exr"))
        self.create_file(os.path.join(eye_left_a, "filename.0004.exr"))
        self.create_file(os.path.join(eye_left_a, "anothername.0001.exr"))
        self.create_file(os.path.join(eye_left_a, "anothername.0002.exr"))
        self.create_file(os.path.join(eye_left_a, "anothername.0003.exr"))
        self.create_file(os.path.join(eye_left_a, "anothername.0004.exr"))

        eye_left_b = os.path.join(self.shot_b_path, "left")

        self.create_file(os.path.join(eye_left_b, "filename.0001.exr"))
        self.create_file(os.path.join(eye_left_b, "filename.0002.exr"))
        self.create_file(os.path.join(eye_left_b, "filename.0003.exr"))
        self.create_file(os.path.join(eye_left_b, "filename.0004.exr"))
        self.create_file(os.path.join(eye_left_b, "anothername.0001.exr"))
        self.create_file(os.path.join(eye_left_b, "anothername.0002.exr"))
        self.create_file(os.path.join(eye_left_b, "anothername.0003.exr"))
        self.create_file(os.path.join(eye_left_b, "anothername.0004.exr"))

        eye_right_a = os.path.join(self.shot_a_path, "right")

        self.create_file(os.path.join(eye_right_a, "filename.0001.exr"))
        self.create_file(os.path.join(eye_right_a, "filename.0002.exr"))
        self.create_file(os.path.join(eye_right_a, "filename.0003.exr"))
        self.create_file(os.path.join(eye_right_a, "filename.0004.exr"))
        self.create_file(os.path.join(eye_right_a, "anothername.0001.exr"))
        self.create_file(os.path.join(eye_right_a, "anothername.0002.exr"))
        self.create_file(os.path.join(eye_right_a, "anothername.0003.exr"))
        self.create_file(os.path.join(eye_right_a, "anothername.0004.exr"))

        eye_right_b = os.path.join(self.shot_b_path, "right")

        self.create_file(os.path.join(eye_right_b, "filename.0001.exr"))
        self.create_file(os.path.join(eye_right_b, "filename.0002.exr"))
        self.create_file(os.path.join(eye_right_b, "filename.0003.exr"))
        self.create_file(os.path.join(eye_right_b, "filename.0004.exr"))
        self.create_file(os.path.join(eye_right_b, "anothername.0001.exr"))
        self.create_file(os.path.join(eye_right_b, "anothername.0002.exr"))
        self.create_file(os.path.join(eye_right_b, "anothername.0003.exr"))
        self.create_file(os.path.join(eye_right_b, "anothername.0004.exr"))
Ejemplo n.º 31
0
 def test_default_frame_spec(self):
     frame_specs = set(["%d", "#", "@", "$F", "<UDIM>", "$UDIM"])
     for frame_spec in frame_specs:
         seq_frame = SequenceKey("field_name", default=frame_spec)
         self.assertEqual(frame_spec, seq_frame.default)