Exemplo n.º 1
0
  def test_brokenTempValue(self, get_devices, get_battery):
    self.file_contents['/sys/class/thermal/thermal_zone0/temp'] = 'n0t a numb3r'
    get_devices.return_value = [self.presentation.device]
    get_battery.return_value = self.battery

    expected_status_no_temp = self.expected_status.copy()
    expected_status_no_temp['device_cereal'].pop('temp')

    status = device_monitor.get_all_status(None)
    self.assertEquals(self.expected_status, status['devices'])
  def test_brokenTempValue(self, get_devices, get_battery):
    self.file_contents['/sys/class/thermal/thermal_zone0/temp'] = 'n0t a numb3r'
    get_devices.return_value = [self.device]
    get_battery.return_value = self.battery

    expected_status_no_temp = self.expected_status.copy()
    expected_status_no_temp['device_cereal'].pop('temp')

    status = device_monitor.get_all_status(None)
    self.assertEquals(self.expected_status, status['devices'])
Exemplo n.º 3
0
    def test_getStatsNoPs(self, get_devices, get_battery):
        get_devices.return_value = [self.device]
        get_battery.return_value = self.battery
        del self.cmd_outputs['ps']  # Throw exception on run shell ps command.

        # Should be same status dict but without process stats.
        expected_status_no_ps = self.expected_status.copy()
        expected_status_no_ps['device_cereal'].pop('processes')

        status = device_monitor.get_all_status(None)
        self.assertEquals(expected_status_no_ps, status['devices'])
  def test_getStatsNoSensors(self, get_devices, get_battery):
    get_devices.return_value = [self.device]
    get_battery.return_value = self.battery
    del self.cmd_outputs['grep']  # Throw exception on run shell grep command.

    # Should be same status dict but without temp stats.
    expected_status_no_temp = self.expected_status.copy()
    expected_status_no_temp['device_cereal'].pop('temp')

    status = device_monitor.get_all_status(None)
    self.assertEquals(expected_status_no_temp, status['devices'])
  def test_getStatsNoPs(self, get_devices, get_battery):
    get_devices.return_value = [self.device]
    get_battery.return_value = self.battery
    del self.cmd_outputs['ps']  # Throw exception on run shell ps command.

    # Should be same status dict but without process stats.
    expected_status_no_ps = self.expected_status.copy()
    expected_status_no_ps['device_cereal'].pop('processes')

    status = device_monitor.get_all_status(None)
    self.assertEquals(expected_status_no_ps, status['devices'])
Exemplo n.º 6
0
  def test_getStatsNoSensors(self, get_devices, get_battery):
    get_devices.return_value = [self.presentation.device]
    get_battery.return_value = self.battery
    del self.cmd_outputs['grep']  # Throw exception on run shell grep command.

    # Should be same status dict but without temp stats.
    expected_status_no_temp = self.expected_status.copy()
    expected_status_no_temp['device_cereal'].pop('temp')

    status = device_monitor.get_all_status(None)
    self.assertEquals(expected_status_no_temp, status['devices'])
Exemplo n.º 7
0
    def test_getStatsNoPs(self, get_devices, get_battery):
        get_devices.return_value = [self.device]
        get_battery.return_value = self.battery
        # Throw exception when listing processes.
        self.device.ListProcesses.side_effect = device_errors.AdbCommandFailedError(
            ['ps'], 'something failed', 1)

        # Should be same status dict but without process stats.
        expected_status_no_ps = self.expected_status.copy()
        expected_status_no_ps['device_cereal'].pop('processes')

        status = device_monitor.get_all_status(None)
        self.assertEquals(expected_status_no_ps, status['devices'])
  def test_getStatsWithBlacklist(self, get_devices, get_battery):
    get_devices.return_value = [self.device]
    get_battery.return_value = self.battery
    blacklist = mock.Mock()
    blacklist.Read = mock.MagicMock(
        return_value={'bad_device': {'reason': 'offline'}})

    # Should be same status dict but with extra blacklisted device.
    expected_status = self.expected_status.copy()
    expected_status['bad_device'] = {'state': 'offline'}

    status = device_monitor.get_all_status(blacklist)
    self.assertEquals(expected_status, status['devices'])
  def test_getStatsNoPs(self, get_devices, get_battery):
    get_devices.return_value = [self.device]
    get_battery.return_value = self.battery
    # Throw exception when listing processes.
    self.device.ListProcesses.side_effect = device_errors.AdbCommandFailedError(
        ['ps'], 'something failed', 1)

    # Should be same status dict but without process stats.
    expected_status_no_ps = self.expected_status.copy()
    expected_status_no_ps['device_cereal'].pop('processes')

    status = device_monitor.get_all_status(None)
    self.assertEquals(expected_status_no_ps, status['devices'])
