Exemple #1
0
    def get_test_destinations(self,
                              runtimes: Optional[Sequence[Runtime]] = None,
                              simulator_name: Optional[re.Pattern] = None,
                              include_unavailable: bool = False,
                              json_output: bool = False,
                              should_print: bool = True) -> List[Simulator]:
        """
        List available destinations for test runs
        """

        try:
            all(r.validate() for r in (runtimes or []))
        except ValueError as ve:
            TestArgument.RUNTIMES.raise_argument_error(str(ve))

        self.logger.info(Colors.BLUE('List available test devices'))
        try:
            simulators = Simulator.list(runtimes, simulator_name, include_unavailable)
        except IOError as e:
            raise XcodeProjectException(str(e)) from e
        if not simulators:
            raise XcodeProjectException('No simulator runtimes are available')

        if should_print:
            if json_output:
                self.echo(json.dumps([s.dict() for s in simulators], indent=4))
            else:
                runtime_simulators = defaultdict(list)
                for s in simulators:
                    runtime_simulators[s.runtime].append(s)
                for runtime in sorted(runtime_simulators.keys()):
                    self.echo(Colors.GREEN('Runtime: %s'), runtime)
                    for simulator in runtime_simulators[runtime]:
                        self.echo(f'- {simulator.name}')
        return simulators
Exemple #2
0
def test_create_simulator(simulator_mock):
    runtime = Runtime('iOS 12.4')
    simulator = Simulator.create(**simulator_mock, runtime=runtime)
    assert simulator.udid == '7D9D6930-90D9-453A-BF11-63C5CA9CDA15'
    assert simulator.is_available is True
    assert simulator.state == 'Shutdown'
    assert simulator.name == 'iPad Air (3rd generation)'
    assert simulator.data_path == pathlib.Path('/path/to/simulator/data')
    assert simulator.log_path == pathlib.Path('/path/to/simulator/logs')
    assert simulator.runtime == runtime
Exemple #3
0
def test_dict_serialization(simulator_mock):
    simulator = Simulator.create(**simulator_mock, runtime=Runtime('iOS 12.4'))
    assert simulator.dict() == {
        'udid': '7D9D6930-90D9-453A-BF11-63C5CA9CDA15',
        'is_available': True,
        'state': 'Shutdown',
        'name': 'iPad Air (3rd generation)',
        'data_path': '/path/to/simulator/data',
        'log_path': '/path/to/simulator/logs',
        'runtime': 'iOS 12.4',
    }
Exemple #4
0
    def _get_test_destinations(self, requested_devices: Optional[List[str]]) -> List[Simulator]:
        if not requested_devices:
            simulators = [self.get_default_test_destination(should_print=False)]
        else:
            try:
                simulators = Simulator.find_simulators(requested_devices)
            except ValueError as ve:
                raise TestArgument.TEST_DEVICES.raise_argument_error(str(ve)) from ve

        self.echo(Colors.BLUE('Running tests on simulators:'))
        for s in simulators:
            self.echo('- %s %s (%s)', s.runtime, s.name, s.udid)
        self.echo('')
        return simulators
Exemple #5
0
    def get_default_test_destination(self,
                                     json_output: bool = False,
                                     should_print: bool = True) -> Simulator:
        """
        Show default test destination for the chosen Xcode version
        """
        xcode = Xcode.get_selected()
        if should_print:
            msg_template = 'Show default test destination for Xcode %s (%s)'
            self.logger.info(Colors.BLUE(msg_template), xcode.version, xcode.build_version)

        try:
            simulator = Simulator.get_default()
        except ValueError as error:
            raise XcodeProjectException(str(error)) from error

        if should_print:
            if json_output:
                self.echo(json.dumps(simulator.dict(), indent=4))
            else:
                self.echo(Colors.GREEN(f'{simulator.runtime} {simulator.name}'))
        return simulator
Exemple #6
0
def test_choose_simulator_not_found():
    description = 'Samsung Galaxy S20'
    with pytest.raises(ValueError) as exception_info:
        Simulator.choose_simulator(description, Simulator.list())
    assert description in str(exception_info.value)
Exemple #7
0
def test_choose_simulator(test_destination, expected_udid):
    simulator = Simulator.choose_simulator(test_destination, Simulator.list())
    assert simulator.udid == expected_udid