def setUp(self):
     self._finder_options = browser_options.BrowserFinderOptions()
     self._finder_options.chrome_root = '../../../'
     self._finder_stubs = system_stub.Override(desktop_browser_finder,
                                               ['os', 'subprocess', 'sys'])
     self._path_stubs = system_stub.Override(desktop_browser_finder.path,
                                             ['os', 'sys'])
    def testUpdateAndCheckArchives(self):
        usr_stub = system_stub.Override(user_story_runner, ['cloud_storage'])
        wpr_stub = system_stub.Override(archive_info, ['cloud_storage'])
        try:
            uss = user_story_set.UserStorySet()
            uss.AddUserStory(
                page_module.Page('http://www.testurl.com', uss, uss.base_dir))
            # Page set missing archive_data_file.
            self.assertRaises(user_story_runner.ArchiveError,
                              user_story_runner._UpdateAndCheckArchives,
                              uss.archive_data_file, uss.wpr_archive_info,
                              uss.user_stories)

            uss = user_story_set.UserStorySet(
                archive_data_file='missing_archive_data_file.json')
            uss.AddUserStory(
                page_module.Page('http://www.testurl.com', uss, uss.base_dir))
            # Page set missing json file specified in archive_data_file.
            self.assertRaises(user_story_runner.ArchiveError,
                              user_story_runner._UpdateAndCheckArchives,
                              uss.archive_data_file, uss.wpr_archive_info,
                              uss.user_stories)

            uss = user_story_set.UserStorySet(
                archive_data_file='../../unittest_data/archive_files/test.json',
                cloud_storage_bucket=cloud_storage.PUBLIC_BUCKET)
            uss.AddUserStory(
                page_module.Page('http://www.testurl.com', uss, uss.base_dir))
            # Page set with valid archive_data_file.
            self.assertTrue(
                user_story_runner._UpdateAndCheckArchives(
                    uss.archive_data_file, uss.wpr_archive_info,
                    uss.user_stories))
            uss.AddUserStory(
                page_module.Page('http://www.google.com', uss, uss.base_dir))
            # Page set with an archive_data_file which exists but is missing a page.
            self.assertRaises(user_story_runner.ArchiveError,
                              user_story_runner._UpdateAndCheckArchives,
                              uss.archive_data_file, uss.wpr_archive_info,
                              uss.user_stories)

            uss = user_story_set.UserStorySet(
                archive_data_file=
                '../../unittest_data/test_missing_wpr_file.json',
                cloud_storage_bucket=cloud_storage.PUBLIC_BUCKET)
            uss.AddUserStory(
                page_module.Page('http://www.testurl.com', uss, uss.base_dir))
            uss.AddUserStory(
                page_module.Page('http://www.google.com', uss, uss.base_dir))
            # Page set with an archive_data_file which exists and contains all pages
            # but fails to find a wpr file.
            self.assertRaises(user_story_runner.ArchiveError,
                              user_story_runner._UpdateAndCheckArchives,
                              uss.archive_data_file, uss.wpr_archive_info,
                              uss.user_stories)
        finally:
            usr_stub.Restore()
            wpr_stub.Restore()
 def setUp(self):
     self._stubs = system_stub.Override(
         android_browser_finder,
         ['adb_commands', 'os', 'subprocess', 'logging'])
     self._android_device_stub = system_stub.Override(
         android_device, ['adb_commands'])
     self._apb_stub = system_stub.Override(android_platform_backend,
                                           ['adb_commands'])
     self._actual_ps_util = android_browser_finder.psutil
     android_browser_finder.psutil = None
Example #4
0
  def setUp(self):
    self.page_set = page_set.PageSet(file_path=os.path.dirname(__file__))
    self.page_set.AddPageWithDefaultRunNavigate('http://www.bar.com/')
    self.page_set.AddPageWithDefaultRunNavigate('http://www.baz.com/')
    self.page_set.AddPageWithDefaultRunNavigate('http://www.foo.com/')

    self._cloud_storage_stub = system_stub.Override(trace, ['cloud_storage'])
