def verify_tails(t: unittest.TestCase, run: kfp_server_api.ApiRun, tasks: dict[str, KfpTask], **kwargs): t.assertEqual(run.status, 'Succeeded') t.assertCountEqual(['print-msg', 'condition-1', 'flip-coin'], tasks.keys()) t.assertIsNone(tasks['condition-1'].children) # MLMD canceled state means NotTriggered state for KFP. t.assertEqual(Execution.State.CANCELED, tasks['condition-1'].state)
def _apply(self, put: unittest.TestCase, value: AdvWvAssertionModel[T], message_builder: MessageBuilder): result_of_validation = value.adv.validate() put.assertIsNone(result_of_validation, message_builder.apply('validation result')) resolved_value = value.adv.resolve(value.environment) self._resolved_value.apply( put, resolved_value, message_builder.for_sub_component('resolved value'))
def assert_constant_consistent(test_case: unittest.TestCase, wf: Waveform): if wf.is_constant(): cvs = wf.constant_value_dict() test_case.assertEqual(wf.defined_channels, cvs.keys()) for ch in wf.defined_channels: test_case.assertEqual(cvs[ch], wf.constant_value(ch)) else: test_case.assertIsNone(wf.constant_value_dict()) test_case.assertIn(None, {wf.constant_value(ch) for ch in wf.defined_channels})
def __assertions_on_hypothetical_reference_to_sdv(self, put: unittest.TestCase, actual: PathSdv, symbols: SymbolTable): restriction = PathAndRelativityRestriction( PathRelativityVariants(RelOptionType, True)) container = PathSymbolValueContext.of_sdv(actual).container result = restriction.is_satisfied_by(symbols, 'hypothetical_symbol', container) put.assertIsNone(result, 'Result of hypothetical restriction on path')
def _apply(self, put: unittest.TestCase, value, message_builder: MessageBuilder, ): put.assertIsInstance(value, SetupSettingsBuilder, message_builder.apply('object should be instance of ' + str(type(SetupSettingsBuilder))) ) assert isinstance(value, SetupSettingsBuilder) # Type info for IDE put.assertIsNone(value.stdin, message_builder.apply('stdin')) self._environ.apply(put, value.environ, message_builder.for_sub_component('environ'))
def __assertions_on_reference_restrictions(self, put: unittest.TestCase, actual: PathSdv, symbols: SymbolTable): for idx, reference in enumerate(actual.references): assert isinstance(reference, SymbolReference) # Type info for IDE container = symbols.lookup(reference.name) assert isinstance(container, SymbolContainer) result = reference.restrictions.is_satisfied_by( symbols, reference.name, container) put.assertIsNone( result, 'Restriction on reference #{}: expects None=satisfaction'. format(idx))
def _apply(self, put: unittest.TestCase, value, message_builder: asrt.MessageBuilder): model = value assert isinstance(model, SettingsBuilderAssertionModel) # Type info for IDE put.assertIsNone(model.actual.stdin.file_name, message_builder.apply('file name should not be set when using here doc')) expected_contents_str = self.expected_contents_resolver.resolve_value_of_any_dependency( model.environment.path_resolving_environment_pre_or_post_sds) put.assertEqual(expected_contents_str, model.actual.stdin.contents, message_builder.apply('stdin as contents'))
def _apply(self, put: unittest.TestCase, value, message_builder: asrt.MessageBuilder): model = value assert isinstance(model, SettingsBuilderAssertionModel) # Type info for IDE put.assertIsNone(model.actual.stdin.contents, message_builder.apply('contents should not be set when using file')) expected_file_name = self._expected_file_reference.value_of_any_dependency( model.environment.path_resolving_environment_pre_or_post_sds.home_and_sds) put.assertEqual(expected_file_name, model.actual.stdin.file_name, message_builder.apply('Name of stdin file in Setup Settings'))
def check_result(put: unittest.TestCase, environment: InstructionEnvironmentForPostSdsStep, expected_matcher_result: Optional[ValueAssertion[str]], actual_result: Optional[ErrorMessageResolver]): if expected_matcher_result is None: put.assertIsNone(actual_result, 'result from main') else: put.assertIsNotNone(actual_result, 'result from main') err_msg_env = ErrorMessageResolvingEnvironment(environment.home_and_sds, environment.symbols) err_msg = actual_result.resolve(err_msg_env) expected_matcher_result.apply_with_message(put, err_msg, 'error result of main')
def assertions(self, put: unittest.TestCase, actual: FailureDetails, message_header: str = None): message_builder = asrt.new_message_builder(message_header) if self.error_message_or_none is None and self.exception_class_or_none is None: put.assertIsNone(actual, message_header) elif self.error_message_or_none is not None: self.error_message_or_none.apply(put, actual.failure_message, message_builder.for_sub_component('failure message')) else: put.assertIsInstance(actual.exception, self.exception_class_or_none, message_builder.for_sub_component('exception class'))
def default_test(tc: unittest.TestCase, q_cls: Type[Queue[int]]): with tc.subTest('queue_001'): q = q_cls(A1) q.push(2) tc.assertEqual([1, 2, 2, 2, 3, 3, 3], ex(q), ) with tc.subTest('queue_002'): q = q_cls(A2) q.push(2) tc.assertEqual([1, 2, 2, 3, 3, 3], ex(q), ) with tc.subTest('queue_003'): q = q_cls(A2) q.push(0) tc.assertEqual([0, 1, 2, 3, 3, 3], ex(q), ) with tc.subTest('queue_004'): q = q_cls(A2) q.push(4) tc.assertEqual([1, 2, 3, 3, 3, 4], ex(q), ) with tc.subTest('queue_005'): q = q_cls(A3) q.push(4) tc.assertEqual([4], ex(q)) with tc.subTest('queue_006'): q = q_cls(A4) q.push(4) tc.assertEqual([1, 4], ex(q)) with tc.subTest('queue_007'): q = q_cls(A4) q.push(0) tc.assertEqual([0, 1], ex(q)) with tc.subTest('queue_007'): q = q_cls([]) tc.assertIsNone(q.peek()) val = 5 q.push(val) v2 = q.peek() tc.assertEqual(v2, val)
def _assertions(self, unittest_case: unittest.TestCase, return_value: Failure): if self._failure_status is None: unittest_case.assertIsNone( return_value, 'Return value must be None (representing success)') else: unittest_case.assertIsNotNone( return_value, 'Return value must not be None (representing failure)') unittest_case.assertEqual(self._failure_status, return_value.status, 'Status') self._line.apply_with_message(unittest_case, return_value.source_location, 'source location path') unittest_case.assertIsNotNone(return_value.failure_details, 'failure_details must be present') self._failure_details.apply_with_message( unittest_case, return_value.failure_details, 'failure_details')
def _assertions(self, unittest_case: unittest.TestCase, return_value: Failure): if self._status is PartialExeResultStatus.PASS: unittest_case.assertIsNone(return_value, 'Return value must be None (representing success)') else: unittest_case.assertIsNotNone(return_value, 'Return value must not be None (representing failure)') unittest_case.assertEqual(self._status, return_value.status, 'Status') self._line.apply_with_message(unittest_case, return_value.source_location, 'source location path') unittest_case.assertIsNotNone(return_value.failure_details, 'failure_details must be present') self._failure_details.apply_with_message(unittest_case, return_value.failure_details, 'failure_details')
def assert_velocity_properties(test_case: unittest.TestCase, data: SeismicData, velocity_prop: VelocityProperties) -> None: test_case.assertIsNotNone(data) test_case.assertIsNotNone(data.velocity_properties) test_case.assertIsNotNone(velocity_prop) for prop in dir(data.velocity_properties): if "_" in prop[0:1] or prop == "count" or prop == "index": continue if getattr(data.velocity_properties, prop) is None: test_case.assertIsNone(getattr(velocity_prop, prop)) else: try: float(getattr(data.velocity_properties, prop)) test_case.assertAlmostEqual(getattr(data.velocity_properties, prop), getattr(velocity_prop, prop), 3) except ValueError: test_case.assertEqual(getattr(data.velocity_properties, prop), getattr(velocity_prop, prop))
def assert_velocity_properties(test_case: unittest.TestCase, data: SeismicData, velocity_prop: VelocityProperties) -> None: test_case.assertIsNotNone(data) test_case.assertIsNotNone(data.velocity_properties) test_case.assertIsNotNone(velocity_prop) for prop in dir(data.velocity_properties): if "_" in prop[0:1] or prop == "count" or prop == "index": continue if getattr(data.velocity_properties, prop) is None: test_case.assertIsNone(getattr(velocity_prop, prop)) else: try: float(getattr(data.velocity_properties, prop)) test_case.assertAlmostEqual( getattr(data.velocity_properties, prop), getattr(velocity_prop, prop), 3) except ValueError: test_case.assertEqual(getattr(data.velocity_properties, prop), getattr(velocity_prop, prop))
def _apply(self, put: unittest.TestCase, value: T, message_builder: MessageBuilder): put.assertIsNone(value, message_builder.apply(self.message))
def _assertions(self, unittest_case: unittest.TestCase, actual_failure_info: FailureInfo): unittest_case.assertIsNone(actual_failure_info, 'There should be no failure')
class Clock_CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey def case_if_base(self, Skip=False): """设置基础,检查是否可以正常启动""" self.driver.activate_app(clock_pkg) if not Skip: if self.test.wait_if_activity(Permissions_Activity): self.test.find_byid(Permission_allow_button).click() time.sleep(1) self.Case.assertTrue(self.test.wait_if_activity(clock_activity), '启动 时钟 失败,超时5秒未检测到主界面') self.test.set_PORTRAIT() time.sleep(1) def case_check_date_time(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) time.sleep(1) self.test.find_byacc('时钟').click() time.sleep(0.5) time_test = TimeUtils.str_A_P_M_time() tmp_time = self.test.find_byid(clock_show_time).text tmp_date = self.test.find_byid(clock_show_data).text if tmp_time not in time_test: self.Case.fail( f'失败,请检查是否与北京时间相差过大,若差1分钟则不是问题,手机时间 : {tmp_time},当前时间 : {time_test}' ) if tmp_date not in TimeUtils.str_date_week(): self.Case.fail( f'失败,请检查是否与北京时间相差过大,手机日期 : {tmp_date},当前日期 : {TimeUtils.str_date_week()}' ) def case_set_alarm(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) time.sleep(1) self.test.find_byacc('闹钟').click() time.sleep(0.5) self.test.find_byacc('展开闹钟').click() time.sleep(1) self.test.find_byid(clock_del_alarm).click() time.sleep(0.2) self.test.find_byacc('展开闹钟').click() time.sleep(0.2) for text_acc in ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']: tmp = self.test.find_byacc(text_acc) if tmp.get_attribute('checked') == 'false': tmp.click() time.sleep(0.2) time.sleep(0.2) self.test.find_byid_list(clock_show_time)[0].click() time.sleep(0.5) if self.test.find_byid(clock_set_time_simulation) is None: self.Case.fail(f'设定闹钟的 模拟时钟 刻度盘未显示') if TimeUtils.is_AM(): self.test.find_byid(clock_set_time_am).click() else: self.test.find_byid(clock_set_time_pm).click() self.test.find_byid(clock_set_time_mode).click() time.sleep(0.2) self.test.find_byid(clock_set_time_hour).send_keys( TimeUtils.get_hour()) self.test.find_byid(clock_set_time_minute).send_keys( TimeUtils.get_minute() + 2) self.test.find_byclass(Button, '确定').click() isFlga = False actions = TouchAction(self.driver) for x in range(122): actions.press(x=(self.test.get_windows_width() * 0.5), y=(self.test.get_windows_height() * 0.15)).release().perform() tmp = self.test.find_byid(clock_set_alarm_state) if tmp is not None: locat = tmp.location actions.long_press(x=locat['x'], y=locat['y']) actions.move_to(x=(self.test.get_windows_width() * 0.9), y=locat['y']) actions.release().perform() isFlga = True break time.sleep(1) self.driver.press_keycode(4, 0, 0) if not isFlga: self.Case.fail(f'闹钟在2分钟内未响,测试失败') self.Case.assertTrue(self.test.wait_if_activity(clock_activity), '闹钟 关闭 失败,超时5秒未检测到主界面') time.sleep(1) def case_check_timer_input(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) time.sleep(1) self.test.find_byacc('定时器').click() time.sleep(0.5) for x in range(10): self.test.find_byid(f'{clock_timer_x}{x}').click() time.sleep(0.1) tmp_time = self.test.find_byid(clock_show_timer).text if f'0{x}秒' not in tmp_time: self.Case.fail(f'定时器设定 {x} 秒失败') self.test.find_byid(clock_del_timer_time).click() time.sleep(0.2) def case_set_timer(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) time.sleep(1) self.test.find_byacc('定时器').click() time.sleep(0.5) self.test.find_byid(clock_timer_6).click() tmp_time = self.test.find_byid(clock_show_timer).text if f'06秒' not in tmp_time: self.Case.fail(f'定时器设定 6 秒失败') self.test.find_byid(clock_start_timer).click() time.sleep(1) self.test.find_byid(clock_start_timer).click() time.sleep(1) text_time = self.test.find_byid(clock_show_timer_started).text try: if 6 > int(text_time) > 4: self.Case.fail(f'定时器计时失败,6秒计时器,剩余{text_time}') except ValueError: self.Case.fail(f'定时器显示失败,显示为:{text_time}') time.sleep(0.5) self.test.find_byid(clock_del_timer).click() time.sleep(0.5) self.Case.assertIsNone(self.test.find_byid(clock_start_timer), '定时器未删除') time.sleep(1) def case_check_Stopwatch(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) time.sleep(1) self.test.find_byacc('秒表').click() time.sleep(0.5) self.Case.assertIsNotNone(self.test.find_byid(clock_show_stopwatch), '秒表 计数盘 未显示') tmp = self.test.find_byid(clock_show_stopwatch_time) self.test.find_byid(clock_start_timer).click() time.sleep(3) self.test.find_byid(clock_start_timer).click() try: tmp_time = 0 """ for x in range(10): tmp = self.test.find_byid(clock_show_stopwatch_time) if tmp is not None: tmp_time = int(tmp.text) """ tmp_time = int(tmp.text) if tmp_time == 0: self.Case.fail(f'未获取到,秒表时间') except ValueError: self.Case.fail(f'秒表时间显示错误,计时约三秒,{tmp_time}') if tmp_time < 2.9: self.Case.fail(f'秒表时间显示错误,计时约三秒,未超过2.9秒:时间为:{tmp_time}') self.test.find_byacc('重置').click() time.sleep(1) def case_check_clock_UI_switch(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '时钟' in str_tmp: m.click() time.sleep(1) break detail_clock = self.test.find_byid(clock_show_time) if detail_clock is None: self.Case.fail("未找到当前详细时间,进入的页面非时钟页面") cities = self.test.find_list_byclass(ImageButton) city_flag = False for city in cities: str_tmp = city.get_attribute('content-desc') if '城市' in str_tmp: city_flag = True break if not city_flag: self.Case.fail("未找到时区(城市)选择按钮,进入的页面非时钟页面") self.test.swipe_Right(600, 1) time.sleep(1) switch_list = self.test.find_list_byclass(Switch) if switch_list is None: alarm_list = self.test.find_list_byclass(TextView) alarm_flag = False for alarm in alarm_list: str_tmp = alarm.text if '没有闹钟' in str_tmp: alarm_flag = True break if not alarm_flag: self.Case.fail("未找到闹钟和没有闹钟提示,进入的页面非闹钟页面") add_list = self.test.find_list_byclass(ImageButton) add_flag = False for add in add_list: str_tmp = add.get_attribute('content-desc') if '添加闹钟' in str_tmp: add_flag = True break if not add_flag: self.Case.fail("未找到添加闹钟的按钮,切换的页面非闹钟页面") self.test.swipe_Left(600, 1) time.sleep(1) self.test.swipe_Left(600, 1) time.sleep(1) timer_text = self.test.find_byid(clock_show_timer) if timer_text is None: self.Case.fail("未找到定时器时刻表,切换的页面非定时器页面") del_list = self.test.find_list_byclass(ImageButton) del_flag = False for d in del_list: str_tmp = d.get_attribute('content-desc') if '删除' in str_tmp: del_flag = True break if not del_flag: self.Case.fail("未找到定时器删除按钮,切换的页面非定时器页面") self.test.swipe_Left(600, 1) time.sleep(1) stopwatch_veiw = self.test.find_byid(clock_stopwatch_veiw) if stopwatch_veiw is None: self.Case.fail("未找到秒表面板,切换的为非秒表页面") start_stop_button_list = self.test.find_list_byclass(ImageButton) start_flag = False for s in start_stop_button_list: str_tmp = s.get_attribute('content-desc') if '开始' in str_tmp: start_flag = True break if not start_flag: self.Case.fail("未找到秒表开始计时的按钮,切换的为非秒表页面") def case_clock_set_city_time(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '时钟' in str_tmp: m.click() time.sleep(1) break city_button = self.test.find_list_byclass(ImageButton) city_flag = False for city in city_button: str_tmp = city.get_attribute('content-desc') if '城市' in str_tmp: city.click() time.sleep(2) city_flag = True break if not city_flag: self.Case.fail("未找到城市按钮,确认当前页面为时钟页面") city_check_list = self.test.find_list_byclass(CheckBox) for city in city_check_list: str_tmp = city.get_attribute('content-desc') if '阿比让' in str_tmp: city.click() time.sleep(1) break back_list = self.test.find_list_byclass(ImageButton) for back in back_list: str_tmp = back.get_attribute('content-desc') if '转到上一层级' in str_tmp: back.click() time.sleep(2) break textview_list = self.test.find_list_byclass(TextView) city_flag = False for t in textview_list: str_tmp = t.text if '阿比让' in str_tmp: city_flag = True break if not city_flag: self.Case.fail("未找到选中的城市") city_button = self.test.find_list_byclass(ImageButton) city_flag = False for city in city_button: str_tmp = city.get_attribute('content-desc') if '城市' in str_tmp: city.click() time.sleep(2) city_flag = True break if not city_flag: self.Case.fail("未找到城市按钮,确认当前页面为时钟页面") city_check_list = self.test.find_list_byclass(CheckBox) for city in city_check_list: str_tmp = city.get_attribute('content-desc') if '阿比让' in str_tmp: city.click() time.sleep(1) break back_list = self.test.find_list_byclass(ImageButton) for back in back_list: str_tmp = back.get_attribute('content-desc') if '转到上一层级' in str_tmp: back.click() time.sleep(2) break def case_back_and_home_out_of_clock(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '时钟' in str_tmp: m.click() time.sleep(1) break self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) if self.test.wait_if_activity(clock_activity): self.Case.fail("在时钟界面按返回键无法退出界面") else: self.case_if_base(True) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) if self.test.wait_if_activity(clock_activity): self.Case.fail("在时钟界面按HOME按钮无法退出界面") def case_preview_and_play_timer_sounds(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '定时器' in str_tmp: m.click() time.sleep(1) break more_list = self.test.find_list_byclass(ImageView) for more in more_list: str_tmp = more.get_attribute('content-desc') if '更多选项' in str_tmp: more.click() time.sleep(1) break set_list = self.test.find_list_byclass(TextView) for s in set_list: str_tmp = s.text if '设置' in str_tmp: s.click() time.sleep(1) break for i in range(3): self.test.swipe_Down(600, 1) time.sleep(0.1) setting_list = self.test.find_list_byclass(TextView) for sets in setting_list: str_tmp = sets.text if '定时器提示音' in str_tmp: sets.click() time.sleep(3) break sounds_list = self.test.find_list_byclass(TextView) sound_flag = False for sound in sounds_list: str_tmp = sound.text if '静音' in str_tmp: sound.click() time.sleep(2) sound_flag = True continue if sound_flag: sound.click() time.sleep(2) for i in range(3): self.test.swipe_Down(600, 1) time.sleep(0.2) sound_list = self.test.find_list_byclass(TextView) for s in sound_list: s.click() time.sleep(2) if not sound_flag: self.Case.fail("未找到任何铃声") def case_set_and_check_timer_sound(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '定时器' in str_tmp: m.click() time.sleep(1) break more_list = self.test.find_list_byclass(ImageView) for more in more_list: str_tmp = more.get_attribute('content-desc') if '更多选项' in str_tmp: more.click() time.sleep(1) break set_list = self.test.find_list_byclass(TextView) for s in set_list: str_tmp = s.text if '设置' in str_tmp: s.click() time.sleep(1) break for i in range(3): self.test.swipe_Down(600, 1) time.sleep(0.1) setting_list = self.test.find_list_byclass(TextView) for sets in setting_list: str_tmp = sets.text if '定时器提示音' in str_tmp: sets.click() time.sleep(3) break sounds_list = self.test.find_list_byclass(TextView) for sound in sounds_list: str_tmp = sound.text if 'Argon' in str_tmp: sound.click() time.sleep(2) break back_list = self.test.find_list_byclass(ImageButton) for back in back_list: str_tmp = back.get_attribute('content-desc') if '转到上一层级' in str_tmp: back.click() time.sleep(1) break setting_list = self.test.find_list_byclass(TextView) sound_check = False for sets in setting_list: str_tmp = sets.text if 'Argon' in str_tmp: sound_check = True break if not sound_check: self.Case.fail("定时器提示音设置失败") back_list = self.test.find_list_byclass(ImageButton) for back in back_list: str_tmp = back.get_attribute('content-desc') if '转到上一层级' in str_tmp: back.click() time.sleep(1) break self.test.find_byid(clock_timer_6).click() time.sleep(1) image_list = self.test.find_list_byclass(ImageButton) for i in image_list: str_tmp = i.get_attribute('content-desc') if '开始' in str_tmp: i.click() time.sleep(2) break for i in range(5): time.sleep(3) button_list = self.test.find_list_byclass(Button) for b in button_list: str_tmp = b.text if '删除' in str_tmp: b.click() time.sleep(2) break if self.test.find_byid(clock_show_timer) is None: self.Case.fail("删除定时器失败") def case_timer_add_one_minute_check(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '定时器' in str_tmp: m.click() time.sleep(1) break one_button = self.test.find_byid(clock_timer_1) for i in range(6): one_button.click() time.sleep(1) for i in range(4): self.test.find_byid(clock_del_timer_time).click() time.sleep(1) image_list = self.test.find_list_byclass(ImageButton) for i in image_list: str_tmp = i.get_attribute('content-desc') if '开始' in str_tmp: i.click() time.sleep(2) break add_list = self.test.find_list_byclass(Button) for adds in add_list: str_tmp = adds.text if '+1:00' in str_tmp: adds.click() time.sleep(1) break button_list = self.test.find_list_byclass(Button) for b in button_list: str_tmp = b.text if '删除' in str_tmp: b.click() time.sleep(2) break
def should_none(test: unittest.TestCase, except_value, real_value): return test.assertIsNone(real_value)
class CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey def case_if_base(self): """检查是否可以正常启动""" try: self.driver.activate_app(phone_pkg) except: self.test.start_activity(phone_pkg,phone_main_activity) self.Case.assertTrue(self.test.wait_if_activity(phone_main_activity), '启动电话失败,超时5秒未检测到主界面') time.sleep(1) def case_get_imei_mdid(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.driver.activate_app(phone_pkg) self.Case.assertTrue(self.test.wait_if_activity(phone_main_activity), '等待5秒未检测到电话主界面') self.test.find_byid(phone_to_keypad).click() time.sleep(1) self.Case.assertIsNotNone(self.test.find_byid(phone_keypad_view),'拨号盘未显示') self.test.find_byid(phone_num_star).click() self.test.find_byid(phone_num_pound).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_6).click() self.test.find_byid(phone_num_pound).click() time.sleep(1) self.Case.assertTrue(('IMEI' in self.test.find_byid(phone_IMEI_Title).text),'IMEI 提示框 未显示') list_imei = self.test.find_byid_list(phone_imei_show) self.Case.assertIsNotNone(list_imei, 'IMEI号不存在') if len(list_imei) < 2: self.Case.fail('IMEI号不存在') for y in list_imei: str = y.text if len(str) == 15: try: int(str) except ValueError: self.Case.fail(f'IMEI号显示错误,非数字 (如果是MEID可能含有字母,并非bug): {str}') elif len(str) > 5: pass else: self.Case.fail(f'IMEI号显示错误 :长度为 0 : {str}') def case_call(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() self.test.find_byid(phone_to_keypad).click() time.sleep(1) self.Case.assertIsNotNone(self.test.find_byid(phone_keypad_view), '拨号盘未显示') num = devices_Config['operators'] if 10086 == num: self.test.find_byid(phone_num_1).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_8).click() self.test.find_byid(phone_num_6).click() elif 10010 == num: self.test.find_byid(phone_num_1).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_1).click() self.test.find_byid(phone_num_0).click() else: self.test.find_byid(phone_num_1).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_0).click() tmp_num = self.test.find_byid(phone_number_view).text tmp_num = int(re.sub(r' ','',tmp_num)) if tmp_num != num: self.Case.fail(f'输入号码显示不正确,输入为:{num},显示为:{tmp_num}') self.test.find_byid(phone_dialpad_button).click() for x in range(20): tmp_time = self.test.find_byid(phone_call_time_view) if tmp_time is not None: break time.sleep(1) time.sleep(3) self.test.find_byid(phone_call_end).click() time.sleep(2) self.Case.assertIsNone(self.test.find_byid(phone_call_time_view),'通话未挂断') self.driver.press_keycode(3, 0, 0) def case_call_112(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() self.test.find_byid(phone_to_keypad).click() time.sleep(1) self.Case.assertIsNotNone(self.test.find_byid(phone_keypad_view), '拨号盘未显示') self.test.find_byid(phone_num_1).click() self.test.find_byid(phone_num_1).click() self.test.find_byid(phone_num_2).click() tmp_num = self.test.find_byid(phone_number_view).text tmp_num = int(re.sub(r' ','',tmp_num)) if tmp_num != 112: self.Case.fail(f'输入号码显示不正确,输入为:{num},显示为:{tmp_num}') self.test.find_byid(phone_dialpad_button).click() for x in range(20): tmp_time = self.test.find_byid(phone_call_time_view) if tmp_time is not None: break time.sleep(1) time.sleep(3) self.test.find_byid(phone_call_end).click() time.sleep(2) self.Case.assertIsNone(self.test.find_byid(phone_call_time_view),'通话未挂断') self.driver.press_keycode(3, 0, 0) def case_ergodic_phone_view(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() tmp_list = self.test.find_byid_list(phone_bottom_Button) tmp_int = 0 for x in tmp_list: tmp_text = x.text if '快速拨号' in tmp_text: x.click() tmp_int += 1 if '通话记录' in tmp_text: x.click() tmp_int += 1 if '联系人' in tmp_text: x.click() tmp_int += 1 time.sleep(0.5) if tmp_int != 3: self.Case.fail("遍历 电话 界面失败,需要包含 :快速拨号 通话记录 联系人") def case_send_msg(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() self.test.find_byid(phone_to_keypad).click() time.sleep(1) self.Case.assertIsNotNone(self.test.find_byid(phone_keypad_view), '拨号盘未显示') test_number = self._random_number(times=5) self.test.find_list_byid(phone_search_action,'发送短信').click() self.Case.assertTrue(self.test.wait_if_activity(msg_edit_activity),'通过电话界面发送短信失败,未进入短信编辑界面') time.sleep(1) tmp_text = self.test.find_byid(msg_phone_edi).text tmp_text = re.sub(" ","",tmp_text) if test_number not in tmp_text: self.Case.fail(f"电话号码不匹配,拨号盘{test_number},短信界面{tmp_text}") def case_new_Contacts(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() self.test.find_byid(phone_to_keypad).click() time.sleep(1) self.Case.assertIsNotNone(self.test.find_byid(phone_keypad_view), '拨号盘未显示') test_number = self._random_number(times=5) self.test.find_list_byid(phone_search_action,'新建联系人').click() if self.test.find_list_byid(contacts_id_text,'联系人备份到') is not None: #取消备份到谷歌 self.test.find_byid(contacts_left_button).click() time.sleep(1) if not self.test.wait_if_activity(contacts_new_contacts_activity): self.Case.fail('未检测到新建联系人界面') time.sleep(1) tmp_text = self.test.find_byclass(Edit_Text,test_number[0:2]).text tmp_text = re.sub(" ","",tmp_text) if test_number not in tmp_text: self.Case.fail(f"电话号码不匹配,拨号盘{test_number},新建联系人{tmp_text}") def _random_number(self,times=11): int_tmp = '' for x in range(times): int_tmp_x = random.randint(0,9) if int_tmp_x == 0: self.test.find_byid(phone_num_0).click() int_tmp = f'{int_tmp}{0}' elif int_tmp_x == 1: self.test.find_byid(phone_num_1).click() int_tmp = f'{int_tmp}{1}' elif int_tmp_x == 2: self.test.find_byid(phone_num_2).click() int_tmp = f'{int_tmp}{2}' elif int_tmp_x == 3: self.test.find_byid(phone_num_3).click() int_tmp = f'{int_tmp}{3}' elif int_tmp_x == 4: self.test.find_byid(phone_num_4).click() int_tmp = f'{int_tmp}{4}' elif int_tmp_x == 5: self.test.find_byid(phone_num_5).click() int_tmp = f'{int_tmp}{5}' elif int_tmp_x == 6: self.test.find_byid(phone_num_6).click() int_tmp = f'{int_tmp}{6}' elif int_tmp_x == 7: self.test.find_byid(phone_num_7).click() int_tmp = f'{int_tmp}{7}' elif int_tmp_x == 8: self.test.find_byid(phone_num_8).click() int_tmp = f'{int_tmp}{8}' else: self.test.find_byid(phone_num_9).click() int_tmp = f'{int_tmp}{9}' time.sleep(0.3) return int_tmp