Exemplo n.º 10
0
  def test_getStatsWithBlacklist(self, get_devices, get_battery):
    get_devices.return_value = [self.presentation.device]
    get_battery.return_value = self.battery
    blacklist = mock.Mock()
    blacklist.Read = mock.MagicMock(
        return_value={'bad_device': {'reason': 'offline'}})

    # Should be same status dict but with extra blacklisted presentation.device.
    expected_status = self.expected_status.copy()
    expected_status['bad_device'] = {'state': 'offline'}

    status = device_monitor.get_all_status(blacklist)
    self.assertEquals(expected_status, status['devices'])
Exemplo n.º 11
0
  def test_getStatsNoBattery(self, get_devices, get_battery):
    get_devices.return_value = [self.device]
    get_battery.return_value = self.battery
    broken_battery_info = mock.Mock()
    broken_battery_info.GetBatteryInfo = mock.MagicMock(
        return_value={'level': '-1', 'temperature': 'not_a_number'})
    get_battery.return_value = broken_battery_info

    # Should be same status dict but without battery stats.
    expected_status_no_battery = self.expected_status.copy()
    expected_status_no_battery['device_cereal'].pop('battery')

    status = device_monitor.get_all_status(None)
    self.assertEquals(expected_status_no_battery, status['devices'])
Exemplo n.º 12
0
  def test_getStatsNoBattery(self, get_devices, get_battery):
    get_devices.return_value = [self.presentation.device]
    get_battery.return_value = self.battery
    broken_battery_info = mock.Mock()
    broken_battery_info.GetBatteryInfo = mock.MagicMock(
        return_value={'level': '-1', 'temperature': 'not_a_number'})
    get_battery.return_value = broken_battery_info

    # Should be same status dict but without battery stats.
    expected_status_no_battery = self.expected_status.copy()
    expected_status_no_battery['device_cereal'].pop('battery')

    status = device_monitor.get_all_status(None)
    self.assertEquals(expected_status_no_battery, status['devices'])
Exemplo n.º 13
0
  def test_getStatsNoSensors(self, get_devices, get_battery):
    get_devices.return_value = [self.device]
    get_battery.return_value = self.battery
    def _throw_on_grep(cmd):
      if cmd.startswith('grep'):
        raise device_errors.AdbShellCommandFailedError(cmd, None, None)
      else:
        return []
    self.device.RunShellCommand = mock.MagicMock(
        side_effect=lambda cmd, **kwargs:
            _throw_on_grep(cmd) + self.cmd_outputs[cmd.split()[0]])

    # Should be same status dict but without temp stats.
    expected_status_no_temp = self.expected_status.copy()
    expected_status_no_temp['device_cereal'].pop('temp')

    status = device_monitor.get_all_status(None)
    self.assertEquals(expected_status_no_temp, status['devices'])
Exemplo n.º 14
0
    def test_getStatsNoSensors(self, get_devices, get_battery):
        get_devices.return_value = [self.device]
        get_battery.return_value = self.battery

        def _throw_on_grep(cmd):
            if cmd.startswith('grep'):
                raise device_errors.AdbShellCommandFailedError(cmd, None, None)
            else:
                return []

        self.device.RunShellCommand = mock.MagicMock(
            side_effect=lambda cmd, **kwargs: _throw_on_grep(
                cmd) + self.cmd_outputs[cmd.split()[0]])

        # Should be same status dict but without temp stats.
        expected_status_no_temp = self.expected_status.copy()
        expected_status_no_temp['device_cereal'].pop('temp')

        status = device_monitor.get_all_status(None)
        self.assertEquals(expected_status_no_temp, status['devices'])
Exemplo n.º 15
0
    def test_getStats(self, get_devices, get_battery):
        get_devices.return_value = [self.device]
        get_battery.return_value = self.battery

        status = device_monitor.get_all_status(None)
        self.assertEquals(self.expected_status, status['devices'])
Exemplo n.º 16
0
  def test_getStats(self, get_devices, get_battery):
    get_devices.return_value = [self.device]
    get_battery.return_value = self.battery

    status = device_monitor.get_all_status(None)
    self.assertEquals(self.expected_status, status['devices'])