Example #5
0
 def testGetIfChanged(self):
   stubs = system_stub.Override(cloud_storage, ['os', 'open'])
   stubs.open.files[_FakeFindGsutil()] = ''
   orig_get = cloud_storage.Get
   orig_read_hash = cloud_storage.ReadHash
   orig_calculate_hash = cloud_storage.CalculateHash
   cloud_storage.ReadHash = _FakeReadHash
   cloud_storage.CalculateHash = _FakeCalulateHashMatchesRead
   file_path = 'test-file-path.wpr'
   hash_path = file_path + '.sha1'
   try:
     cloud_storage.Get = self._FakeGet
     # hash_path doesn't exist.
     self.assertFalse(cloud_storage.GetIfChanged(file_path,
                                                 cloud_storage.PUBLIC_BUCKET))
     # hash_path exists, but file_path doesn't.
     stubs.os.path.files.append(hash_path)
     self.assertTrue(cloud_storage.GetIfChanged(file_path,
                                                cloud_storage.PUBLIC_BUCKET))
     # hash_path and file_path exist, and have same hash.
     stubs.os.path.files.append(file_path)
     self.assertFalse(cloud_storage.GetIfChanged(file_path,
                                                 cloud_storage.PUBLIC_BUCKET))
     # hash_path and file_path exist, and have different hashes.
     cloud_storage.CalculateHash = _FakeCalulateHashNewHash
     self.assertTrue(cloud_storage.GetIfChanged(file_path,
                                                cloud_storage.PUBLIC_BUCKET))
   finally:
     stubs.Restore()
     cloud_storage.Get = orig_get
     cloud_storage.CalculateHash = orig_calculate_hash
     cloud_storage.ReadHash = orig_read_hash
    def testGetFilesInDirectoryIfChanged(self):
        stubs = system_stub.Override(cloud_storage, ['os'])
        stubs.os._directory = {
            'dir1': ['1file1.sha1', '1file2.txt', '1file3.sha1'],
            'dir2': ['2file.txt'],
            'dir3': ['3file1.sha1']
        }
        stubs.os.path.dirs = ['real_dir_path']

        def IncrementFilesUpdated(*_):
            IncrementFilesUpdated.files_updated += 1

        IncrementFilesUpdated.files_updated = 0
        orig_get_if_changed = cloud_storage.GetIfChanged
        cloud_storage.GetIfChanged = IncrementFilesUpdated
        try:
            self.assertRaises(ValueError,
                              cloud_storage.GetFilesInDirectoryIfChanged,
                              os.path.abspath(os.sep),
                              cloud_storage.PUBLIC_BUCKET)
            self.assertEqual(0, IncrementFilesUpdated.files_updated)
            self.assertRaises(ValueError,
                              cloud_storage.GetFilesInDirectoryIfChanged,
                              'fake_dir_path', cloud_storage.PUBLIC_BUCKET)
            self.assertEqual(0, IncrementFilesUpdated.files_updated)
            cloud_storage.GetFilesInDirectoryIfChanged(
                'real_dir_path', cloud_storage.PUBLIC_BUCKET)
            self.assertEqual(3, IncrementFilesUpdated.files_updated)
        finally:
            cloud_storage.GetIfChanged = orig_get_if_changed
            stubs.Restore()
Example #7
0
 def setUp(self):
     self.log_output = StringIO.StringIO()
     self.stream_handler = logging.StreamHandler(self.log_output)
     logging.getLogger().addHandler(self.stream_handler)
     self._real_subprocess = trybot_browser_finder.subprocess
     self._real_urllib2 = trybot_browser_finder.urllib2
     self._stubs = system_stub.Override(trybot_browser_finder,
                                        ['sys', 'open', 'os'])
