def test_doesnt_expand_nonexistent_vars(self): with mock.patch.dict("os.environ", self.env): e = Expander() o = {"foo": "${JOB}_hello", "bar": "x_${PROD}_y"} result = e.evaluate(o) self.assertIsInstance(result, dict) self.assertEqual(result, o)
def test_expand_dict_target(self): e = Expander(**self.context) result = e.evaluate({"foo": "x_<shot>_y", "bar": "x_<ct_dept>_y"}) self.assertIsInstance(result, dict) self.assertEqual(result, { "foo": "x_/metropolis/shot01/_y", "bar": "x_texturing_y" })
def test_expand_env_vars(self): with mock.patch.dict("os.environ", self.env): e = Expander() result = e.evaluate({"foo": "${SHOT}_hello", "bar": "x_${DEPT}_y"}) self.assertIsInstance(result, dict) self.assertEqual(result, { "foo": "MT_shot01_hello", "bar": "x_texturing_y" })
def test_expand_empty_list_target(self): e = Expander(**self.context) result = e.evaluate([]) self.assertIsInstance(result, list) self.assertEqual(result, [])
def test_expand_list_target(self): e = Expander(**self.context) result = e.evaluate(["x_<shot>_y", "x_<ct_dept>_y"]) self.assertIsInstance(result, list) self.assertEqual(result, ["x_/metropolis/shot01/_y", "x_texturing_y"])
def test_repeated_tokens(self): e = Expander(**self.context) result = e.evaluate("x_<Scene>_<Scene>_y") self.assertEqual(result, "x_/projects/myscene_/projects/myscene_y")
def test_mixed_case(self): e = Expander(**self.context) result = e.evaluate("x_<Scene>_y") self.assertEqual(result, "x_/projects/myscene_y")
def test_bad_value_raises(self): e = Expander(**self.context) with self.assertRaises(KeyError): e.evaluate("<bad>")
def test_expand_empty_dict_target(self): e = Expander(**self.context) result = e.evaluate({}) self.assertIsInstance(result, dict) self.assertEqual(result, {})
def test_expand_value_target(self): e = Expander(**self.context) result = e.evaluate("x_<home>_y") self.assertEqual(result, "x_/users/joebloggs/_y")
def test_invalid_when_expr_invalid(self): e = Expander(**self.context) with self.assertRaises(ValueError): e.evaluate("/prefix/<pad start X>/<Scene>.<pad start 4>.exr")
def test_expand_value_with_expr_when_identical_expr_appears_twice(self): e = Expander(**self.context) result = e.evaluate("/prefix/<pad start 4>/<Scene>.<pad start 4>.exr") self.assertEqual(result, "/prefix/0020/foo.0020.exr")
def test_expand_value_with_several_plugins(self): e = Expander(start=20, outpath="C:\\my\\path") result = e.evaluate("<posix outpath>/foo.<pad start 4>.exr") self.assertEqual(result, "/my/path/foo.0020.exr")
def test_expand_value_with_expr(self): e = Expander(**self.context) result = e.evaluate("/prefix/<Scene>.<pad start 4>.exr") self.assertEqual(result, "/prefix/foo.0020.exr")
def test_bad_list_value_raises(self): e = Expander(**self.context) with self.assertRaises(KeyError): e.evaluate(["<bad>", "directories"])
def test_expand_numeric_value_target(self): e = Expander(**self.context) result = e.evaluate("x_<frames>_y") self.assertEqual(result, "x_20_y")
def test_expand_numeric_value_is_string(self): e = Expander(**self.context) result = e.evaluate("<frames>") self.assertIsInstance(result, str) self.assertEqual(result, "20")
def test_bad_dict_value_raises(self): e = Expander(**self.context) with self.assertRaises(KeyError): e.evaluate({"foo": "<bad>", "bar": "directories"})
def test_bad_dict_value_does_not_raise_if_safe(self): e = Expander(safe=True, **self.context) result = e.evaluate("x_<bad>_y") self.assertEqual(result, "x_<bad>_y")