Changeset 179788 in webkit


Ignore:
Timestamp:
Feb 7, 2015 4:44:06 PM (9 years ago)
Author:
ddkilzer@apple.com
Message:

[iOS] Make Simulator class testable
<http://webkit.org/b/141358>

Rubber-stamped by Darin Adler.

  • Scripts/webkitpy/common/system/platforminfo.py:

(PlatformInfo.xcode_simctl_list): Move xcrun simctl list
command to here from Simulator.refresh() in xcode/simulator.py
so that the output of the command can be mocked.

  • Scripts/webkitpy/common/system/platforminfo_mock.py:

(MockPlatformInfo.init): Set self.expected_xcode_simctl_list
to None.
(MockPlatformInfo.xcode_simctl_list): Add method that returns
self.expected_xcode_simctl_list expectation.

  • Scripts/webkitpy/xcode/simulator.py: Add missing copyright

and license header.
(Simulator.init): Add optional 'host' parameter to make it
possible to pass in a mock object for testing. Set self._host
to 'host' parameter or create Host() object.
(Simulator.refresh): Call new PlatformInfo.xcode_simctl_list()
method.

  • Scripts/webkitpy/xcode/simulator_unittest.py: Add unit test

for current code.
(SimulatorTest):
(SimulatorTest.setUp):
(SimulatorTest._set_expected_xcrun_simctl_list):
(SimulatorTest.test_simulator_device_types):
(test_invalid_device_types_header):
(test_invalid_runtimes_header):
(test_invalid_devices_header):

Location:
trunk/Tools
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r179778 r179788  
     12015-02-07  David Kilzer  <ddkilzer@apple.com>
     2
     3        [iOS] Make Simulator class testable
     4        <http://webkit.org/b/141358>
     5
     6        Rubber-stamped by Darin Adler.
     7
     8        * Scripts/webkitpy/common/system/platforminfo.py:
     9        (PlatformInfo.xcode_simctl_list): Move `xcrun simctl list`
     10        command to here from Simulator.refresh() in xcode/simulator.py
     11        so that the output of the command can be mocked.
     12
     13        * Scripts/webkitpy/common/system/platforminfo_mock.py:
     14        (MockPlatformInfo.__init__): Set self.expected_xcode_simctl_list
     15        to None.
     16        (MockPlatformInfo.xcode_simctl_list): Add method that returns
     17        self.expected_xcode_simctl_list expectation.
     18
     19        * Scripts/webkitpy/xcode/simulator.py: Add missing copyright
     20        and license header.
     21        (Simulator.__init__): Add optional 'host' parameter to make it
     22        possible to pass in a mock object for testing.  Set self._host
     23        to 'host' parameter or create Host() object.
     24        (Simulator.refresh): Call new PlatformInfo.xcode_simctl_list()
     25        method.
     26
     27        * Scripts/webkitpy/xcode/simulator_unittest.py: Add unit test
     28        for current code.
     29        (SimulatorTest):
     30        (SimulatorTest.setUp):
     31        (SimulatorTest._set_expected_xcrun_simctl_list):
     32        (SimulatorTest.test_simulator_device_types):
     33        (test_invalid_device_types_header):
     34        (test_invalid_runtimes_header):
     35        (test_invalid_devices_header):
     36
    1372015-02-07  Csaba Osztrogonác  <ossy@webkit.org>
    238
  • trunk/Tools/Scripts/webkitpy/common/system/platforminfo.py

    r179622 r179788  
    126126        return ''
    127127
     128    def xcode_simctl_list(self):
     129        if not self.is_mac():
     130            return ()
     131        output = self._executive.run_command(['xcrun', 'simctl', 'list'], return_stderr=False)
     132        return (line for line in output.splitlines())
     133
    128134    def _determine_os_name(self, sys_platform):
    129135        if sys_platform == 'darwin':
  • trunk/Tools/Scripts/webkitpy/common/system/platforminfo_mock.py

    r179622 r179788  
    3232        self.os_name = os_name
    3333        self.os_version = os_version
     34        self.expected_xcode_simctl_list = None
    3435
    3536    def is_mac(self):
     
    5960    def xcode_sdk_version(self, sdk_name):
    6061        return '8.1'
     62
     63    def xcode_simctl_list(self):
     64        return self.expected_xcode_simctl_list
  • trunk/Tools/Scripts/webkitpy/xcode/simulator.py

    r179716 r179788  
     1# Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
     2#
     3# Redistribution and use in source and binary forms, with or without
     4# modification, are permitted provided that the following conditions
     5# are met:
     6# 1.  Redistributions of source code must retain the above copyright
     7#     notice, this list of conditions and the following disclaimer.
     8# 2.  Redistributions in binary form must reproduce the above copyright
     9#     notice, this list of conditions and the following disclaimer in the
     10#     documentation and/or other materials provided with the distribution.
     11#
     12# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
     13# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     14# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     15# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     16# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     17# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     18# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     19# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     20# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     21# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     22
    123import itertools
    224import logging
     
    628import subprocess
    729import time
     30
     31from webkitpy.common.host import Host
    832
    933_log = logging.getLogger(__name__)
     
    217241        '\s*(?P<name>[^(]+ )\((?P<udid>[^)]+)\) \((?P<state>[^)]+)\)( \((?P<availability>[^)]+)\))?')
    218242
    219     def __init__(self):
     243    def __init__(self, host=None):
     244        self._host = host or Host()
    220245        self.runtimes = []
    221246        self.device_types = []
     
    252277        Refresh runtime and device type information from ``simctl list``.
    253278        """
    254         command = ['xcrun', 'simctl', 'list']
    255         simctl_p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    256         stdout, stderr = simctl_p.communicate()
    257         if simctl_p.returncode != 0:
    258             raise RuntimeError(
    259                 '{command} failed:\n{stdout}\n{stderr}'.format(command=' '.join(command), stdout=stdout, stderr=stderr))
    260 
    261         lines = (line for line in stdout.splitlines())
     279        lines = self._host.platform.xcode_simctl_list()
    262280        device_types_header = next(lines)
    263281        if device_types_header != '== Device Types ==':
Note: See TracChangeset for help on using the changeset viewer.