| OLD | NEW |
| (Empty) |
| 1 # Copyright 2014 The LUCI Authors. All rights reserved. | |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | |
| 3 # that can be found in the LICENSE file. | |
| 4 | |
| 5 DEPS = [ | |
| 6 'path', | |
| 7 'platform', | |
| 8 'properties', | |
| 9 'step', | |
| 10 ] | |
| 11 | |
| 12 from recipe_engine.config_types import Path | |
| 13 | |
| 14 def RunSteps(api): | |
| 15 api.step('step1', ['/bin/echo', str(api.path['tmp_base'].join('foo'))]) | |
| 16 | |
| 17 # module.resource(...) demo. | |
| 18 api.step('print resource', | |
| 19 ['echo', api.path.resource('dir', 'file.py')]) | |
| 20 | |
| 21 # module.package_repo_resource() demo. | |
| 22 api.step('print package dir', | |
| 23 ['echo', api.path.package_repo_resource('dir', 'file.py')]) | |
| 24 | |
| 25 assert 'checkout' not in api.path | |
| 26 api.path['checkout'] = api.path['tmp_base'].join('checkout') | |
| 27 assert 'checkout' in api.path | |
| 28 | |
| 29 # Global dynamic paths (see config.py example for declaration): | |
| 30 dynamic_path = api.path['checkout'].join('jerky') | |
| 31 api.step('checkout path', ['/bin/echo', dynamic_path]) | |
| 32 | |
| 33 # Methods from python os.path are available via api.path. | |
| 34 # For testing, we asserted that this file existed in the test description | |
| 35 # below. | |
| 36 assert api.path.exists(api.path['tmp_base']) | |
| 37 | |
| 38 temp_dir = api.path.mkdtemp('kawaab') | |
| 39 assert api.path.exists(temp_dir) | |
| 40 | |
| 41 file_path = api.path['tmp_base'].join('new_file') | |
| 42 abspath = api.path.abspath(file_path) | |
| 43 api.path.assert_absolute(abspath) | |
| 44 | |
| 45 api.step('touch me', ['touch', api.path.abspath(file_path)]) | |
| 46 # Assert for testing that a file exists. | |
| 47 api.path.mock_add_paths(file_path) | |
| 48 assert api.path.exists(file_path) | |
| 49 | |
| 50 realpath = api.path.realpath(file_path) | |
| 51 assert api.path.exists(realpath) | |
| 52 | |
| 53 home_path = api.path.join(api.path.expanduser('~'), 'file') | |
| 54 api.step('touch my home', ['touch', home_path]) | |
| 55 api.path.mock_add_paths(home_path) | |
| 56 assert api.path.exists(home_path) | |
| 57 | |
| 58 # Convert strings to Paths | |
| 59 paths_to_convert = [ | |
| 60 api.path['start_dir'].join('some', 'thing'), | |
| 61 api.path['start_dir'], | |
| 62 api.path.resource("module_resource.py"), | |
| 63 api.path.resource(), | |
| 64 api.resource("recipe_resource.py"), | |
| 65 api.resource(), | |
| 66 ] | |
| 67 for p in paths_to_convert: | |
| 68 after = api.path.abs_to_path(str(p)) | |
| 69 api.step('converted path %s' % p, ['echo', after]) | |
| 70 assert after == p, (after, p) | |
| 71 | |
| 72 try: | |
| 73 api.path.abs_to_path('non/../absolute') | |
| 74 assert False, "this should have thrown" # pragma: no cover | |
| 75 except ValueError as ex: | |
| 76 assert "is not absolute" in ex.message, ex | |
| 77 | |
| 78 try: | |
| 79 if api.platform.is_win: | |
| 80 api.path.abs_to_path('C:\some\other\root\non\absolute') | |
| 81 else: | |
| 82 api.path.abs_to_path('/some/other/root/non/absolute') | |
| 83 assert False, "this should have thrown" # pragma: no cover | |
| 84 except ValueError as ex: | |
| 85 assert "could not figure out" in ex.message, ex | |
| 86 | |
| 87 | |
| 88 def GenTests(api): | |
| 89 for platform in ('linux', 'win', 'mac'): | |
| 90 yield (api.test(platform) + api.platform.name(platform) + | |
| 91 # Test when a file already exists | |
| 92 api.path.exists(api.path['tmp_base'])) | |
| 93 | |
| 94 # We have support for chromium swarming built in to the engine for some | |
| 95 # reason. TODO(phajdan.jr) remove it. | |
| 96 yield (api.test('%s_swarming' % platform) + | |
| 97 api.platform.name(platform) + | |
| 98 api.properties(path_config='swarming') + | |
| 99 api.path.exists(api.path['tmp_base'])) | |
| 100 | |
| 101 yield (api.test('%s_kitchen' % platform) + | |
| 102 api.platform.name(platform) + | |
| 103 api.properties(path_config='kitchen') + | |
| 104 api.path.exists(api.path['tmp_base'])) | |
| 105 | |
| 106 yield (api.test('%s_luci' % platform) + | |
| 107 api.platform.name(platform) + | |
| 108 api.properties(**{ | |
| 109 '$recipe_engine/path': { | |
| 110 'cache_dir': '/c', | |
| 111 'temp_dir': '/t' | |
| 112 }, | |
| 113 }) + | |
| 114 api.path.exists(api.path['tmp_base'])) | |
| OLD | NEW |