def test_runnable_to_recipe_noop(self): runnable = Runnable('noop', None) recipe_path = os.path.join(self.tmpdir.name, 'recipe.json') runnable.write_json(recipe_path) self.assertTrue(os.path.exists(recipe_path)) loaded_runnable = Runnable.from_recipe(recipe_path) self.assertEqual(loaded_runnable.kind, 'noop')
def test_runnable_to_recipe_uri(self): runnable = Runnable('exec-test', '/bin/true') recipe_path = os.path.join(self.tmpdir.name, 'recipe.json') runnable.write_json(recipe_path) self.assertTrue(os.path.exists(recipe_path)) loaded_runnable = Runnable.from_recipe(recipe_path) self.assertEqual(loaded_runnable.kind, 'exec-test') self.assertEqual(loaded_runnable.uri, '/bin/true')
def test_runnable_to_recipe_uri(self): runnable = Runnable("exec-test", "/bin/true") recipe_path = os.path.join(self.tmpdir.name, "recipe.json") runnable.write_json(recipe_path) self.assertTrue(os.path.exists(recipe_path)) loaded_runnable = Runnable.from_recipe(recipe_path) self.assertEqual(loaded_runnable.kind, "exec-test") self.assertEqual(loaded_runnable.uri, "/bin/true")
def command_runnable_run_recipe(self, args): """ Runs a runnable definition from a recipe :param args: parsed command line arguments turned into a dictionary :type args: dict """ runnable = Runnable.from_recipe(args.get("recipe")) runner = self.get_runner_from_runnable(runnable) for status in runner.run(runnable): self.echo(status)
def test_recipe_exec(self): open_mocked = unittest.mock.mock_open( read_data=('{"kind": "exec-test", "uri": "/bin/sh", ' '"args": ["/etc/profile"], ' '"kwargs": {"TERM": "vt3270"}}')) with unittest.mock.patch("builtins.open", open_mocked): runnable = Runnable.from_recipe("fake_path") self.assertEqual(runnable.kind, "exec-test") self.assertEqual(runnable.uri, "/bin/sh") self.assertEqual(runnable.args, ("/etc/profile", )) self.assertEqual(runnable.kwargs, {"TERM": "vt3270"})
def test_recipe_noop(self): open_mocked = unittest.mock.mock_open(read_data='{"kind": "noop"}') with unittest.mock.patch("builtins.open", open_mocked): runnable = Runnable.from_recipe("fake_path") self.assertEqual(runnable.kind, "noop")