Example #8
0
 def setUp(self):
   self._options = options_for_unittests.GetCopy()
   self._stubs = system_stub.Override(
       android_platform_backend,
       ['perf_control', 'adb_commands'])
   self.battery_patcher = mock.patch.object(battery_utils, 'BatteryUtils')
   self.battery_patcher.start()
   self._actual_ps_util = android_platform_backend.psutil
    def setUp(self):
        self._options = options_for_unittests.GetCopy()
        self._stubs = system_stub.Override(android_platform_backend, [
            'perf_control', 'thermal_throttle', 'adb_commands', 'certutils',
            'adb_install_cert'
        ])

        # Skip _FixPossibleAdbInstability by setting psutil to None.
        self._actual_ps_util = android_platform_backend.psutil
        android_platform_backend.psutil = None
 def testOpenRestoresCorrectly(self):
     file_path = os.path.realpath(__file__)
     stubs = system_stub.Override(system_stub_test_module, ['open'])
     stubs.open.files = {file_path: 'contents'}
     f = system_stub_test_module.SystemStubTest.TestOpen(file_path)
     self.assertEqual(type(f), system_stub.OpenFunctionStub.FileStub)
     stubs.open.files = {}
     stubs.Restore()
     # This will throw an error if the open stub wasn't restored correctly.
     f = system_stub_test_module.SystemStubTest.TestOpen(file_path)
     self.assertEqual(type(f), file)
Example #11
0
 def setUp(self):
     self._options = options_for_unittests.GetCopy()
     self._stubs = system_stub.Override(android_platform_backend,
                                        ['perf_control', 'adb_commands'])
     self.battery_patcher = mock.patch.object(battery_utils, 'BatteryUtils')
     self.battery_patcher.start()
     self._actual_ps_util = android_platform_backend.psutil
     self.setup_prebuilt_tool_patcher = mock.patch(
         'telemetry.core.platform.android_platform_backend._SetupPrebuiltTools'
     )
     m = self.setup_prebuilt_tool_patcher.start()
     m.return_value = True
Example #12
0
    def setUp(self):
        ps = page_set.PageSet(file_path=os.path.dirname(__file__))
        ps.AddUserStory(
            page_module.Page('http://www.bar.com/', ps, ps.base_dir))
        ps.AddUserStory(
            page_module.Page('http://www.baz.com/', ps, ps.base_dir))
        ps.AddUserStory(
            page_module.Page('http://www.foo.com/', ps, ps.base_dir))
        self.page_set = ps

        self._cloud_storage_stub = system_stub.Override(
            trace, ['cloud_storage'])
 def testExistsReturnsFalse(self):
     stubs = system_stub.Override(cloud_storage, ['subprocess'])
     orig_find_gs_util = cloud_storage.FindGsutil
     try:
         stubs.subprocess.Popen.communicate_result = (
             '', 'CommandException: One or more URLs matched no objects.\n')
         stubs.subprocess.Popen.returncode_result = 1
         cloud_storage.FindGsutil = _FakeFindGsutil
         self.assertFalse(
             cloud_storage.Exists('fake bucket', 'fake remote path'))
     finally:
         stubs.Restore()
         cloud_storage.FindGsutil = orig_find_gs_util
Example #14
0
 def _assertRunCommandRaisesError(self, communicate_strs, error):
   stubs = system_stub.Override(cloud_storage, ['open', 'subprocess'])
   orig_find_gs_util = cloud_storage.FindGsutil
   cloud_storage.FindGsutil = _FakeFindGsutil
   stubs.open.files = {'fake gsutil path':''}
   stubs.subprocess.Popen.returncode_result = 1
   try:
     for string in communicate_strs:
       stubs.subprocess.Popen.communicate_result = ('', string)
       self.assertRaises(error, cloud_storage._RunCommand, [])
   finally:
     stubs.Restore()
     cloud_storage.FindGsutil = orig_find_gs_util
