Skip to content

Commit

Permalink
Merge pull request #1140 from secretrobotron/device-absent-error-hand…
Browse files Browse the repository at this point in the history
…ling

Device absent error handling
  • Loading branch information
yimelia committed Jul 6, 2023
2 parents ae0f283 + eacfce7 commit 48733f1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
6 changes: 6 additions & 0 deletions airtest/core/error.py
Expand Up @@ -70,6 +70,12 @@ class DeviceConnectionError(BaseError):
DEVICE_CONNECTION_ERROR = r"error:\s*((device \'\S+\' not found)|(cannot connect to daemon at [\w\:\s\.]+ Connection timed out))"
pass

class NoDeviceError(BaseError):
"""
When no device is connected
"""
pass


class ICmdError(Exception):
"""
Expand Down
26 changes: 21 additions & 5 deletions airtest/core/helper.py
@@ -1,21 +1,37 @@
# -*- coding: utf-8 -*-
import time
import sys
import functools
import os
import six
import sys
import time
import traceback
from airtest.core.settings import Settings as ST
from airtest.utils.logwraper import Logwrap, AirtestLogger
from airtest.utils.logger import get_logger
from airtest.utils.logwraper import Logwrap, AirtestLogger
from airtest.core.error import NoDeviceError


class DeviceMetaProperty(type):

@property
def DEVICE(cls):
if G._DEVICE is None:
raise NoDeviceError("No devices added.")
return G._DEVICE

@DEVICE.setter
def DEVICE(self, dev):
self._DEVICE = dev
self.LOGGING.debug("Set current device to: %s" % dev)


class G(object):
class G(object, metaclass=DeviceMetaProperty):
"""Represent the globals variables"""
BASEDIR = []
LOGGER = AirtestLogger(None)
LOGGING = get_logger("airtest.core.api")
SCREEN = None
DEVICE = None
_DEVICE = None
DEVICE_LIST = []
RECENT_CAPTURE = None
RECENT_CAPTURE_PATH = None
Expand Down

0 comments on commit 48733f1

Please sign in to comment.