1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
10 import mock
# pylint: disable=F0401
12 import fetch_benchmark_deps
16 return sorted([os
.path
.normcase(p
) for p
in paths
.splitlines()])
19 class FetchBenchmarkDepsUnittest(unittest
.TestCase
):
20 """The test guards fetch_benchmark_deps.
22 It assumes the following telemetry APIs always success:
23 telemetry.wpr.archive_info.WprArchiveInfo.DownloadArchivesIfNeeded
24 catapult_base.cloud_storage.GetFilesInDirectoryIfChanged
28 """Override sys.argv as if it is called from commnad line."""
30 sys
.argv
= ['./fetch_benchmark_deps', '']
32 def _RunFetchBenchmarkDepsTest(self
, benchmark_name
,
33 expected_fetched_file_paths
= None):
34 """Simulates './fetch_benchmark_deps [benchmark_name]'
36 It checks if the paths returned are expected and have corresponding sha1
37 checksums. The expected result can be omitted if the dependencies of
38 specified benchmarks are subject to changes.
41 benchmark_name: benchmark name
42 expected_fetched_file_paths: the expected result.
44 sys
.argv
[1] = benchmark_name
45 output
= StringIO
.StringIO()
46 with mock
.patch('telemetry.wpr.archive_info.WprArchiveInfo'
47 '.DownloadArchivesIfNeeded') as mock_download
:
48 with mock
.patch('catapult_base.cloud_storage'
49 '.GetFilesInDirectoryIfChanged') as mock_get
:
50 mock_download
.return_value
= True
51 mock_get
.GetFilesInDirectoryIfChanged
.return_value
= True
52 fetch_benchmark_deps
.main(output
)
53 for f
in output
.getvalue().splitlines():
54 fullpath
= os
.path
.join(fetch_benchmark_deps
.GetChromiumDir(), f
)
55 sha1path
= fullpath
+ '.sha1'
56 self
.assertTrue(os
.path
.isfile(sha1path
))
57 if expected_fetched_file_paths
:
58 self
.assertEquals(expected_fetched_file_paths
,
59 NormPaths(output
.getvalue()))
61 def testFetchWPRs(self
):
62 self
._RunFetchBenchmarkDepsTest
('smoothness.top_25_smooth')
64 def testFetchServingDirs(self
):
65 self
._RunFetchBenchmarkDepsTest
('media.tough_video_cases')
67 def testFetchOctane(self
):
68 expected
= 'src/tools/perf/page_sets/data/octane_001.wpr'
69 self
._RunFetchBenchmarkDepsTest
('octane', NormPaths(expected
))