Example #15
0
    def setUp(self):
        self._options = options_for_unittests.GetCopy()
        self._stubs = system_stub.Override(android_platform_backend, [
            'perf_control', 'thermal_throttle', 'adb_commands', 'certutils',
            'adb_install_cert', 'platformsettings'
        ])

        # Skip _FixPossibleAdbInstability by setting psutil to None.
        self._actual_ps_util = android_platform_backend.psutil
        android_platform_backend.psutil = None
        self.battery_patcher = mock.patch.object(battery_utils, 'BatteryUtils')
        self.battery_patcher.start()
        self.setup_prebuilt_tool_patcher = mock.patch(
            'telemetry.core.platform.android_platform_backend._SetupPrebuiltTools'
        )
        m = self.setup_prebuilt_tool_patcher.start()
        m.return_value = True
  def setUp(self):
    self.tmp_dir = tempfile.mkdtemp()
    # Write the metadata.
    self.user_story_set_archive_info_file = os.path.join(
        self.tmp_dir, 'info.json')
    with open(self.user_story_set_archive_info_file, 'w') as f:
      f.write(archive_info_contents)

    # Write the existing .wpr files.
    for i in [1, 2]:
      with open(os.path.join(self.tmp_dir, ('data_00%d.wpr' % i)), 'w') as f:
        f.write(archive_info_contents)

    # Create the PageSetArchiveInfo object to be tested.
    self.archive_info = archive_info.WprArchiveInfo.FromFile(
        self.user_story_set_archive_info_file, cloud_storage.PUBLIC_BUCKET)
    # Use cloud_storage system stub.
    self.overrides = system_stub.Override(archive_info, ['cloud_storage'])
Example #17
0
 def testDownloadArchivesIfNeeded(self):
     overrides = system_stub.Override(archive_info, ['cloud_storage'])
     try:
         cloud_storage_stub = overrides.cloud_storage
         # Second hash doesn't match, need to fetch it.
         cloud_storage_stub.SetRemotePathsForTesting({
             cloud_storage.PUBLIC_BUCKET: {
                 recording1: "dummyhash",
                 recording2: "dummyhash22"
             }
         })
         cloud_storage_stub.SetCalculatedHashesForTesting({
             os.path.join(self.tmp_dir, recording1):
             "dummyhash",
             os.path.join(self.tmp_dir, recording2):
             "dummyhash2",
         })
         self.archive_info.DownloadArchivesIfNeeded()
         self.assertEquals(len(cloud_storage_stub.downloaded_files), 1)
         self.assertEquals(cloud_storage_stub.downloaded_files[0],
                           recording2)
     finally:
         overrides.Restore()
  def setUp(self):
    self.finder_options = browser_options.BrowserFinderOptions()

    # Mock out what's needed for testing with exact APKs
    self._android_browser_finder_stub = system_stub.Override(
        android_browser_finder, ['adb_commands', 'os'])
 def SuppressExceptionFormatting(self):
   """Fake out exception formatter to avoid spamming the unittest stdout."""
   story_runner.exception_formatter = FakeExceptionFormatterModule
   self._story_runner_logging_stub = system_stub.Override(
     story_runner, ['logging'])
Example #20
0
 def CaptureFormattedException(self):
   exception_formatter.PrintFormattedException = CaptureStderr(
       exception_formatter.PrintFormattedException,
       self._formatted_exception_buffer)
   self._story_runner_logging_stub = system_stub.Override(
       story_runner, ['logging'])
 def SuppressExceptionFormatting(self):
     user_story_runner.exception_formatter = FakeExceptionFormatterModule
     self._user_story_runner_logging_stub = system_stub.Override(
         user_story_runner, ['logging'])
Example #22
0
 def setUp(self):
     self._android_device_stub = system_stub.Override(
         android_device, ['adb_commands'])
Example #23
0
 def setUp(self):
     self._android_device_stub = system_stub.Override(
         android_device, ['adb_commands', 'os', 'subprocess', 'logging'])
     self._apb_stub = system_stub.Override(android_platform_backend,
                                           ['adb_commands'])