Index: gm/rebaseline_server/download_actuals_test.py |
diff --git a/gm/rebaseline_server/download_actuals_test.py b/gm/rebaseline_server/download_actuals_test.py |
index c405a3cf57a6c364503f91e04c8a1079123fc48f..88135305192dc9ec297e93577c274115e5b657c0 100755 |
--- a/gm/rebaseline_server/download_actuals_test.py |
+++ b/gm/rebaseline_server/download_actuals_test.py |
@@ -25,8 +25,6 @@ import tempfile |
import urllib |
# Imports from within Skia |
-import fix_pythonpath # must do this first |
-from pyutils import url_utils |
import base_unittest |
import download_actuals |
@@ -36,14 +34,52 @@ class DownloadTest(base_unittest.TestCase): |
def test_fetch(self): |
"""Tests fetch() of GM results from actual-results.json .""" |
downloader = download_actuals.Download( |
- actuals_base_url=url_utils.create_filepath_url( |
+ actuals_base_url=download_actuals.create_filepath_url( |
os.path.join(self._input_dir, 'gm-actuals')), |
- gm_actuals_root_url=url_utils.create_filepath_url( |
+ gm_actuals_root_url=download_actuals.create_filepath_url( |
os.path.join(self._input_dir, 'fake-gm-imagefiles'))) |
downloader.fetch( |
builder_name='Test-Android-GalaxyNexus-SGX540-Arm7-Release', |
dest_dir=self._output_dir_actual) |
+ def test_create_filepath_url(self): |
+ """Tests create_filepath_url(). """ |
+ with self.assertRaises(Exception): |
+ url_or_path.create_filepath_url('http://1.2.3.4/path') |
+ # Pass absolute filepath. |
+ self.assertEquals( |
+ download_actuals.create_filepath_url( |
+ '%sdir%sfile' % (os.path.sep, os.path.sep)), |
+ 'file:///dir/file') |
+ # Pass relative filepath. |
+ self.assertEquals( |
+ download_actuals.create_filepath_url(os.path.join('dir', 'file')), |
+ 'file://%s/dir/file' % urllib.pathname2url(os.getcwd())) |
+ |
+ def test_copy_contents(self): |
+ """Tests copy_contents(). """ |
+ contents = 'these are the contents' |
+ tempdir_path = tempfile.mkdtemp() |
+ try: |
+ source_path = os.path.join(tempdir_path, 'source') |
+ source_url = download_actuals.create_filepath_url(source_path) |
+ with open(source_path, 'w') as source_handle: |
+ source_handle.write(contents) |
+ dest_path = os.path.join(tempdir_path, 'new_subdir', 'dest') |
+ # Destination subdir does not exist, so copy_contents() should fail |
+ # if create_subdirs_if_needed is False. |
+ with self.assertRaises(Exception): |
+ download_actuals.copy_contents(source_url=source_url, |
+ dest_path=dest_path, |
+ create_subdirs_if_needed=False) |
+ # If create_subdirs_if_needed is True, it should work. |
+ download_actuals.copy_contents(source_url=source_url, |
+ dest_path=dest_path, |
+ create_subdirs_if_needed=True) |
+ self.assertEquals(open(dest_path).read(), contents) |
+ finally: |
+ shutil.rmtree(tempdir_path) |
+ |
def main(): |
base_unittest.main(DownloadTest) |