def test_key_only(self): definition = "{Shot}" template_string = TemplateString(definition, self.keys) input_string = "shot_1" expected = {"Shot": "shot_1"} result = template_string.get_fields(input_string) self.assertEquals(expected, result)
def test_key_only(self): definition = "{Shot}" template_string = TemplateString(definition, self.keys) input_string = "shot_1" expected = {"Shot": "shot_1"} result = template_string.get_fields(input_string) self.assertEqual(expected, result)
def test_key_first(self): definition = "{Shot}.{Sequence}" template_string = TemplateString(definition, self.keys) input_string = "shot_1.Seq_12" expected = {"Shot": "shot_1", "Sequence": "Seq_12"} result = template_string.get_fields(input_string) self.assertEqual(expected, result)
def test_key_first(self): definition = "{Shot}.{Sequence}" template_string = TemplateString(definition, self.keys) input_string = "shot_1.Seq_12" expected = {"Shot": "shot_1", "Sequence": "Seq_12"} result = template_string.get_fields(input_string) self.assertEquals(expected, result)
def test_optional_value(self): template_string = TemplateString("something-{Shot}[.{Sequence}]", self.keys) fields = {"Shot": "shot_1", "Sequence": "seq_2"} expected = "something-shot_1.seq_2" result = template_string.apply_fields(fields) self.assertEquals(expected, result) # remove optional value del(fields["Sequence"]) expected = "something-shot_1" result = template_string.apply_fields(fields) self.assertEquals(expected, result)
def test_optional_value(self): template_string = TemplateString("something-{Shot}[.{Sequence}]", self.keys) fields = {"Shot": "shot_1", "Sequence": "seq_2"} expected = "something-shot_1.seq_2" result = template_string.apply_fields(fields) self.assertEqual(expected, result) # remove optional value del fields["Sequence"] expected = "something-shot_1" result = template_string.apply_fields(fields) self.assertEqual(expected, result)
def test_optional_values(self): template_string = TemplateString("something-{Shot}[.{Sequence}]", self.keys) input_string = "something-shot_1.seq_2" expected = {"Shot": "shot_1", "Sequence": "seq_2"} self.assertTrue(template_string.validate(input_string)) # without optional value input_string = "something-shot_1" expected = {"Shot": "shot_1"} self.assertTrue(template_string.validate(input_string))
def test_static_key_first(self): definition = "{Shot}something-{Sequence}." template = TemplateString(definition, self.keys) expected = [[ "%s%s" % (template._prefix, os.path.sep), "something-", "." ]] self.assertEqual(expected, template._static_tokens)
def test_definition_short_end_static(self): """Tests case when input string longer than definition which ends with non key.""" definition = "{Shot}.something" template_string = TemplateString(definition, self.keys) input_string = "shot_1.something-else" self.assertRaises(TankError, self.template_string.get_fields, input_string)
def setUp(self): super(TestTemplateString, self).setUp() self.keys = { "Sequence": StringKey("Sequence"), "Shot": StringKey("Shot"), "version": IntegerKey("version"), } self.template_string = TemplateString("something-{Shot}.{Sequence}", self.keys)
def test_definition_preseves_leading_slash(self): """ The TemplateString should not change the use of os seperators in the input definition. """ # forward slashes with leading slash definition = "/tmp/{Shot}/something/{Sequence}/" template_string = TemplateString(definition, self.keys) self.assertEqual(definition, template_string.definition)
def test_optional_values(self): """ Test definition containing optional sections resolves correctly. """ template_string = TemplateString("something-{Shot}[.{Sequence}]", self.keys) input_string = "something-shot_1.seq_2" expected = {"Shot": "shot_1", "Sequence": "seq_2"} result = template_string.get_fields(input_string) self.assertEqual(expected, result) # without optional value input_string = "something-shot_1" expected = {"Shot": "shot_1"} result = template_string.get_fields(input_string) self.assertEqual(expected, result)
def test_optional_values(self): """ Test definition containing optional sections resolves correctly. """ template_string = TemplateString("something-{Shot}[.{Sequence}]", self.keys) input_string = "something-shot_1.seq_2" expected = {"Shot": "shot_1", "Sequence": "seq_2"} result = template_string.get_fields(input_string) self.assertEquals(expected, result) # without optional value input_string = "something-shot_1" expected = {"Shot": "shot_1"} result = template_string.get_fields(input_string) self.assertEquals(expected, result)
def test_key_first(self): definition = "{Shot}something-{Sequence}." template_string = TemplateString(definition, self.keys) valid_string = "shot_1something-Seq_12." self.assertTrue(template_string.validate(valid_string))
def test_conflicting_values(self): definition = "{Shot}-{Sequence}.{Shot}" template_string = TemplateString(definition, self.keys) invalid_string = "shot_1-Seq_12.shot_2" self.assertFalse(self.template_string.validate(invalid_string))
def test_definition_preserves_back_slashes(self): # back slashes with leading slash definition = r"\something\{Shot}\\" template_string = TemplateString(definition, self.keys) self.assertEqual(definition, template_string.definition)
def test_static_simple(self): definition = "something-{Shot}.{Sequence}" template = TemplateString(definition, self.keys) expected = [["%s%ssomething-" % (template._prefix, os.path.sep), "."]] self.assertEquals(expected, template._static_tokens)