Exemplo n.º 1
0
 def test_type_change(self):
     """Exception is raised if replacement type differs."""
     with self.assertRaises(TypeError):
         replace = jmes.Replace("metadata", "root().TM")
         replace.run(deepcopy(SAMPLE_STATE))
     with self.assertRaises(TypeError):
         replace = jmes.Replace("templates", "root().TM")
         replace.run(deepcopy(SAMPLE_STATE))
Exemplo n.º 2
0
 def test_update_list(self):
     """When value_expr gives a list, it is replaced in-place."""
     replace = jmes.Replace("templates", "@[?TM < `0.5`]")
     results = replace.run(deepcopy(SAMPLE_STATE))
     self.assertEqual(results, {
         "TM": 0.5,
         "templates": [
             {"TM": 0.3, "name": "foo"},
         ],
         "metadata": {"date": "1970-01-01"}
     })
Exemplo n.º 3
0
 def test_update_dict(self):
     """When value_expr gives a dict, it is replaced in-place."""
     replace = jmes.Replace("metadata", "{qux: `123`}")
     results = replace.run(deepcopy(SAMPLE_STATE))
     self.assertEqual(results, {
         "TM": 0.5,
         "templates": [
             {"TM": 0.3, "name": "foo"},
             {"TM": 0.6, "name": "bar"},
         ],
         "metadata": {"qux": 123}
     })
Exemplo n.º 4
0
 def test_replace_identity(self):
     """Replacing identical elements does nothing."""
     replace = jmes.Replace("@", "@")
     results = replace.run(deepcopy(SAMPLE_STATE))
     self.assertEqual(results, SAMPLE_STATE)
Exemplo n.º 5
0
 def test_invalid_selection(self):
     """Can only replace dicts and lists."""
     with self.assertRaises(TypeError):
         replace = jmes.Replace("TM", "`[1,2,3]`")
         replace.run(deepcopy(SAMPLE_STATE))