def update_1_row(row_values, row_idx): # get valid permutations according to the current content of the matrix row_content = data.get_row(row_idx) con_filter = tools.get_filter( row_content ) # contradiction filter - to delete all those who contradict the currently known values (row_content) unknown_row = [data.state.Unknown for x in range(data.COLUMNS)] valid_perms = get_perms( unknown_row, row_values, con_filter) # meanwhile_content starts "empty" - Unknown #find the 'agreed' values and update the matrix intersection = tools.get_intersection(valid_perms) data.set_row(intersection, row_idx) # update COLUMNS_CAN_IMPROVE and make false in this data.ROWS_HAS_CHANGE[row_idx] = False for i in range(len(row_content)): if (row_content[i] == data.state.Unknown and intersection[i] == data.state.Black) or ( row_content[i] == data.state.Unknown and intersection[i] == data.state.White): data.COLUMNS_HAS_CHANGE[i] = True # return whether there was an improvement has_improvement = False if tools.has_diff(row_content, intersection): has_improvement = True return has_improvement
def update_1_column(column_values, column_idx): # get valid permutations according to the current content of the matrix column_content = data.get_column(column_idx) con_filter = tools.get_filter(column_content) unknown_column = [data.state.Unknown for x in range(data.ROWS)] valid_perms = get_perms(unknown_column, column_values, con_filter) # meanwhile_content starts "empty" #find the 'agreed' values and update the matrix intersection = tools.get_intersection(valid_perms) data.set_column(intersection, column_idx) # update ROWS_CAN_IMPROVE and make false in this data.COLUMNS_HAS_CHANGE[column_idx] = False for i in range(len(column_content)): if (column_content[i] == data.state.Unknown and intersection[i] == data.state.Black) or ( column_content[i] == data.state.Unknown and intersection[i] == data.state.White): data.ROWS_HAS_CHANGE[i] = True # return whether there was an improvement has_improvement = False if tools.has_diff(column_content, intersection): has_improvement = True return has_improvement
class testcase(unittest.TestCase): logger = set_logger(__name__) sdk = tools.get_api() model = tools.get_model() filters = tools.get_filter() filter_count = int(tools.read_job_config()['filter_count']) unfilter_count = int(tools.read_job_config()['unfilter_count']) timeout = tools.read_job_config()['case_timeout'] def setUp(self): self.timeout_flag = None self.flag1 = 0 self.flag2 = 0 self.key=None self.logger.info('X/E 测试chip0 filter uuid被动扫描 chip1 filter uuid 主动扫描,S chip0 filter uuid 主动扫描') self.timer = Timer(self.timeout, self.set_timeout) self.timer.start() def tearDown(self): self.timer.cancel() # 测试方法 def test_scan_filter_uuid(self): if self.model.startswith('S') or self.model.startswith('s'): a = threading.Thread(target=self.chip0_scan, args=(0, self.filters['filter_uuid'])) a.setDaemon(True) a.start() while True: if self.flag1 == 1: self.assertTrue(True) self.logger.info('pass\n') break elif self.timeout_flag: self.logger.info('fail\n') self.fail('Case failed,start scan timeout.') self.logger.error("Case failed,start scan timeout.") break else: a = threading.Thread(target=self.chip0_scan, args=(1, self.filters['filter_uuid'])) b = threading.Thread(target=self.chip1_scan, args=(0, self.filters['filter_uuid'])) a.setDaemon(True) b.setDaemon(True) b.start() a.start() while True: if self.flag1==1 and self.flag2==1: self.assertTrue(True) self.logger.info('pass\n') break elif self.timeout_flag: self.logger.info('fail\n') self.fail('Case failed,case timeout.') self.logger.error("Case failed,start scan timeout.") # break sys.exit(1)
class testcase(unittest.TestCase): logger = set_logger(__name__) sdk = tools.get_api() model = tools.get_model() filters = tools.get_filter() filter_count = int(tools.read_job_config()['filter_count']) unfilter_count = int(tools.read_job_config()['unfilter_count']) timeout = tools.read_job_config()['case_timeout'] def setUp(self): self.timeout_flag = None self.flag1 = 0 self.flag2 = 0 self.logger.info('测试X/E chip0 chip1 filter rssi主动扫描,S chip0 filter rssi 主动扫描') self.timer = Timer(self.timeout, self.set_timeout) self.timer.start() def tearDown(self): self.timer.cancel()
class testcase(unittest.TestCase): logger = set_logger(__name__) sdk = tools.get_api() model = tools.get_model() filters = tools.get_filter() timeout = tools.read_job_config()['case_timeout'] filter_count = int(tools.read_job_config()['filter_count']) unfilter_count = int(tools.read_job_config()['unfilter_count']) def setUp(self): self.timeout_flag = None self.flag1 = 0 self.flag2 = 0 self.logger.info('测试chip0 filter name主动扫描,chip1 不加过虑主动扫描') self.timer = Timer(self.timeout, self.set_timeout) self.timer.start() def tearDown(self): self.timer.cancel() #测试方法 # noinspection PyUnreachableCode,PyUnreachableCode def test_scan_filter_name(self): if self.model.startswith('S') or self.model.startswith('s'): a = threading.Thread(target=self.chip0_scan, args=(1, self.filters['filter_name'])) b = threading.Thread(target=self.chip0_scan, args=(0, )) a.setDaemon(True) b.setDaemon(True) b.start() a.start() while True: if self.flag1 == 2: self.assertTrue(True) self.logger.info('pass\n') break elif self.timeout_flag: self.logger.info('fail\n') self.fail('Case failed,start scan timeout.') self.logger.error("Case failed,start scan timeout.") break else: a = threading.Thread(target=self.chip0_scan, args=(1, self.filters['filter_name'])) b = threading.Thread(target=self.chip1_scan, args=(0, )) a.setDaemon(True) b.setDaemon(True) b.start() a.start() while True: if self.flag1 == 1 and self.flag2 == 1: self.assertTrue(True) self.logger.info('pass\n') break elif self.timeout_flag: self.logger.info('fail\n') self.fail('Case failed,start scan timeout.') self.logger.error("Case failed,start scan timeout.") break # noinspection PyUnreachableCode def chip0_scan(self, active=0, filter_name=None): #step1:chip 1 start passive scan,then start chip0 scan. with closing( self.sdk.scan(chip=0, active=active, filter_name=filter_name)) as self.sse1: count = 0 for message in self.sse1: if message.startswith('data'): msg = json.loads(message[5:]) if filter_name: #进入开启过滤的扫描结果判断流程 if count < self.filter_count: print('chip0', count, message) name = msg['name'] if name != self.filters['filter_name']: self.fail('filter name failed.') self.logger.debug('filter name failed.') break else: count += 1 else: self.flag1 += 1 self.logger.debug( 'Step 1:chip0 start scan with filter name success.' ) break else: #进入不开启过滤的扫描结果判断流程 if count < 300: print('chip0', count, message) count += 1 else: self.flag1 += 1 self.logger.debug( 'Step 1:chip0 start scan with no filter name success.' ) break # noinspection PyUnreachableCode def chip1_scan(self, active=0, filter_name=None): #step2:start chip0 scan. with closing( self.sdk.scan(chip=1, active=active, filter_name=filter_name)) as self.sse2: count = 0 tmp_name = [] for message in self.sse2: if message.startswith('data'): msg = json.loads(message[5:]) if filter_name: if count < self.filter_count: print('chip1', count, message) name = msg['name'] if name != filter_name: self.fail('filter name failed.') self.logger.debug('filter name failed.') break else: count += 1 else: self.flag2 += 1 self.logger.debug( 'Step 2:chip1 start scan with filter name success.' ) break else: #进入不开启过滤的扫描结果判断流程 if count < self.unfilter_count: print('chip1', count, message) count += 1 else: self.flag2 += 1 self.logger.debug( 'Step 2:chip1 start scan with no filter name success.' ) break def set_timeout(self): self.timeout_flag = True
class testcase(unittest.TestCase): logger = set_logger(__name__) local_sdk, cloud_sdk = tools.get_all_api() model = tools.get_model() filters = tools.get_filter() timeout = tools.read_job_config()['case_timeout'] def setUp(self): self.timeout_flag = None self.flag1 = None self.flag2 = None self.logger.info('测试点:测试chip0 local扫描的同时,chip1进行cloud扫描') self.timer = Timer(self.timeout, self.set_timeout) self.timer.start() def tearDown(self): self.timer.cancel() def test_scan_on_cloud_local(self): a = threading.Thread(target=self.local_scan) b = threading.Thread(target=self.cloud_scan) a.setDaemon(True) b.setDaemon(True) b.start() a.start() while True: if self.flag1 and self.flag2: self.assertTrue(True) self.logger.info('pass\n') break elif self.timeout_flag: self.logger.info('fail\n') self.fail('Case failed,start scan timeout.') self.logger.error("Case failed,start scan timeout.") break def test_step(self): self.flag = None #step1:start local scan. with closing(self.local_sdk.scan(chip=1)) as self.sse2: count = 0 for message in self.sse2: if message.startswith('data'): if count < 100: print('local', count, message) count += 1 else: self.flag = True self.logger.debug('Step 1: start local scan success.') break #step3:停止本地扫描 time.sleep(3) self.logger.debug('Step 2: stop local scan success.') #step2:start cloud scan. with closing(self.cloud_sdk.scan(chip=0)) as self.sse1: count = 0 for message in self.sse1: if message.startswith('data'): if count < 100: print('cloud', count, message) count += 1 else: self.flag = True self.logger.debug('Step 3:start cloud scan success.') break def set_timeout(self): self.timeout_flag = True