| OLD | NEW |
| (Empty) |
| 1 # Copyright 2016 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 from recipe_engine.types import freeze | |
| 6 | |
| 7 | |
| 8 DEPS = [ | |
| 9 'path', | |
| 10 'shutil', | |
| 11 'step', | |
| 12 ] | |
| 13 | |
| 14 TEST_CONTENTS = freeze({ | |
| 15 'simple': 'abcde', | |
| 16 'spaces': 'abcde fgh', | |
| 17 'symbols': '! ~&&', | |
| 18 'multiline': '''ab | |
| 19 cd | |
| 20 efg | |
| 21 ''', | |
| 22 }) | |
| 23 | |
| 24 | |
| 25 def RunSteps(api): | |
| 26 # remove demo. | |
| 27 api.shutil.remove('foo', 'bar') | |
| 28 | |
| 29 # listdir demo. | |
| 30 result = api.shutil.listdir('fake dir', '/fake/dir') | |
| 31 for element in result: | |
| 32 api.step('manipulate %s' % str(element), ['some', 'command']) | |
| 33 | |
| 34 # mkdtemp demo. | |
| 35 for prefix in ('prefix_a', 'prefix_b'): | |
| 36 # Create temp dir. | |
| 37 temp_dir = api.path.mkdtemp(prefix) | |
| 38 assert api.path.exists(temp_dir) | |
| 39 # Make |temp_dir| surface in expectation files. | |
| 40 api.step('print %s' % prefix, ['echo', temp_dir]) | |
| 41 | |
| 42 for name, content in TEST_CONTENTS.iteritems(): | |
| 43 api.shutil.write('write_%s' % name, 'tmp_file.txt', content) | |
| 44 actual_content = api.shutil.read( | |
| 45 'read_%s' % name, 'tmp_file.txt', | |
| 46 test_data=content | |
| 47 ) | |
| 48 msg = 'expected %s but got %s' % (content, actual_content) | |
| 49 assert actual_content == content, msg | |
| 50 | |
| 51 try: | |
| 52 # copytree | |
| 53 content = 'some file content' | |
| 54 tmp_dir = api.path['tmp_base'].join('copytree_example_tmp') | |
| 55 api.shutil.makedirs('makedirs', tmp_dir) | |
| 56 path = tmp_dir.join('dummy_file') | |
| 57 api.shutil.write('write %s' % path, path, content) | |
| 58 new_tmp = api.path['tmp_base'].join('copytree_example_tmp2') | |
| 59 new_path = new_tmp.join('dummy_file') | |
| 60 api.shutil.copytree('copytree', tmp_dir, new_tmp) | |
| 61 actual_content = api.shutil.read('read %s' % new_path, new_path, | |
| 62 test_data=content) | |
| 63 assert actual_content == content | |
| 64 | |
| 65 # glob. | |
| 66 files = api.shutil.glob( | |
| 67 'glob', tmp_dir.join('*'), | |
| 68 test_data=[tmp_dir.join('dummy_file')]) | |
| 69 assert files == [str(tmp_dir.join('dummy_file'))], files | |
| 70 | |
| 71 finally: | |
| 72 api.shutil.rmtree(tmp_dir, name='cleanup') | |
| 73 api.shutil.rmtree(new_tmp, name='cleanup2') | |
| 74 | |
| 75 | |
| 76 def GenTests(api): | |
| 77 yield api.test('basic') | |
| OLD | NEW |