Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: gm/rebaseline_server/download_actuals_test.py

Issue 317783004: Revert "rebaseline_server: download actual-results.json files from GCS instead of SVN" (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/rebaseline_server/download_actuals.py ('k') | gm/rebaseline_server/fix_pythonpath.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 """ 3 """
4 Copyright 2014 Google Inc. 4 Copyright 2014 Google Inc.
5 5
6 Use of this source code is governed by a BSD-style license that can be 6 Use of this source code is governed by a BSD-style license that can be
7 found in the LICENSE file. 7 found in the LICENSE file.
8 8
9 Test download.py 9 Test download.py
10 10
11 TODO(epoger): Create a command to update the expected results (in 11 TODO(epoger): Create a command to update the expected results (in
12 self._output_dir_expected) when appropriate. For now, you should: 12 self._output_dir_expected) when appropriate. For now, you should:
13 1. examine the results in self._output_dir_actual and make sure they are ok 13 1. examine the results in self._output_dir_actual and make sure they are ok
14 2. rm -rf self._output_dir_expected 14 2. rm -rf self._output_dir_expected
15 3. mv self._output_dir_actual self._output_dir_expected 15 3. mv self._output_dir_actual self._output_dir_expected
16 Although, if you're using an SVN checkout, this will blow away .svn directories 16 Although, if you're using an SVN checkout, this will blow away .svn directories
17 within self._output_dir_expected, which wouldn't be good... 17 within self._output_dir_expected, which wouldn't be good...
18 18
19 """ 19 """
20 20
21 # System-level imports 21 # System-level imports
22 import os 22 import os
23 import shutil 23 import shutil
24 import tempfile 24 import tempfile
25 import urllib 25 import urllib
26 26
27 # Imports from within Skia 27 # Imports from within Skia
28 import fix_pythonpath # must do this first
29 from pyutils import url_utils
30 import base_unittest 28 import base_unittest
31 import download_actuals 29 import download_actuals
32 30
33 31
34 class DownloadTest(base_unittest.TestCase): 32 class DownloadTest(base_unittest.TestCase):
35 33
36 def test_fetch(self): 34 def test_fetch(self):
37 """Tests fetch() of GM results from actual-results.json .""" 35 """Tests fetch() of GM results from actual-results.json ."""
38 downloader = download_actuals.Download( 36 downloader = download_actuals.Download(
39 actuals_base_url=url_utils.create_filepath_url( 37 actuals_base_url=download_actuals.create_filepath_url(
40 os.path.join(self._input_dir, 'gm-actuals')), 38 os.path.join(self._input_dir, 'gm-actuals')),
41 gm_actuals_root_url=url_utils.create_filepath_url( 39 gm_actuals_root_url=download_actuals.create_filepath_url(
42 os.path.join(self._input_dir, 'fake-gm-imagefiles'))) 40 os.path.join(self._input_dir, 'fake-gm-imagefiles')))
43 downloader.fetch( 41 downloader.fetch(
44 builder_name='Test-Android-GalaxyNexus-SGX540-Arm7-Release', 42 builder_name='Test-Android-GalaxyNexus-SGX540-Arm7-Release',
45 dest_dir=self._output_dir_actual) 43 dest_dir=self._output_dir_actual)
46 44
45 def test_create_filepath_url(self):
46 """Tests create_filepath_url(). """
47 with self.assertRaises(Exception):
48 url_or_path.create_filepath_url('http://1.2.3.4/path')
49 # Pass absolute filepath.
50 self.assertEquals(
51 download_actuals.create_filepath_url(
52 '%sdir%sfile' % (os.path.sep, os.path.sep)),
53 'file:///dir/file')
54 # Pass relative filepath.
55 self.assertEquals(
56 download_actuals.create_filepath_url(os.path.join('dir', 'file')),
57 'file://%s/dir/file' % urllib.pathname2url(os.getcwd()))
58
59 def test_copy_contents(self):
60 """Tests copy_contents(). """
61 contents = 'these are the contents'
62 tempdir_path = tempfile.mkdtemp()
63 try:
64 source_path = os.path.join(tempdir_path, 'source')
65 source_url = download_actuals.create_filepath_url(source_path)
66 with open(source_path, 'w') as source_handle:
67 source_handle.write(contents)
68 dest_path = os.path.join(tempdir_path, 'new_subdir', 'dest')
69 # Destination subdir does not exist, so copy_contents() should fail
70 # if create_subdirs_if_needed is False.
71 with self.assertRaises(Exception):
72 download_actuals.copy_contents(source_url=source_url,
73 dest_path=dest_path,
74 create_subdirs_if_needed=False)
75 # If create_subdirs_if_needed is True, it should work.
76 download_actuals.copy_contents(source_url=source_url,
77 dest_path=dest_path,
78 create_subdirs_if_needed=True)
79 self.assertEquals(open(dest_path).read(), contents)
80 finally:
81 shutil.rmtree(tempdir_path)
82
47 83
48 def main(): 84 def main():
49 base_unittest.main(DownloadTest) 85 base_unittest.main(DownloadTest)
50 86
51 87
52 if __name__ == '__main__': 88 if __name__ == '__main__':
53 main() 89 main()
OLDNEW
« no previous file with comments | « gm/rebaseline_server/download_actuals.py ('k') | gm/rebaseline_server/fix_pythonpath.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698