diff --git a/recipe_modules/infra_paths/api.py b/recipe_modules/infra_paths/api.py index c84928c4f..1b902826f 100644 --- a/recipe_modules/infra_paths/api.py +++ b/recipe_modules/infra_paths/api.py @@ -3,6 +3,7 @@ # found in the LICENSE file. from recipe_engine import recipe_api +from recipe_engine.config_types import Path, NamedBasePath class InfraPathsApi(recipe_api.RecipeApi): @@ -28,6 +29,10 @@ class InfraPathsApi(recipe_api.RecipeApi): else: self.set_config('buildbot') + for path in self._test_data.get('exists', []): + assert isinstance(path.base, NamedBasePath) + self.m.path.mock_add_paths(self[path.base.name].join(*path.pieces)) + def __getitem__(self, name): self._lazy_set_config() return self.c.paths[name] diff --git a/recipe_modules/infra_paths/example.expected/linux.json b/recipe_modules/infra_paths/example.expected/linux.json index 9ec0cb6ce..98dba8c96 100644 --- a/recipe_modules/infra_paths/example.expected/linux.json +++ b/recipe_modules/infra_paths/example.expected/linux.json @@ -4,6 +4,10 @@ "cwd": "[CWD]", "name": "step" }, + { + "cmd": [], + "name": "path exists" + }, { "name": "$result", "recipe_result": null, diff --git a/recipe_modules/infra_paths/example.expected/mac.json b/recipe_modules/infra_paths/example.expected/mac.json index 9ec0cb6ce..98dba8c96 100644 --- a/recipe_modules/infra_paths/example.expected/mac.json +++ b/recipe_modules/infra_paths/example.expected/mac.json @@ -4,6 +4,10 @@ "cwd": "[CWD]", "name": "step" }, + { + "cmd": [], + "name": "path exists" + }, { "name": "$result", "recipe_result": null, diff --git a/recipe_modules/infra_paths/example.expected/win.json b/recipe_modules/infra_paths/example.expected/win.json index 9ec0cb6ce..98dba8c96 100644 --- a/recipe_modules/infra_paths/example.expected/win.json +++ b/recipe_modules/infra_paths/example.expected/win.json @@ -4,6 +4,10 @@ "cwd": "[CWD]", "name": "step" }, + { + "cmd": [], + "name": "path exists" + }, { "name": "$result", "recipe_result": null, diff --git a/recipe_modules/infra_paths/example.py b/recipe_modules/infra_paths/example.py index 9e6f712fa..f55bf058b 100644 --- a/recipe_modules/infra_paths/example.py +++ b/recipe_modules/infra_paths/example.py @@ -4,6 +4,7 @@ DEPS = [ 'infra_paths', + 'recipe_engine/path', 'recipe_engine/platform', 'recipe_engine/properties', 'recipe_engine/step', @@ -14,10 +15,16 @@ from recipe_engine.config_types import Path def RunSteps(api): api.step('step', [], cwd=api.infra_paths['slave_build']) + if api.path.exists(api.infra_paths['slave_build'].join('foo.txt')): + api.step('path exists', []) + def GenTests(api): for platform in ('linux', 'win', 'mac'): - yield (api.test(platform) + api.platform.name(platform)) + yield (api.test(platform) + + api.platform.name(platform) + + api.infra_paths.exists( + api.infra_paths['slave_build'].join('foo.txt'))) yield (api.test('%s_kitchen' % platform) + api.platform.name(platform) + diff --git a/recipe_modules/infra_paths/test_api.py b/recipe_modules/infra_paths/test_api.py new file mode 100644 index 000000000..a5bbb9ae4 --- /dev/null +++ b/recipe_modules/infra_paths/test_api.py @@ -0,0 +1,16 @@ +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +from recipe_engine import recipe_test_api +from recipe_engine.config_types import Path, NamedBasePath + +class InfraPathsTestApi(recipe_test_api.RecipeTestApi): + @recipe_test_api.mod_test_data + @staticmethod + def exists(*paths): + assert all(isinstance(p, Path) for p in paths) + return paths + + def __getitem__(self, name): + return Path(NamedBasePath(name))