class TestConfigData: def setup(self): print('Test start.') self.config = Config( '/Users/jameszhang/python/project/appCrawler/test/testdata/config/NBA_Android_config.yml' ) def teardown(self): del self.config print('Test end.') def test_get_attr_str(self): platform_name = self.config.platformName assert platform_name == 'Android' def test_get_attr_list(self): list_data = self.config.test_list for i in range(1, 4): assert list_data[i - 1] == i def test_get_attr_error(self): with pytest.raises(expected_exception=AttributeError): self.config.error_attr def test_get_appium_desired_caps(self): desired_caps = self.config.appium_desired_caps() assert desired_caps['appPackage'] == 'com.nbaimd.gametime.nba2011' assert desired_caps[ 'appActivity'] == 'com.neulion.nba.base.LaunchDispatcherActivity' def test_white_apps(self): white_apps = self.config.white_apps() assert isinstance(white_apps, Set) assert "com.nbaimd.gametime.nba2011" in white_apps
class TestAppiumUtil: def setup(self): print('Test start.') # config_path = '/Users/jameszhang/python/project/appCrawler/test/testdata/config/NBA_Android_config.yml' config_path = os.path.join(os.path.dirname(__file__), 'testdata/config', 'NBA_Android_config.yml') uid = device_info_util.get_serial_numbers_android() self.config = Config(config_path, uid[0]) def teardown(self): print('Test end.') del self.config def test_appium_init_driver(self): self.driver = Appium(self.config.appium_desired_caps()) self.driver.quit() def test_save_page_source(self): self.driver = Appium(self.config.appium_desired_caps()) time.sleep(20) page_source = self.driver.get_page_source() date = str(int(time.time())) with open('testdata/pageSource/{}.xml'.format(date), 'w', encoding='utf-8') as fp: fp.write(page_source) self.driver.quit()
def setup(self): print('test start') uid = device_info_util.get_serial_numbers_android() config_path = os.path.join(os.path.dirname(__file__), 'testdata', 'config', 'NBA_Android_config.yml') config = Config(config_path, uid[0]) screenshot = os.path.join(os.path.dirname(__file__), 'testdata\\screenshot') if not os.path.exists(screenshot): os.mkdir(screenshot) self.driver = Appium(config.appium_desired_caps())
def __init__(self): config = Config('space_window.conf', __file__) location = config.get('weather', 'location', 'United_Kingdom/England/London') self.url = 'https://www.yr.no/place/%s/forecast.xml' % location self.re_top = re.compile('<time from=.*?\/time>', re.S) self.re_desc = re.compile('<symbol number=\".*?\" name=\"(.*?)\"') self.re_temp = re.compile('<temperature unit=\".*?\" value=\"(.*?)"') #self.re_wind_dir=re.compile('<windDirection.*? code=\"(.*?)\"') self.re_wind_speed=\ re.compile('<windSpeed.*? mps=\"(.*?)\".*?name=\"(.*?)"')
def load_config(self): config = Config('space_window.conf', __file__) self._player = config.get('player', 'player', 'omxplayer') self._player_args = config.get( 'player', 'player_args', ' --timeout 60 --loop --no-osd -b').replace('-b', '') self._player_pl_args = config.get('player', 'playlist_player_args', ' --timeout 60 --no-osd -b').replace( '-b', '') self._player_cmd = self._player + ' ' + self._player_args self._player_pl_cmd = self._player + ' ' + self._player_pl_args
def load_config(self): config = Config('space_window.conf', __file__) self._delay = config.getint('nasa', 'frame_delay', 5) self._fontname = config.get('font', 'name', 'comicsansms') self._fontsize = config.getint('nasa', 'font_size', 48) self._font = pg.font.SysFont(self._fontname, self._fontsize) self._text_col = config.getcolor('nasa', 'foreground', (100, 100, 100)) self._text_height_ratio = config.getint('nasa', 'height_ratio', 10)
def __init__(self,status_update_func,screen): config = Config('space_window.conf',__file__) self._start_with=config.get('global','start_with','streams') self._current_stream=None self._resume_stream=None self._check_timer_delay=20 self._check_timer=None self._wait=False self._streams=Streams.load() self._nasa=NasaPod(screen) self._gallery=Gallery(status_update_func,screen) self._music=Music(status_update_func) self._clock=Clock(screen) self._mopidy=None self._status_update=status_update_func if not _standalone: threading.Thread(target=self.launch_mopidy).start() self._streams.set_status_func(status_update_func) self._resume_func=self.run_something
def performer(config_path, serial, timer): config = Config(config_path, udid=serial) spider = Crawler(config, timer) try: while True: spider.run() except QuitAppiumException: # return test result. return spider.report_path, spider.record log.error('test end!')
def load_config(self): config = Config('space_window.conf', __file__) self._forecol = config.getcolor('clock', 'foreground', (255, 128, 0)) bckcol = config.getcolor('clock', 'background', (32, 0, 32)) time_sz = config.getint('clock', 'time_size', 192) date_sz = config.getint('clock', 'date_size', 24) self._border = config.getint('clock', 'border', 10) self._separation = config.getint('clock', 'separation', 8) path = os.path.dirname(os.path.abspath(__file__)) fontname = os.path.join(path, 'digital-7_mono.ttf') self._time_font = pygame.font.Font(fontname, time_sz) self._secs_font = pygame.font.Font(fontname, time_sz / 3) self._date_font = pygame.font.Font(fontname, date_sz) self._black.fill(bckcol) self._init_rects() timezone = config.get('clock', 'timezone', 'NONE') if timezone != 'NONE': os.environ['TZ'] = timezone time.tzset()
def __init__(self,screen): config = Config('space_window.conf',__file__) self._border=config.getint('message','border',10) self._left=config.getbool('message','left',False) self._top=config.getbool('message','top',False) self._forecol=config.getcolor('message','foreground',(255,128,0)) bckcol=config.getcolor('message','background',(32,0,32)) fontname=config.get('font','name','comicsansms') fontsz=config.getint('message','font_size',68) self.running=False self._delay=1 self._screen=None self.text=None self.black=None self.font=None #sleep(1) self.screen = screen self.black=self.screen.copy() self.black.fill(bckcol) self.font = pg.font.SysFont(fontname, fontsz) self.lock=threading.Lock()
def screen(): global _screen if _screen is None: config = Config('space_window.conf', __file__) fbdev = config.get('pygame', 'fbdev', 'None') if fbdev != 'None': os.putenv('SDL_VIDEODRIVER', 'fbcon') os.environ["SDL_FBDEV"] = fbdev pygame_init() scrw = config.getint('pygame', 'screen_width', 0) scrh = config.getint('pygame', 'screen_height', 0) depth = config.getint('pygame', 'screen_depth', 0) if depth == 0: _screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) else: _screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN, depth) return _screen
def __init__(self, status_func=None): self._status_func = status_func self.playing = False config = Config('space_window.conf', __file__) self._player = config.get('player', 'player', _player) self._player_args = config.get('player', 'player_args', _player_args) self._player_pl_args=config.get('player','playlist_player_args',\ _player_args) self._player_cmd = self._player + ' ' + self._player_args self._player_pl_cmd = self._player + ' ' + self._player_pl_args self._player_stream_cmd = self._player_pl_cmd self._player_fbcp = '' fbdev = config.get('pygame', 'fbdev', 'None') if fbdev != 'None': self._player_fbcp = 'fbcp&' self._player_cmd = 'fbcp& ' + self._player_cmd self._player_pl_cmd = 'fbcp& ' + self._player_pl_cmd _log = logger.get(__name__)
def test_config_file_incorrect(self, path): with pytest.raises(expected_exception=Exception): Config(path)
_wpa_block_open = """ \tnetwork={ \t ssid="SSIDNAME" \t auth_alg=OPEN \t key_mgmt=NONE \t priority=10 }\n""" _wpa_header = """ ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=GB """ config = Config('space_window.conf', __file__) ap_name = config.get('access-point', 'name', 'UnusualWiFi') _ap_driver = config.get('access-point', 'driver', 'nl80211') # edimax driver is rtl871xdrv _ap_interface = config.get('access-point', 'interface', 'wlan0') ap_ip = config.get('access-point', 'ip', '192.168.4.1') _ap_iprange = config.get('access-point', 'iprange', '192.168.4.2,192.168.4.20') def _get_config_path(): return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'conf') # run a program and wait for it to finish def run(rcmd):
def load_config(self): config = Config('space_window.conf', __file__) self._delay = config.getint('gallery', 'frame_delay', 10)
def setup(self): print('Test start.') # config_path = '/Users/jameszhang/python/project/appCrawler/test/testdata/config/NBA_Android_config.yml' config_path = os.path.join(os.path.dirname(__file__), 'testdata/config', 'NBA_Android_config.yml') uid = device_info_util.get_serial_numbers_android() self.config = Config(config_path, uid[0])
import random PORT_NUMBER = 80 MOPIDY_PORT=6680 _ip=wifi.get_ip() _processes=None _streams=None _gallery=None _music=None _server=None _standalone=False _cnt=random.randint(0,1000) _log=logger.get(__name__) _config = Config('space_window.conf',__file__) def set_standalone(standalone): global _standalone _standalone=standalone procmod.set_standalone(standalone) _screen=None _msg=None def set_screen(screen): global _screen global _msg _screen = screen _msg=msg.MsgScreen(_screen) def _status_update(txt):
def setup(self): print('Test start.') self.config = Config( '/Users/jameszhang/python/project/appCrawler/test/testdata/config/NBA_Android_config.yml' )
def test_config_file_correct(self, path): Config(path)
def main(): print_spider() try: params_dict = cmd_parse() except FilePathInvalid as msg: log.error(msg) else: config_path = params_dict.get('config') # default 2 minutes. timer = int(params_dict.get('timer', 2)) # default 5 threads. max_workers = int(params_dict.get('max_workers', 5)) # default dfs travel_mode = params_dict.get('travel_mode', 'mixture') support_mode = {'mixture', 'dfs', 'bfs'} if travel_mode not in support_mode: _origin_mode = travel_mode travel_mode = support_mode.pop() log.warning( f"{_origin_mode} travel mode is not support, set travel mode to {travel_mode}" ) Crawler.travel_mode = travel_mode futures_map = dict() config = Config(config_path=config_path) devices_list = list() platform = config.platformName if platform == 'Android': devices_list = get_serial_numbers_android() elif platform == 'iOS': devices_list = get_serial_numbers_ios() else: log.error("Not support {} platform".format(platform)) if not devices_list: log.warning("Not find any device.") else: with futures.ThreadPoolExecutor(max_workers) as executor: futures_list = [] for serial in devices_list: future = executor.submit(performer, config_path, serial, timer) futures_map[future] = serial futures_list.append(future) for future in futures.as_completed(futures_list): print(futures_map.get(future)) report_dir, record = future.result() json_gene = GenerateJson(report_dir, record) json_gene.insert_crash_log() json_gene.generate_json() # generate report report = Report(report_dir=report_dir) try: report.clear_expired_report(expired_day=3) except Exception as exc: log.error(exc) finally: report.generate_report() kill_adb_server() log.warning("All test end.")