def check_both_single_and_multiple_line_source( self, put: unittest.TestCase, first_source_line_instruction_argument_source_template: str, act_phase_source_lines: list, expected_cmd_and_args: ValueAssertion, hds_contents: home_populators.HomePopulator = home_populators.empty()): instruction_argument_source = first_source_line_instruction_argument_source_template.format_map( self.format_map_for_template_string) for source, source_assertion in equivalent_source_variants_with_assertion(put, instruction_argument_source): # ARRANGE # os_process_executor = AtcOsProcessExecutorThatRecordsArguments() arrangement = Arrangement(source, act_phase_source_lines, atc_os_process_executor=os_process_executor, hds_contents=hds_contents) expectation = Expectation(source_after_parse=source_assertion) # ACT # check(put, arrangement, expectation) # ASSERT # put.assertFalse(os_process_executor.command.shell, 'Command should not indicate shell execution') actual_cmd_and_args = os_process_executor.command.args put.assertIsInstance(actual_cmd_and_args, list, 'Arguments of command to execute should be a list of arguments') put.assertTrue(len(actual_cmd_and_args) > 0, 'List of arguments is expected to contain at least the file|interpreter argument') expected_cmd_and_args.apply_with_message(put, actual_cmd_and_args, 'actual_cmd_and_args')
def what_is_session(): with DocumentStore() as store: store.initialize() # region session_usage_1 with store.open_session() as session: entity = Company(name= "Company") session.store(entity) session.save_changes() company_id = entity.Id with store.open_session() as session: entity = session.load(company_id, object_type= Company) print(entity.name) # endregion # region session_usage_2 with store.open_session() as session: entity = session.load(company_id, object_type=Company) entity.name = "Another Company" session.save_changes() # endregion with store.open_session() as session: # region session_usage_3 TestCase.assertTrue(session.load(company_id, object_type=Company) is session.load(company_id, object_type=Company))
def test_hideHud(self): self.game.showHud('playerHud') TestCase.assertTrue(self, self.game.tilemap.layers['playerHud'].visible) self.game.hideHud('playerHud') TestCase.assertFalse(self, self.game.tilemap.layers['playerHud'].visible)
def _apply(self, put: unittest.TestCase, value: spe.ResultAndStderr, message_builder: asrt.MessageBuilder): put.assertIsInstance(value, spe.ResultAndStderr) put.assertTrue(value.result.is_success, message_builder.apply('Result is expected to indicate success'))
def _apply(self, put: unittest.TestCase, value: T, message_builder: MessageBuilder = MessageBuilder()): msg = message_builder.apply(self.message) if self.expected: put.assertTrue(value, msg) else: put.assertFalse(value, msg)
def test_main(self): url = "http://" + str(settings.getIpAddress()) + ":" + str(settings.globalVars.portNumber) url = url.strip() print('TEST SERVER @ ' + url) website = urllib2.urlopen(url) website_html = str(website.read()) flag = website_html.__contains__("<pre>") TestCase.assertTrue(self,flag, "Invalid Server Response") pass
def _apply(self, put: unittest.TestCase, value: T, message_builder: MessageBuilder): file_path = pathlib.Path(self.path_name) put.assertTrue(file_path.exists(), message_builder.apply('Path should exist')) put.assertTrue(file_path.is_dir(), message_builder.apply('Path should be a directory'))
def _assert_table_contains(put: unittest.TestCase, table: sut.SymbolTable, expected_symbol: NameAndValue): put.assertTrue(table.contains(expected_symbol.name), 'table SHOULD contain the value') put.assertIn(expected_symbol.name, table.names_set, 'names set should contain the value') put.assertIs(expected_symbol.value, table.lookup(expected_symbol.name), 'lookup should fins the value')
def assert_is_success_and_output_dir_contains_at_least_result_files(put: unittest.TestCase, expected: SubProcessResult, actual: sut.Result): put.assertTrue(actual.is_success, 'Result should indicate success') put.assertEqual(expected.exitcode, actual.exit_code, 'Exit code') contents_assertion = assert_dir_contains_at_least_result_files(PROCESS_OUTPUT_WITH_NON_ZERO_EXIT_STATUS, actual.file_names) contents_assertion.apply(put, actual.output_dir_path)
def first_line_should_be_exit_identifier(put: unittest.TestCase, output: str, expected_exit_value: ExitValue): lines = output.split() put.assertTrue(len(lines) > 0, 'There should be at least one line (found {})'.format(len(lines))) first_line = lines[0] put.assertEqual(expected_exit_value.exit_identifier, first_line, 'first line')
def _apply(self, put: unittest.TestCase, value, message_builder: asrt.MessageBuilder): put.assertIsInstance(value, ConstantStringFragmentResolver) assert isinstance(value, ConstantStringFragmentResolver) # Type info for IDE put.assertTrue(value.is_string_constant, message_builder.apply('is_string_constant')) put.assertEqual(self.expected.string_constant, value.string_constant, message_builder.apply('string_constant'))
def _apply(self, put: unittest.TestCase, actual: Pattern, message_builder: MessageBuilder): put.assertEqual(self.pattern_string, actual.pattern, 'regex pattern string') for matching_string in self.matching_string_list: put.assertTrue(bool(actual.search(matching_string)), 'reg-ex should match "{}"'.format(matching_string)) put.assertFalse(bool(actual.search(self.non_matching_string)), 'reg-ex should not match "{}"'.format(self.non_matching_string))
def _assert_source_is_not_at_eof_and_has_current_whole_line(put: unittest.TestCase, source: ParseSource, expected_current_line: str): put.assertTrue(source.has_current_line, 'There should be remaining lines in the source') put.assertFalse(source.is_at_eof, 'There should be remaining source') put.assertEqual(expected_current_line, source.current_line_text, 'Should should have given current line') put.assertEqual(expected_current_line, source.remaining_part_of_current_line, 'Current line should be identical to remaining-part-of-current-line')
def assert_equal_failure_details(unit_tc: unittest.TestCase, expected: FailureDetails, actual: FailureDetails): if expected.is_only_failure_message: unit_tc.assertTrue(actual.is_only_failure_message, 'An error message is expected') unit_tc.assertEqual(expected.failure_message, actual.failure_message, 'The failure message should be the expected') else: unit_tc.assertFalse(actual.is_only_failure_message, 'An exception is expected') unit_tc.assertEqual(expected.exception, actual.exception, 'The exception should be the expected')
def assert_is_file_with_contents(test: unittest.TestCase, file_path: pathlib.Path, expected_content: str, msg=None): file_name = str(file_path) test.assertTrue(file_path.exists(), 'File should exist: ' + file_name) test.assertTrue(file_path.is_file(), 'Should be a regular file: ' + file_name) f = open(str(file_path)) actual_contents = f.read() f.close() if msg is None: msg = 'Contents of:' + file_name test.assertEqual(expected_content, actual_contents, msg)
def evaluate_user_object(test: unittest.TestCase, user_object: dict) -> None: """ Helper function for evaluating an user object :param test: The currently running test case :param user_object: The user object to evaluate """ test.assertIn("username", user_object, "User name is not in the user object") test.assertEqual(user_object["username"], "arobito", 'User name in user object is not "arobito"') test.assertIn("level", user_object, "User level is not in user object") test.assertEqual(user_object["level"], "Administrator", 'User level is not "Administrator"') test.assertIn("timestamp", user_object, "Timestamp is not in user object") test.assertIn("last_access", user_object, "Last access timestamp is not in user object") test.assertIsInstance(user_object["timestamp"], float, "Timestamp is not a float") test.assertIsInstance(user_object["last_access"], float, "Last access is not a float") test.assertTrue( user_object["timestamp"] <= user_object["last_access"], "Timestamp is not less or equal the last access" )
def _expect_file_ref(put: unittest.TestCase, source: ParseSource, expectation: ExpectedFileRef, rel_opt_arg_conf: RelOptionArgumentConfiguration = sut.CONFIGURATION, ): # ACT # actual = sut.parse_from_parse_source(source, rel_opt_arg_conf) # ASSERT # put.assertIs(string_or_file.SourceType.PATH, actual.source_type, 'source type') put.assertTrue(actual.is_file_ref, 'is_file_ref') symbol_references_assertion = equals_symbol_references(expectation.common.symbol_references) expected_file_ref_resolver = matches_file_ref_resolver(expectation.file_ref_value, symbol_references_assertion, symbol_table=expectation.common.symbol_table) expected_file_ref_resolver.apply_with_message(put, actual.file_reference_resolver, 'file_reference_resolver') _expect_common(put, source, actual, expectation.common)
def test_predicates(): say_test("test_predicates") tc = TestCase() lst = LinkedList() lst2 = LinkedList() tc.assertEqual(lst, lst2) lst2.append(100) tc.assertNotEqual(lst, lst2) lst.append(100) tc.assertEqual(lst, lst2) tc.assertFalse(1 in lst) tc.assertFalse(None in lst) lst = LinkedList() for i in range(100): lst.append(i) tc.assertFalse(100 in lst) tc.assertTrue(50 in lst)
def assert_dags_equals(test_case: unittest.TestCase, expected_dag: DAG, actual_dag: DAG): expected_dg = TransformerUtils.get_digraph_from_airflow_dag( expected_dag) actual_dg = TransformerUtils.get_digraph_from_airflow_dag(actual_dag) test_case.assertEqual(len(expected_dg.nodes), len(actual_dg.nodes)) def node_matcher(mismatches, n1, n2): i: BaseOperator = n1['op'] j: BaseOperator = n2['op'] diff = deepdiff.DeepDiff( i, j, exclude_paths=['root._dag', 'root.azure_hook.client'], exclude_regex_paths=[ re.compile(".*hook.*conn.*"), re.compile(".*{}.*".format( Transformer.TRANSFORMED_BY_HEADER)) ], view='tree', verbose_level=10) if diff != {}: mismatches.append((i, j, diff)) return diff == {} mismatches = [] is_isomorphic = nx.is_isomorphic(expected_dg, actual_dg, node_match=functools.partial( node_matcher, mismatches)) if not is_isomorphic: for i, j, diff in mismatches: print(f"Operators {i} and {j} are not equal") pprint(diff, indent=2) test_case.assertTrue(is_isomorphic)
def evaluate_user_object(test: unittest.TestCase, user_object: dict) -> None: """ Helper function for evaluating an user object :param test: The currently running test case :param user_object: The user object to evaluate """ test.assertIn('username', user_object, 'User name is not in the user object') test.assertEqual(user_object['username'], 'arobito', 'User name in user object is not "arobito"') test.assertIn('level', user_object, 'User level is not in user object') test.assertEqual(user_object['level'], 'Administrator', 'User level is not "Administrator"') test.assertIn('timestamp', user_object, 'Timestamp is not in user object') test.assertIn('last_access', user_object, 'Last access timestamp is not in user object') test.assertIsInstance(user_object['timestamp'], float, 'Timestamp is not a float') test.assertIsInstance(user_object['last_access'], float, 'Last access is not a float') test.assertTrue(user_object['timestamp'] <= user_object['last_access'], 'Timestamp is not less or equal the last access')
def check_all_paths_processed( test_case: unittest.TestCase, controller: BaseDirectIngestController, file_tags: List[str], unexpected_tags: List[str], ) -> None: """Checks that all non-directory paths with expected tags have been processed and moved to storage. """ if not isinstance(controller.fs.gcs_file_system, FakeGCSFileSystem): raise ValueError(f"Controller fs must have type " f"FakeGCSFileSystem. Found instead " f"type [{type(controller.fs.gcs_file_system)}]") file_tags_processed = set() for path in controller.fs.gcs_file_system.all_paths: if isinstance(path, GcsfsDirectoryPath): continue file_tag = filename_parts_from_path(path).file_tag if file_tag not in unexpected_tags: # Test all expected files have been moved to storage test_case.assertTrue( path.abs_path().startswith( controller.storage_directory_path.abs_path()), f"{path} has not been moved to correct storage directory", ) file_tags_processed.add(filename_parts_from_path(path).file_tag) else: test_case.assertTrue(path.file_name.startswith("unprocessed")) # Test that each expected file tag has been processed test_case.assertEqual(file_tags_processed, set(file_tags).difference(set(unexpected_tags)))
def test_gate_decomposition(gate: cirq.Gate, testcase: unittest.TestCase, print_circuit=True, expected_unitary=None): qubits = cirq.LineQubit.range(2) control, target = qubits circuit_compressed = cirq.Circuit() circuit_decomposed = cirq.Circuit() circuit_compressed.append(gate.on(control, target)) circuit_decomposed.append( cirq.decompose(gate.on(control, target), keep=is_a_basic_operation)) if print_circuit: print("Compressed circuit: \n{}".format(circuit_compressed)) print("Decomposed circuit: \n{}".format(circuit_decomposed)) print(cirq.unitary(circuit_compressed).round(3)) print(cirq.unitary(circuit_decomposed).round(3)) testcase.assertTrue( np.allclose((cirq.unitary(circuit_compressed) if expected_unitary is None else expected_unitary), cirq.unitary(circuit_decomposed)))
def _check_projection(test_instance: unittest.TestCase, relevant_all, kernels_this): # see <https://en.wikipedia.org/wiki/Projection_(linear_algebra)> project_matrix = relevant_all.T @ inv( relevant_all @ relevant_all.T) @ relevant_all kernels_this_projected = (project_matrix @ kernels_this.T).T assert kernels_this_projected.shape == kernels_this.shape # check cos cos_values = np.asarray([ cos_between(v1, v2) for v1, v2 in zip(kernels_this, kernels_this_projected) ]) # it's not very reliable. # check norm norm_diff = np.asarray([ norm(v1) / norm(v2) for v1, v2 in zip(kernels_this, kernels_this_projected) ]) test_instance.assertTrue(abs(cos_values - 1).max() < 0.01) # print(norm_diff) test_instance.assertTrue(abs(norm_diff - 1).max() < 0.01) return kernels_this_projected
def ValidateMetrics(test: unittest.TestCase, pipeline_result: beam.runners.runner.PipelineResult, telemetry_descriptors: List[Text], logical_format: Text, physical_format: Text): all_metrics = pipeline_result.metrics() maintained_metrics = all_metrics.query( beam.metrics.metric.MetricsFilter().with_namespace( "tfx." + ".".join(telemetry_descriptors + ["io"]))) test.assertIsNot(maintained_metrics, None) counters = maintained_metrics[beam.metrics.metric.MetricResults.COUNTERS] test.assertTrue(counters) distributions = maintained_metrics[ beam.metrics.metric.MetricResults.DISTRIBUTIONS] test.assertTrue(distributions) for m in counters + distributions: test.assertTrue( m.key.metric.name.startswith( "LogicalFormat[%s]-PhysicalFormat[%s]-" % (logical_format, physical_format)))
def sort_dict(d): return sorted(d.items(), key=lambda x: x[1], reverse=True) testd = {3: 1, 2: 2, 1: 3} # for k,v in testd.items(): # print(k,v) print(list(zip(testd.values(), testd.keys()))) from unittest import TestCase Test = TestCase() print(sort_dict(sort_dict(testd))) Test.assertTrue(sort_dict(testd) == [(1, 3), (2, 2), (3, 1)])
lst2 = ArrayList() lst.data = ConstrainedList([]) lst2.data = ConstrainedList([1, 2, 3]) tc.assertNotEqual(lst, lst2) lst.data = ConstrainedList([1, 2, 3]) tc.assertEqual(lst, lst2) lst.data = ConstrainedList([]) tc.assertFalse(1 in lst) tc.assertFalse(None in lst) lst.data = ConstrainedList(range(100)) tc.assertFalse(100 in lst) tc.assertTrue(50 in lst) # In[209]: # (10 points) test queries from unittest import TestCase tc = TestCase() lst = ArrayList() tc.assertEqual(0, len(lst)) tc.assertEqual(0, lst.count(1)) with tc.assertRaises(ValueError): lst.index(1)
def assertTrue(self, expr, thing=None, msg=None): if thing is not None: raise ValueError("Did you really mean to use assertTrue?") return TestCase.assertTrue(self, expr, msg=msg)
def assert_contains_html(asserter: TestCase, html: str, chunk: str): # indent=0: meh, but that kinda works and results in pretty assertion failures! bhtml = normalise_html(html) bchunk = normalise_html(chunk) asserter.assertTrue(bchunk in bhtml) # TODO assertContainsSubstring?
def test_transaction3(self): trans3 = self.res.listTransactions[3] # action 0 TestCase.assertFalse(self, trans3.actions[0].type) # out TestCase.assertEqual(self, trans3.actions[0].channel, 3) TestCase.assertEqual(self, trans3.actions[0].label, EGreekCharacters.DELTA.__str__ + "0out") TestCase.assertEqual(self, trans3.actions[0].rootTerm.name, "aenc") TestCase.assertEqual(self, trans3.actions[0].rootTerm.arguments[0].name, "sign") TestCase.assertEqual(self, trans3.actions[0].rootTerm.arguments[1].name, "pub") TestCase.assertEqual( self, trans3.actions[0].rootTerm.arguments[0].arguments[0].name, "concat") a = self.res.getVarInlist("a") c = self.res.getVarInlist("c") k1 = self.res.getVarInlist("k1") ska = self.res.getVarInlist("ska") skc = self.res.getVarInlist("skc") TestCase.assertEqual( self, trans3.actions[0].rootTerm.arguments[0].arguments[0].arguments[0], a) TestCase.assertEqual( self, trans3.actions[0].rootTerm.arguments[0].arguments[0].arguments[1], c) TestCase.assertEqual( self, trans3.actions[0].rootTerm.arguments[0].arguments[0].arguments[2], k1) TestCase.assertEqual( self, trans3.actions[0].rootTerm.arguments[0].arguments[1], ska) TestCase.assertEqual( self, trans3.actions[0].rootTerm.arguments[1].arguments[0], skc) typea = self.res.getTypeInlist("typea") typec = self.res.getTypeInlist("typec") noncek = self.res.getTypeInlist("noncek") kaenca = self.res.getTypeInlist("kaenca") kaencc = self.res.getTypeInlist("kaencc") TestCase.assertEqual( self, trans3.actions[0].rootTerm.arguments[0].arguments[0]. arguments[0].type, typea) TestCase.assertEqual( self, trans3.actions[0].rootTerm.arguments[0].arguments[0]. arguments[1].type, typec) TestCase.assertEqual( self, trans3.actions[0].rootTerm.arguments[0].arguments[0]. arguments[2].type, noncek) TestCase.assertEqual( self, trans3.actions[0].rootTerm.arguments[0].arguments[1].type, kaenca) TestCase.assertEqual( self, trans3.actions[0].rootTerm.arguments[1].arguments[0].type, kaencc) # action 1 TestCase.assertTrue(self, trans3.actions[1].type) # in TestCase.assertEqual(self, trans3.actions[1].channel, 3) TestCase.assertEqual(self, trans3.actions[1].label, EGreekCharacters.DELTA.__str__ + "1in") TestCase.assertEqual(self, trans3.actions[1].rootTerm.name, "senc") xa1 = self.res.getVarInlist("xa1") TestCase.assertEqual(self, trans3.actions[1].rootTerm.arguments[0], xa1) TestCase.assertEqual(self, trans3.actions[1].rootTerm.arguments[1], k1) noncem = self.res.getTypeInlist("noncem") TestCase.assertEqual(self, trans3.actions[1].rootTerm.arguments[0].type, noncem) TestCase.assertEqual(self, trans3.actions[1].rootTerm.arguments[1].type, noncek)
class Music_Video_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): """检查是否可以正常启动""" self.Case.assertTrue( self.test.start_activity(music_video_pkg, music_video_acivity), '启动 视频 失败,超时5秒未检测到主界面') def case_if_music_base(self, skip=False): """检查是否可以正常启动""" self.test.start_activity(music_video_pkg, music_video_music_acivity) time.sleep(1) if not skip: for x in range(3): if self.test.wait_if_activity(Permissions_Activity, timeout=3): time.sleep(0.3) self.test.find_byid(Permission_allow_button).click() time.sleep(0.5) else: time.sleep(1) break self.Case.assertTrue( self.test.wait_if_activity(music_video_music_acivity), '启动 音乐 失败,超时5秒未检测到主界面') time.sleep(1) def case_play_video(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.Case.assertTrue( self.test.start_activity(music_video_pkg, music_video_acivity), '启动 视频 失败,超时5秒未检测到主界面') time.sleep(1) if self._check_video_list('video_1'): self.test.find_list_byid(TEXT_ID_1, 'video_1').click() self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') for y in range(5): if y > 2: self.Case.assertTrue( self.test.wait_if_activity(music_video_acivity), '启动 视频播放完毕未返回主界面,超时5秒未检测到界面') break time.sleep(3) time.sleep(1) def case_play_stop_video(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.Case.assertTrue( self.test.start_activity(music_video_pkg, music_video_acivity), '启动 视频 失败,超时5秒未检测到主界面') time.sleep(1) if self._check_video_list('video_2'): self.test.find_list_byid(TEXT_ID_1, 'video_2').click() self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') self.test.find_byid(gallery_video_surface_view).click() self.test.find_byid(gallery_video_surface_view).click() time.sleep(1) tmp = self.test.find_byacc('播放视频') if tmp is not None: tmp.click() else: self.Case.fail('视频暂停失败,请检查') for y in range(16): if y > 13: self.Case.assertTrue( self.test.wait_if_activity(music_video_acivity), '启动 视频播放完毕未返回主界面,超时5秒未检测到界面') break time.sleep(3) time.sleep(1) def case_sleep_replay_video(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.Case.assertTrue( self.test.start_activity(music_video_pkg, music_video_acivity), '启动 视频 失败,超时5秒未检测到主界面') time.sleep(1) if self._check_video_list('video_2'): self.test.find_list_byid(TEXT_ID_1, 'video_2').click() self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') time.sleep(3) self.driver.lock(1) # 休眠一秒 self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') for y in range(16): if y > 12: self.Case.assertTrue( self.test.wait_if_activity(music_video_acivity), '启动 视频播放完毕未返回主界面,超时5秒未检测到界面') break time.sleep(3) time.sleep(1) def case_play_music(self): self.case_if_music_base(True) self.test.find_byacc(music_video_music_menu).click() time.sleep(0.2) self.test.find_list_byid(music_video_music_menu_title, '歌曲').click() time.sleep(1) self._find_music('music_7').click() time.sleep(1) tmp = self.test.find_byid(music_video_music_list_nowplay_icon) self.Case.assertIsNotNone(tmp, '歌曲未在播放') time.sleep(3) tmp.click() time.sleep(0.5) def _find_music(self, keytext): for y in range(10): el = self.test.find_list_byid(music_video_music_list, keytext) if el is not None: return el self.test.swipe_Down(600, 1) time.sleep(0.2) return None def _check_video_list(self, keytext): for y in range(10): if self.test.find_list_byid(TEXT_ID_1, keytext) is not None: return True self.test.swipe_Down(600, 1) time.sleep(0.2) return False def case_music_play_three_class_music_flie(self): self.case_if_music_base(True) ogg_flag = False mp3_flag = False flac_flag = False for i in range(3): time.sleep(3) flie_list = self.test.find_byid_list(music_video_music_list) for n in flie_list: if not ogg_flag: if ".ogg" in n.text: n.click() time.sleep(3) ogg_flag = True continue if not mp3_flag: if ".mp3" in n.text: n.click() time.sleep(3) mp3_flag = True continue if not flac_flag: if ".flac" in n.text: n.click() time.sleep(3) flac_flag = True continue if not ogg_flag or not mp3_flag or not flac_flag: # 若有未找到3类型中一种则下滑列表重新获取 self.test.swipe_Down(600, 1) time.sleep(0.3) if not ogg_flag or not mp3_flag or not flac_flag: self.Case.fail( f"播放失败,ogg:{ogg_flag},mp3{mp3_flag},flac{flac_flag}") self.test.find_byid(music_video_music_list_nowplay_icon).click() def case_music_detail_replay_music_1(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() # 进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() # 显示当前播放列表 replay = self.test.find_byid(music_video_music_detail_replay_button) replay_status = self._check_replay_close(replay) if not replay_status: self.Case.fail("未切换至关闭重新播放模式") elif replay_status: self._find_lost_muisc_and_play() self._replay_muisc_skip() totaltime = self.test.find_byid( music_video_music_detail_totaltime).text for i in range(10): time.sleep(3) currenttime = self.test.find_byid( music_video_music_detail_crrenttime).text if currenttime == totaltime: break replay_status = self._check_replay_list(replay) if not replay_status: self.Case.fail("未切换至重新播放列表模式") elif replay_status: self._find_lost_muisc_and_play() current_music = self.test.find_byid( music_video_music_list_song_name) self._replay_muisc_skip() for i in range(3): time.sleep(3) if not current_music.text == self.test.find_byid( music_video_music_list_song_name).text: self.test.find_byid( music_video_music_list_song_name).click() break def case_music_detail_replay_music_2(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() # 进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() # 显示当前播放列表 replay = self.test.find_byid(music_video_music_detail_replay_button) replay_status = self._check_replay_current(replay) if not replay_status: self.Case.fail("未切换至重新播放当前音乐模式") elif replay_status: current_music = self.test.find_byid( music_video_music_list_song_name) self.test.find_byid(music_video_music_play_pause).click() self._replay_muisc_skip() for i in range(3): time.sleep(3) if current_music.text == self.test.find_byid( music_video_music_list_song_name).text: break def _check_replay_close(self, el): for i in range(3): el.click() if self.test.if_toast_text("重复播放已关闭。") is not None: return True return False def _check_replay_list(self, el): for i in range(3): el.click() if self.test.if_toast_text("重复播放所有歌曲。") is not None: return True return False def _check_replay_current(self, el): for i in range(3): el.click() if self.test.if_toast_text("重复播放当前歌曲。") is not None: return True return False def _replay_muisc_skip(self): progress_loc = self.test.find_byid(music_video_music_detail_progress) loc = progress_loc.location actions = TouchAction(self.driver) actions.long_press(x=(self.test.get_windows_height() * 0.3), y=loc['y']) actions.move_to(x=(self.test.get_windows_width() * 0.98), y=loc['y']) actions.release().perform() def _find_lost_muisc_and_play(self): #self.test.find_byid(music_video_music_detail_currentlist).click() for i in range(3): self.test.swipe_Down(600, 1) time.sleep(0.3) detail_muisclist = self.test.find_byid_list(music_video_music_list) if detail_muisclist is not None: detail_lostmuisc = detail_muisclist[len(detail_muisclist) - 1] detail_lostmuisc.click() time.sleep(0.2) if self.test.find_byid(music_video_music_list_song_name ).text != detail_lostmuisc.text: self.Case.fail('播放的音乐与选定的音乐不同') def case_music_detail_pervious_play(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() # 进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() # 显示当前播放列表 current_music = self.test.find_byid(music_video_music_list_song_name) for i in range(3): self.test.swipe_Down(600, 1) time.sleep(0.3) detail_musiclist = self.test.find_byid_list( music_video_music_list) # 获取当前歌曲列表 pervious_music = detail_musiclist[len(detail_musiclist) - 1] if current_music.text != pervious_music.text: self.test.find_byid(music_video_music_detail_previous).click() time.sleep(1) if not self.test.find_byid(music_video_music_list_song_name ).text == pervious_music.text: self.Case.fail("上一曲功能失败") def case_music_detail_next_play(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() #进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() #显示当前播放列表 for i in range(3): self.test.swipe_UP(600, 1) time.sleep(0.3) detail_musiclist = self.test.find_byid_list( music_video_music_list) #获取当前歌曲列表 current_music = detail_musiclist[0] current_music.click() next_music = detail_musiclist[1] if current_music.text != next_music.text: self.test.find_byid(music_video_music_detail_next).click() if not self.test.find_byid( music_video_music_list_song_name).text == next_music.text: self.Case.fail("下一曲功能失败") def case_music_detail_play_and_pause(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() # 进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() # 显示当前播放列表 current_time = self.test.find_byid( music_video_music_detail_crrenttime).text play_and_pause = self.test.find_byid(music_video_music_play_pause) play_and_pause.click() time.sleep(2) if current_time == self.test.find_byid( music_video_music_detail_crrenttime).text: self.Case.fail("歌曲继续播放功能失败") play_and_pause.click() current_time = self.test.find_byid( music_video_music_detail_crrenttime).text for i in range(3): time.sleep(3) if current_time != self.test.find_byid( music_video_music_detail_crrenttime).text: self.Case.fail("歌曲暂停功能失败") def case_music_detail_random_close(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() # 进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() # 显示当前播放列表 time.sleep(1) detail_musiclist = self.test.find_byid_list(music_video_music_list) for i in range(3): self.test.find_byid(music_video_music_detail_random).click() if self.test.if_toast_text("随机播放已关闭。") is not None: detail_musiclist[0].click() time.sleep(0.2) next_button = self.test.find_byid( music_video_music_detail_next) next_button.click() if detail_musiclist[1].text != self.test.find_byid( music_video_music_list_song_name).text: self.Case.fail("随机播放关闭功能失败") break def case_music_detail_random(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() # 进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() # 显示当前播放列表 time.sleep(1) detail_musiclist = self.test.find_byid_list(music_video_music_list) for i in range(3): self.test.find_byid(music_video_music_detail_random).click() if self.test.if_toast_text("随机播放已打开。") is not None: detail_musiclist[0].click() time.sleep(0.2) next_button = self.test.find_byid( music_video_music_detail_next) next_button.click() time.sleep(0.2) if detail_musiclist[1].text == self.test.find_byid( music_video_music_list_song_name).text: next_button.click(0.2) if detail_musiclist[2].text == self.test.find_byid( music_video_music_list_song_name).text: self.Case.fail("随机播放功能失败") break def case_music_delete_file(self): self.case_if_music_base(True) music_list = self.test.find_byid_list(music_video_music_list) indicator_list = self.test.find_byid_list( music_video_music_indicator_list) music_name = music_list[0].text indicator_list[0].click() time.sleep(1) delete_button = self.test.find_list_byid(music_video_music_title_list, '删除') delete_button.click() time.sleep(1) delete_flie = self.test.find_byid(music_video_music_delete) delete_flie.click() time.sleep(1) if self.test.find_list_byid(music_video_music_list, music_name) is not None: self.Case.fail("删除音乐文件失败") def case_video_main_activity_keydown_recent(self): self.case_if_base() time.sleep(1) self.driver.press_keycode(187, 0, 0) # all apps list 多任务管理按钮 time.sleep(2) self.driver.press_keycode(4, 0, 0) time.sleep(2) self.Case.assertTrue(self.test.wait_if_activity(music_video_acivity), '没有返回视频 主界面') def case_video_Movie_activity_keydown_recent(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) if self._check_video_list('video_2'): self.test.find_list_byid(TEXT_ID_1, 'video_2').click() self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') time.sleep(2) self.driver.press_keycode(187, 0, 0) # all apps list 多任务管理按钮 time.sleep(2) self.driver.press_keycode(4, 0, 0) time.sleep(2) self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '没有返回 播放 界面') time.sleep(0.5) self.driver.press_keycode(4, 0, 0) time.sleep(1) def case_video_Movie_activity_keydown_home(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) if self._check_video_list('video_2'): self.test.find_list_byid(TEXT_ID_1, 'video_2').click() self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') time.sleep(2) self.driver.press_keycode(3, 0, 0) #HOME键 time.sleep(2) try: self.Case.assertTrue( self.test.start_activity(music_video_pkg, music_video_acivity), '未成功返回播放界面') except selenium.common.exceptions.WebDriverException: pass self.driver.press_keycode(4, 0, 0) time.sleep(1) def case_video_Movie_activity_longkeydown_power(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) if self._check_video_list('video_2'): self.test.find_list_byid(TEXT_ID_1, 'video_2').click() self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') time.sleep(2) self.driver.long_press_keycode(26, 0, 0) # power键 time.sleep(0.2) self.driver.press_keycode(4, 0, 0) time.sleep(1) def case_music_set_widget(self): self.driver.press_keycode(3, 0, 0) time.sleep(1) tmp = get_widget_menu(self.driver) if tmp is None: self.Case.fail('未成功长按出 桌面 小菜单') tmp.click() time.sleep(1) tmp = widget_list_swipe_Down(self.driver) if tmp is None: self.Case.fail('未找到音乐小挂件') touchAction = TouchAction(self.driver) touchAction.long_press(el=tmp) time.sleep(2) touchAction.release().perform() time.sleep(1) tmp = self.test.find_byid(music_video_widget_icon) if tmp is None: self.Case.fail('音乐桌面小图标,未放置成功') tmp.click() self.Case.assertTrue( self.test.wait_if_activity(music_video_music_acivity), '通过桌面小挂件打开音乐失败') time.sleep(1) def case_music_set_singer_view(self): self.case_if_music_base(True) time.sleep(1) self.test.find_byacc(music_video_music_menu).click() time.sleep(0.2) self.test.find_list_byid(music_video_music_menu_title, '音乐人').click() time.sleep(1) tmp_list = self.test.find_list_byclass(TextView) for x in tmp_list: t = x.text if '付娜' in t: time.sleep(1) return if '中央芭蕾舞团管弦乐队' in t: time.sleep(1) return if '周深' in t: time.sleep(1) return if '张含韵' in t: time.sleep(1) return self.Case.fail('歌曲非 歌手 列表排列') def case_music_add_play_list(self): time_name = TimeUtils.str_HMS_Name() self.case_if_music_base(True) time.sleep(1) if self.test.find_byclass(TextView, '歌曲', isText=True) is None: self.test.find_byacc(music_video_music_menu).click() time.sleep(0.2) self.test.find_list_byid(music_video_music_menu_title, '歌曲').click() time.sleep(1) tmp_list = self.test.find_byid_list(music_video_music_indicator_list) tmp_int = random.randint(2, len(tmp_list) - 2) tmp_list[tmp_int].click() time.sleep(0.5) self.test.find_list_byid(ID_title, '添加到播放列表').click() time.sleep(0.5) self.test.find_list_byid(ID_title, '新建播放列表').click() time.sleep(0.5) tmp_el = self.test.find_byid(music_video_music_playlist_edit) tmp_el.clear() tmp_el.send_keys(f'list_{time_name}') self.test.find_byid(music_video_music_create_playlist).click() if self.test.if_toast_text('歌曲已添加到播放列表') is None: log('error', '添加到 收藏,未找到 toast') self.test.find_byacc(music_video_music_menu).click() time.sleep(1) self.test.find_list_byid(music_video_music_menu_title, '播放列表').click() time.sleep(1) self._checK_play_list(f'list_{time_name}').click() time.sleep(1) tmp = self.test.find_byclass(TextView, 'music_') if tmp is None: self.Case.fail('列表中没有音乐 {music_}') def case_music_favorite(self): self.case_if_music_base(True) time.sleep(1) if self.test.find_byclass(TextView, '歌曲', isText=True) is None: self.test.find_byacc(music_video_music_menu).click() time.sleep(0.2) self.test.find_list_byid(music_video_music_menu_title, '歌曲').click() time.sleep(1) tmp_int = random.randint(1, 8) test_name = f'music_{tmp_int}' self._find_music(test_name).click() time.sleep(1) self.test.find_byid(music_video_music_list_nowplay_icon).click() time.sleep(1) self.test.find_byid(music_video_music_list_song_name).click() time.sleep(1) self.test.find_byid(music_video_music_favorite).click() if self.test.if_toast_text('歌曲已添加到播放列表') is None: log('error', '添加到 收藏,未找到 toast') self.driver.press_keycode(4, 0, 0) time.sleep(1) self.test.find_byacc(music_video_music_menu).click() time.sleep(1) self.test.find_list_byid(music_video_music_menu_title, '播放列表').click() time.sleep(1) self._checK_play_list('我的收藏').click() time.sleep(1) tmp = self.test.find_byclass(TextView, test_name) if tmp is None: self.Case.fail(f'列表中没有音乐 {test_name}') def case_music_share(self): self.case_if_music_base(True) time.sleep(1) if self.test.find_byclass(TextView, '歌曲', isText=True) is None: self.test.find_byacc(music_video_music_menu).click() time.sleep(0.2) self.test.find_list_byid(music_video_music_menu_title, '歌曲').click() time.sleep(1) tmp_list = self.test.find_byid_list(music_video_music_indicator_list) tmp_int = random.randint(2, len(tmp_list) - 2) tmp_list[tmp_int].click() time.sleep(0.5) self.test.find_list_byid(ID_title, '分享').click() time.sleep(1) if not self.test.wait_if_activity(Share_Activity): self.Case.fail(f'分享界面未显示') tmp_list = self.test.find_list_byclass(TextView) isBluetooth = False isNFC = False for x in tmp_list: t = x.text if '蓝牙' in t: isBluetooth = True if 'NFC' in t or 'Beam' in t: isNFC = True if isBluetooth and isNFC: time.sleep(1) return if not isNFC: self.Case.fail(f'没有NFC分享 选项,请确认是否需要') if not isBluetooth: self.Case.fail(f'没有蓝牙分享 选项,请确认是否需要') def case_music_bgm_rec_sms(self): self.case_if_music_base(True) time.sleep(1) if self.test.find_byclass(TextView, '歌曲', isText=True) is None: self.test.find_byacc(music_video_music_menu).click() time.sleep(0.2) self.test.find_list_byid(music_video_music_menu_title, '歌曲').click() time.sleep(1) for x in range(5): tmp_int = random.randint(1, 8) test_name = f'music_{tmp_int}' tmp = self._find_music(test_name) if tmp is not None: tmp.click() break time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) messaging_CaseMethod = Messaging_CaseMethod( self.driver, 'case_Messaging_A_test_if_base') messaging_CaseMethod.case_if_send_and_rec_sms() time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) self.case_if_music_base(True) time.sleep(1) self.test.find_byid(music_video_music_list_nowplay_icon).click() time.sleep(1) def case_music_bgm_camera(self): self.case_if_music_base(True) time.sleep(1) if self.test.find_byclass(TextView, '歌曲', isText=True) is None: self.test.find_byacc(music_video_music_menu).click() time.sleep(0.2) self.test.find_list_byid(music_video_music_menu_title, '歌曲').click() time.sleep(1) for x in range(5): tmp_int = random.randint(1, 8) test_name = f'music_{tmp_int}' tmp = self._find_music(test_name) if tmp is not None: tmp.click() break time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) camera_CaseMethod = Camera_CaseMethod(self.driver, 'case_Camera_A_test_if_base') camera_CaseMethod.case_back_front_take_a_picture() time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) self.case_if_music_base(True) time.sleep(1) self.test.find_byid(music_video_music_list_nowplay_icon).click() time.sleep(1) def case_music_bgm_video(self): self.case_if_music_base(True) time.sleep(1) if self.test.find_byclass(TextView, '歌曲', isText=True) is None: self.test.find_byacc(music_video_music_menu).click() time.sleep(0.2) self.test.find_list_byid(music_video_music_menu_title, '歌曲').click() time.sleep(1) for x in range(5): tmp_int = random.randint(1, 8) test_name = f'music_{tmp_int}' tmp = self._find_music(test_name) if tmp is not None: tmp.click() break time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) camera_CaseMethod = Camera_CaseMethod(self.driver, 'case_Camera_A_test_if_base') camera_CaseMethod.case_back_front_take_a_video() time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) self.case_if_music_base(True) time.sleep(1) self.test.find_byid(music_video_music_list_nowplay_icon).click() time.sleep(1) def case_music_bgm_play_film(self): self.case_if_music_base(True) time.sleep(1) if self.test.find_byclass(TextView, '歌曲', isText=True) is None: self.test.find_byacc(music_video_music_menu).click() time.sleep(0.2) self.test.find_list_byid(music_video_music_menu_title, '歌曲').click() time.sleep(1) for x in range(5): tmp_int = random.randint(1, 8) test_name = f'music_{tmp_int}' tmp = self._find_music(test_name) if tmp is not None: tmp.click() break time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) self.case_play_video() time.sleep(1) def case_music_notifications_widget_test(self): self.case_if_music_base(True) time.sleep(1) if self.test.find_byclass(TextView, '歌曲', isText=True) is None: self.test.find_byacc(music_video_music_menu).click() time.sleep(0.2) self.test.find_list_byid(music_video_music_menu_title, '歌曲').click() time.sleep(1) for x in range(5): tmp_int = random.randint(1, 8) test_name = f'music_{tmp_int}' tmp = self._find_music(test_name) if tmp is not None: tmp.click() break time.sleep(1) self.driver.open_notifications() time.sleep(0.5) self.test.find_byid(music_video_music_widget_next).click() time.sleep(1) tmp_text = self.test.find_byid(music_video_music_widget_song_name).text if test_name in tmp_text: self.Case.fail(f'没有更换下一曲') time.sleep(1) self.test.find_byid(music_video_music_widget_prev).click() time.sleep(1) tmp_text_1 = self.test.find_byid( music_video_music_widget_song_name).text if tmp_text in tmp_text_1: self.Case.fail(f'没有更换上一曲') time.sleep(1) self.test.find_byid(music_video_music_widget_pause).click() time.sleep(0.5) self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(0.5) self.Case.assertTrue( self.test.wait_if_activity(music_video_music_acivity), '未检测到音乐界面') time.sleep(0.5) def _checK_play_list(self, key): for x in range(5): tmp = self.test.find_byclass(TextView, key) if tmp is not None: return tmp self.test.swipe_Down(600, 1) time.sleep(0.5) return None
def _assert_source_is_at_end(put: unittest.TestCase, source: ParseSource): put.assertFalse(source.has_current_line, 'There should be no remaining lines in the source') put.assertTrue(source.is_at_eof, 'There should be no remaining data in the source')
from dateutil.relativedelta import relativedelta from unittest import TestCase first_date = datetime(2014,7,25,0,0) # 一次应交金额 money_every_time = 1000 #month = timedelta(day = 30) second_date = first_date + relativedelta(month=1) print(second_date) now = datetime.now() print('今天日期:' + str(now)) lasting_days = now - first_date # print(lasting_days.days) # 截至目前 应交次数( ) times = math.ceil(lasting_days.days/30) now_money_cost = times*money_every_time test = TestCase() test.assertTrue(now_money_cost==5000) # 累积收益 commu_benifit = 84 # 累积收益 日均 benifit_everyday = round(commu_benifit / lasting_days.days,3) print('产品名称为: {}\n\t\t到目前你的收益金额为: {} 元;\n\t\t每天平均收益为: {} 元'.format(product_name, commu_benifit, benifit_everyday))
def test_check_delimiters_1(): tc = TestCase() tc.assertTrue(check_delimiters("()")) tc.assertTrue(check_delimiters("[]")) tc.assertTrue(check_delimiters("{}")) tc.assertTrue(check_delimiters("<>"))
def test_check_delimiters_2(): tc = TestCase() tc.assertTrue(check_delimiters("([])")) tc.assertTrue(check_delimiters("[{}]")) tc.assertTrue(check_delimiters("{<()>}")) tc.assertTrue(check_delimiters("<({[]})>"))
def test_check_delimiters_3(): tc = TestCase() tc.assertTrue(check_delimiters("([] () <> [])")) tc.assertTrue(check_delimiters("[{()} [] (<> <>) {}]")) tc.assertTrue(check_delimiters("{} <> () []")) tc.assertTrue(check_delimiters("<> ([] <()>) <[] [] <> <>>"))
class Gallery_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): """检查是否可以正常启动""" self.driver.activate_app(gallery_Pkg) self.Case.assertTrue(self.test.wait_if_activity(gallery_activity), '启动图库失败,超时5秒未检测到主界面') def case_swipe_view(self): self.case_if_base() time.sleep(1) root_view = self.test.find_byid(gallery_root_view) root_view.click() self.test.swipe_Right(200, 3) self.test.swipe_Left(200, 3) def case_swipe_L_view(self): self.case_if_base() time.sleep(1) self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() self.test.swipe_Right(200, 3) self.test.find_byid(photopage_bottom).click() def case_get_picture_date(self): """返回 hms 时分秒int时间戳,仅相机拍照""" self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) self.test.find_byacc('更多选项').click() tmp = self.test.find_list_byid(gallery_details_title, '详细信息') tmp.click() tmp_text = self.test.find_list_byid(gallery_picture_details_text, '标题').text tmp_time = int(tmp_text.split('_')[2]) return tmp_time def case_get_picture_size(self): """ 返回照片的尺寸,[int , int] :return: tmp_width , tmp_hight """ self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) self.test.find_byacc('更多选项').click() tmp = self.test.find_list_byid(gallery_details_title, '详细信息') tmp.click() tmp_hight = self.test.find_list_byid(gallery_picture_details_text, '高度').text #width tmp_hight = int(tmp_hight.split(' ')[1]) tmp_width = self.test.find_list_byid(gallery_picture_details_text, '宽度').text # width tmp_width = int(tmp_width.split(' ')[1]) return tmp_width, tmp_hight def case_get_picture_flash(self): """ 返回照片是否使用闪光灯 :return: boolean """ self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) self.test.find_byacc('更多选项').click() tmp = self.test.find_list_byid(gallery_details_title, '详细信息') tmp.click() tmp = self.test.find_list_byid(gallery_picture_details_text, '闪光灯').text #width if "未使用" in tmp: return False return True def case_get_title(self): """ 返回照片名称 :return: name(str) """ self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) self.test.find_byacc('更多选项').click() tmp = self.test.find_list_byid(gallery_details_title, '详细信息') tmp.click() tmp_name = self.test.find_list_byid(gallery_picture_details_text, '标题').text #width return tmp_name def case_play_item(self): """预览第一张照片或者视频""" self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) actions = TouchAction(self.driver) actions.press(x=self.test.get_windows_width() / 2, y=self.test.get_windows_height() / 2).release().perform() time.sleep(1) actions.press(x=self.test.get_windows_width() / 2, y=self.test.get_windows_height() / 2).release().perform() time.sleep(5)
def assert_is_null(put: unittest.TestCase, actual: sut.TokenStream): put.assertTrue(actual.is_null, 'is null') put.assertIs(LookAheadState.NULL, actual.look_ahead_state, 'look ahead state')
def sort_dict(d): return sorted(d.items(), key=lambda x: x[1], reverse=True) testd = {3:1,2:2,1:3} # for k,v in testd.items(): # print(k,v) print(list(zip(testd.values(), testd.keys()))) from unittest import TestCase Test = TestCase() print(sort_dict(sort_dict(testd))) Test.assertTrue(sort_dict(testd) == [(1,3),(2,2),(3,1)])
Initially, there is a number N on the chalkboard. On each player's turn, that player makes a move consisting of: Choosing any x with 0 < x < N and N % x == 0. Replacing the number N on the chalkboard with N - x. Also, if a player cannot make a move, they lose the game. Return True if and only if Alice wins the game, assuming both players play optimally. ''' from unittest import TestCase class Solution: ''' T (first player win): 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 T F T F T F T F T F T F T F T F T F T F T F T F T F 64.43% ''' def divisorGame(self, N: int) -> bool: return N % 2 == 0 if __name__ == '__main__': t = TestCase() s = Solution() t.assertTrue(s.divisorGame(2)) t.assertFalse(s.divisorGame(3))
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
from unittest import TestCase tc = TestCase() q = Queue(5) tc.assertEqual(q.data, [None] * 5) for i in range(5): q.enqueue(i) with tc.assertRaises(RuntimeError): q.enqueue(5) for i in range(5): tc.assertEqual(q.dequeue(), i) tc.assertTrue(q.empty()) # In[385]: from unittest import TestCase tc = TestCase() q = Queue(10) for i in range(6): q.enqueue(i) tc.assertEqual(q.data.count(None), 4) for i in range(5):
return False for i in range(len(f)): temp = f[:] del temp[i] return can_make_product(p / f[i], temp) # In[16]: # (5 points) from unittest import TestCase tc = TestCase() tc.assertTrue(can_make_product(10, [2, 5])) tc.assertTrue(can_make_product(10, [2, 3, 4, 5])) tc.assertTrue(can_make_product(10, [3, 4, 2, 5])) tc.assertTrue(can_make_product(10, [10])) tc.assertTrue(can_make_product(81, [2, 2, 3, 3, 4, 9])) tc.assertTrue(can_make_product(66402, [2, 4, 5, 12, 17, 25, 31, 63])) tc.assertFalse(can_make_product(10, [2, 2, 2, 4])) tc.assertFalse(can_make_product(243, [2, 2, 3, 3, 3, 4, 4, 4])) tc.assertFalse(can_make_product(81, [2, 3, 5, 9, 11])) tc.assertFalse(can_make_product(100, [3, 4, 5, 8, 10])) tc.assertFalse(can_make_product(12369, [3, 4, 5, 8, 19, 20, 31])) # ## Block Voting Systems # In voting systems such as the United States' electoral college, voters are assigned different weights which we'll refer to as voting "blocks". This makes it so that a given voter may have a greater or lesser impact on the outcome of a vote. #
def test_check_delimiters_1(): tc = TestCase() tc.assertTrue(check_delimiters('()')) tc.assertTrue(check_delimiters('[]')) tc.assertTrue(check_delimiters('{}')) tc.assertTrue(check_delimiters('<>'))
def sandbox_directory_structure_exists(put: unittest.TestCase, actual: Result): _common_assertions(actual, put) put.assertTrue(actual.partial_result.sds.root_dir.is_dir())
def test_check_delimiters_3(): tc = TestCase() tc.assertTrue(check_delimiters('([] () <> [])')) tc.assertTrue(check_delimiters('[{()} [] (<> <>) {}]')) tc.assertTrue(check_delimiters('{} <> () []')) tc.assertTrue(check_delimiters('<> ([] <()>) <[] [] <> <>>'))
if c == ' ': continue # for string readable if c in ('(', '{', '['): stk.append(c) elif len(stk) > 0: if (stk[-1] == '(' and c == ')' or stk[-1] == '{' and c == '}' or stk[-1] == '[' and c == ']'): stk.pop() else: return False else: return False return len(stk) == 0 if __name__ == '__main__': t = TestCase() s = Solution() t.assertTrue(s.isValid('')) t.assertTrue(s.isValid('()')) t.assertTrue(s.isValid('()[]{}')) t.assertTrue(s.isValid('()[{}]')) t.assertTrue(s.isValid('([{}])')) t.assertTrue(s.isValid('() [{}] [] [[[]]]')) t.assertFalse(s.isValid('(( [{}] [] [[[]]]')) t.assertFalse(s.isValid('(( [{}] [] [[[]]] )')) t.assertTrue(s.isValid('(( [{}] [] [[[]]] ))')) t.assertFalse(s.isValid('([{])')) t.assertFalse(s.isValid('([{]})')) print('OK!')
Left parenthesis '(' must go before the corresponding right parenthesis ')'. '*' could be treated as a single right parenthesis ')' or a single left parenthesis '(' or an empty string. An empty string is also valid. Example 1: Input: "()" Output: True Example 2: Input: "(*)" Output: True Example 3: Input: "(*))" Output: True Note: The string size will be in the range [1, 100]. ''' from typing import List from unittest import TestCase def checkValidString(s: str) -> bool: pass # **)*(* if __name__ == "__main__": test = TestCase() test.assertTrue(checkValidString("(*))")) test.assertTrue(checkValidString("((*)")) test.assertTrue(checkValidString("(*)"))
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
class Doc_CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey self.new_name = TimeUtils.str_HMS_Name() def case_if_base(self, Skip=False): """设置基础,检查是否可以正常启动""" try: self.driver.activate_app(doc_pkg) except: self.test.start_activity(doc_pkg, doc_acivity) self.Case.assertTrue(self.test.wait_if_activity(doc_acivity), '启动 文件管理器 失败,超时5秒未检测到主界面') self.test.set_PORTRAIT() time.sleep(1) def case_check_root_menu(self): self.case_if_base() self.test.find_byacc(doc_root_menu).click() time.sleep(0.2) tmp_list = self.test.find_byid_list(ID_title) isImages = False isVideos = False isAudio = False isRecent = False for x in tmp_list: t = x.text if '最近' in t: isRecent = True continue if '图片' in t: isImages = True continue if '视频' in t: isVideos = True continue if '音频' in t: isAudio = True continue if not isRecent or not isAudio or not isVideos or not isImages: self.Case.fail( f'文件菜单不满足:图片:{isImages},视频:{isVideos},音频:{isAudio},最近:{isRecent}' ) time.sleep(1) def case_new_and_del_folder(self): self.case_if_base() self.test.find_byacc(Menu).click() time.sleep(0.2) tmp_list = self.test.find_byid_list(doc_action_menu) for x in tmp_list: t = x.text if '新建文件夹' in t: x.click() time.sleep(0.5) break tmp_list = self.test.find_list_byclass(Edit_Text) if tmp_list is None: self.Case.fail('文件夹名称输入框不存在') tmp_list[0].clear() tmp_list[0].send_keys(f'doc_{self.new_name}') tmp_list = self.test.find_byclass(Button, '确定').click() time.sleep(0.3) tmp_list = self.test.find_byid_list(ID_title) isNew = False touchAction = TouchAction(self.driver) for y in tmp_list: t = y.text if f'doc_{self.new_name}' in t: isNew = True touchAction.long_press(y) time.sleep(1.5) touchAction.release().perform() break if not isNew: self.Case.fail(f'文件夹不存在:[doc_{self.new_name}]') self.test.find_byid(doc_search_and_del).click() time.sleep(0.3) self.test.find_byclass(Button, '确定').click() time.sleep(1) tmp_list = self.test.find_byid_list(ID_title) if tmp_list is None: return for z in tmp_list: t = z.text if f'doc_{self.new_name}' in t: self.Case.fail(f'doc_{self.new_name},未删除') time.sleep(1) def case_new_and_change_folder(self): self.case_if_base() self.test.find_byacc(Menu).click() time.sleep(0.2) tmp_list = self.test.find_byid_list(doc_action_menu) for x in tmp_list: t = x.text if '新建文件夹' in t: x.click() time.sleep(0.5) break tmp_list = self.test.find_list_byclass(Edit_Text) if tmp_list is None: self.Case.fail('文件夹名称输入框不存在') tmp_list[0].clear() tmp_list[0].send_keys(f'doc_new_{self.new_name}') tmp_list = self.test.find_byclass(Button, '确定').click() time.sleep(0.3) tmp_list = self.test.find_byid_list(ID_title) isNew = False touchAction = TouchAction(self.driver) for y in tmp_list: t = y.text if f'doc_new_{self.new_name}' in t: isNew = True touchAction.long_press(y) time.sleep(1.5) touchAction.release().perform() break if not isNew: self.Case.fail(f'文件夹不存在:[doc_new_{self.new_name}]') self.test.find_byacc(Menu).click() time.sleep(0.2) tmp_list = self.test.find_byid_list(doc_action_menu) for x in tmp_list: t = x.text if '重命名' in t: x.click() time.sleep(0.5) break tmp_list = self.test.find_list_byclass(Edit_Text) if tmp_list is None: self.Case.fail('文件夹名称输入框不存在') tmp_list[0].clear() tmp_list[0].send_keys(f'doc_old_{self.new_name}') tmp_list = self.test.find_byclass(Button, '确定').click() time.sleep(0.3) tmp_list = self.test.find_byid_list(ID_title) isNew = False for y in tmp_list: t = y.text if f'doc_old_{self.new_name}' in t: isNew = True break if not isNew: self.Case.fail(f'文件夹不存在:[doc_old_{self.new_name}]') time.sleep(1) def case_del_music(self): self.case_if_base() self.test.find_byacc(doc_root_menu).click() time.sleep(0.2) tmp_list = self.test.find_byid_list(ID_title) for x in tmp_list: t = x.text if '音频' in t: x.click() time.sleep(0.5) break tmp_list = self.test.find_byid_list(ID_title) touchAction = TouchAction(self.driver) isNew = False for y in tmp_list: t = y.text if f'张含韵' in t: isNew = True y.click() time.sleep(1) break if not isNew: self.Case.fail(f"未找到相关歌曲文件: 张含韵") tmp_list = self.test.find_byid_list(ID_title) for z in tmp_list: t = z.text if f'歌曲' in t: z.click() time.sleep(1) break tmp_list = self.test.find_byid_list(ID_title) for g in tmp_list: t = g.text if f'doc_music' in t: touchAction.long_press(g) time.sleep(1.5) touchAction.release().perform() break time.sleep(0.5) self.test.find_byid(doc_search_and_del).click() time.sleep(0.3) self.test.find_byclass(Button, '确定').click() time.sleep(1) tmp_list = self.test.find_byid_list(ID_title) if tmp_list is None: return for d in tmp_list: t = d.text if 'doc_music' in t: self.Case.fail(f'张含韵 music ,未删除') time.sleep(1)
def test_check_delimiters_2(): tc = TestCase() tc.assertTrue(check_delimiters('([])')) tc.assertTrue(check_delimiters('[{}]')) tc.assertTrue(check_delimiters('{<()>}')) tc.assertTrue(check_delimiters('<({[]})>'))
class CALC_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(calc_pkg) except: self.test.start_activity(calc_pkg, calc_acivity) self.Case.assertTrue(self.test.wait_if_activity(calc_acivity), '启动 计算器 失败,超时5秒未检测到主界面') time.sleep(1) def case_get_add_result(self): self.case_if_base() int_a = random.randint(0, 9) int_b = random.randint(0, 9) time.sleep(0.2) self.test.find_byid(f'{calc_number_test}{int_a}').click() self.test.find_byid(calc_op_add).click() self.test.find_byid(f'{calc_number_test}{int_b}').click() self.test.find_byid(calc_eq).click() time.sleep(0.1) tmp = self.test.find_byid(calc_show_result).text if (int_a + int_b) != int(tmp): self.Case.fail(f'计算结果失败,{int_a} + {int_b} = {tmp}') time.sleep(0.5) self.test.find_byid(calc_clr).click() tmp = self.test.find_byid(calc_show_result).text if tmp not in '': self.Case.fail(f'计算结果未清除') time.sleep(0.5) def case_get_sub_result(self): self.case_if_base() int_a = random.randint(0, 9) int_b = random.randint(0, 9) time.sleep(0.2) self.test.find_byid(f'{calc_number_test}{int_a}').click() self.test.find_byid(calc_op_sub).click() self.test.find_byid(f'{calc_number_test}{int_b}').click() self.test.find_byid(calc_eq).click() time.sleep(0.1) tmp = self.test.find_byid(calc_show_result).text tmp_new = re.search('\d+', tmp).group(0) if int_a >= int_b: if (int_a - int_b) != int(tmp): self.Case.fail( f'计算结果失败 int_a >= int_b: {int_a} - {int_b} = {tmp}') else: try: int(tmp) self.Case.fail( f'计算结果失败 - not in tmp: {int_a} - {int_b} = {tmp}') except ValueError: pass if (int_b - int_a) != int(tmp_new): self.Case.fail(f'计算结果失败 tmp_new: {int_a} - {int_b} = {tmp}') time.sleep(0.5) self.test.find_byid(calc_clr).click() tmp = self.test.find_byid(calc_show_result).text if tmp not in '': self.Case.fail(f'计算结果未清除') time.sleep(0.5) def case_get_mul_result(self): self.case_if_base() int_a = random.randint(0, 9) int_b = random.randint(0, 9) time.sleep(0.2) self.test.find_byid(f'{calc_number_test}{int_a}').click() self.test.find_byid(calc_op_mul).click() self.test.find_byid(f'{calc_number_test}{int_b}').click() self.test.find_byid(calc_eq).click() time.sleep(0.1) tmp = self.test.find_byid(calc_show_result).text if (int_a * int_b) != int(tmp): self.Case.fail(f'计算结果失败: {int_a} * {int_b} = {tmp}') time.sleep(0.5) self.test.find_byid(calc_clr).click() tmp = self.test.find_byid(calc_show_result).text if tmp not in '': self.Case.fail(f'计算结果未清除') time.sleep(0.5) def case_get_div_result(self): self.case_if_base() int_a = random.randint(0, 9) int_b = random.randint(0, 9) time.sleep(0.2) self.test.find_byid(f'{calc_number_test}{int_a}').click() self.test.find_byid(calc_op_div).click() self.test.find_byid(f'{calc_number_test}{int_b}').click() self.test.find_byid(calc_eq).click() time.sleep(0.1) tmp = self.test.find_byid(calc_show_result).text try: tmp = float(tmp) except ValueError: if int_b != 0: self.Case.fail(f'计算结果失败 ValueError: {int_a} / {int_b} = {tmp}') else: return tmp = round(tmp, 2) if round(int_a / int_b, 2) != tmp: self.Case.fail(f'计算结果失败: {int_a} / {int_b} = {tmp}') time.sleep(0.5) self.test.find_byid(calc_clr).click() tmp = self.test.find_byid(calc_show_result).text if tmp not in '': self.Case.fail(f'计算结果未清除') time.sleep(0.5) def case_switch_UI_check(self): self.case_if_base() if self.test.find_byid(calc_number_1) is None: self.Case.fail("未找到‘1’按钮") if self.test.find_byid(calc_number_2) is None: self.Case.fail("未找到‘2’按钮") if self.test.find_byid(calc_number_3) is None: self.Case.fail("未找到‘3’按钮") if self.test.find_byid(calc_number_4) is None: self.Case.fail("未找到‘4’按钮") if self.test.find_byid(calc_number_5) is None: self.Case.fail("未找到‘5’按钮") if self.test.find_byid(calc_number_6) is None: self.Case.fail("未找到‘6’按钮") if self.test.find_byid(calc_number_7) is None: self.Case.fail("未找到‘7’按钮") if self.test.find_byid(calc_number_8) is None: self.Case.fail("未找到‘8’按钮") if self.test.find_byid(calc_number_9) is None: self.Case.fail("未找到‘9’按钮") if self.test.find_byid(calc_eq) is None: self.Case.fail("未找到‘=’按钮") if self.test.find_byid(calc_number_0) is None: self.Case.fail("未找到‘0’按钮") if self.test.find_byid(calc_dec_point) is None: self.Case.fail("未找到点按钮") if self.test.find_byid(calc_del) is None: self.Case.fail("未找到删除按钮") if self.test.find_byid(calc_op_div) is None: self.Case.fail("未找到‘÷’按钮") if self.test.find_byid(calc_op_mul) is None: self.Case.fail("未找到’ב按钮") if self.test.find_byid(calc_op_sub) is None: self.Case.fail("未找到“-”按钮") if self.test.find_byid(calc_op_add) is None: self.Case.fail("未找到“+”按钮") self.test.swipe_Left(600, 1) time.sleep(1) if self.test.find_byid(calc_advanced_INV) is None: self.Case.fail("未找到“INV”按钮") if self.test.find_byid(calc_advanced_DEG) is None: self.Case.fail("未找到“DEG”按钮") if self.test.find_byid(calc_advanced_pct) is None: self.Case.fail("未找到“%”按钮") if self.test.find_byid(calc_advanced_sin) is None: self.Case.fail("未找到“sin”按钮") if self.test.find_byid(calc_advanced_cos) is None: self.Case.fail("未找到“cos”按钮") if self.test.find_byid(calc_advanced_tan) is None: self.Case.fail("未找到“tan”按钮") if self.test.find_byid(calc_advanced_ln) is None: self.Case.fail("未找到“ln”按钮") if self.test.find_byid(calc_advanced_log) is None: self.Case.fail("未找到“log”按钮") if self.test.find_byid(calc_advanced_fact) is None: self.Case.fail("未找到“!”按钮") if self.test.find_byid(calc_advanced_pi) is None: self.Case.fail("未找到“π”按钮") if self.test.find_byid(calc_advanced_e) is None: self.Case.fail("未找到“e”按钮") if self.test.find_byid(calc_advanced_pow) is None: self.Case.fail("未找到“^”按钮") def case_calc_basic_button_check(self): self.case_if_base() for i in range(10): self.test.find_byid(f'{calc_number_test}{i}').click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if f'{i}' not in result: self.Case.fail(f"按钮‘{i}’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_dec_point).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '.' not in result: self.Case.fail("按钮‘.’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_number_0).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '0' in result: self.test.find_byid(calc_op_div).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '÷' not in result: self.Case.fail("按钮‘÷’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_op_mul).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '×' not in result: self.Case.fail("按钮‘×’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_op_sub).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '−' not in result: self.Case.fail("按钮‘-’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_op_add).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '+' not in result: self.Case.fail("按钮‘+’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_eq).click() time.sleep(1) result = self.test.find_byid(calc_show_result).text if '0' in result: more_list = self.test.find_list_byclass(ImageButton) for more in more_list: str_tmp = more.get_attribute('content-desc') if '更多选项' in str_tmp: more.click() time.sleep(1) break text_button_list = self.test.find_list_byclass(TextView) for t in text_button_list: str_tmp = t.text if '在结果中显示前导数' in str_tmp: t.click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) for text in text_list: str_tmp = text.text if '0 (精确)' not in str_tmp: self.Case.fail("结果显示错误") else: self.test.find_byclass(Button, '关闭').click() time.sleep(1) break break more_list = self.test.find_list_byclass(ImageButton) for more in more_list: str_tmp = more.get_attribute('content-desc') if '更多选项' in str_tmp: more.click() time.sleep(1) break text_button_list = self.test.find_list_byclass(TextView) for t in text_button_list: str_tmp = t.text if '以分数形式显示结果' in str_tmp: t.click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) for text in text_list: str_tmp = text.text if '0' not in str_tmp: self.Case.fail("结果显示错误") else: self.test.find_byclass(Button, '关闭').click() time.sleep(1) break break def case_clac_advance_button_check(self): self.case_if_base() self.test.swipe_Left(600, 1) time.sleep(1) INV = self.test.find_byid(calc_advanced_INV) INV.click() time.sleep(1) btext_list = self.test.find_list_byclass(Button) b_flag = True for btext in btext_list: str_tmp = btext.text if f'sin⁻¹' == f'sin' and f'sin' in str_tmp: self.Case.fail("未出现sin⁻¹按钮") b_flag = False continue if f'cos⁻¹' == f'cos' and f'cos' in str_tmp: self.Case.fail("未出现cos⁻¹按钮") b_flag = False continue if f'tan⁻¹' == f'tan' and f'tan' in str_tmp: self.Case.fail("未出现tan⁻¹按钮") b_flag = False continue if f'eˣ' == f'ln' and f'ln' in str_tmp: self.Case.fail("未出现eˣ按钮") b_flag = False continue if f'10ˣ' == f'log' and f'log' in str_tmp: self.Case.fail("未出现10ˣ按钮") b_flag = False continue if f'x²' == f'√' and f'√' in str_tmp: self.Case.fail("未出现x²按钮") b_flag = False break if not b_flag: self.Case.fail("INV 功能不完整") self.test.find_byid(calc_advanced_DEG).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) t_flag = False for t in text_list: str_tmp = t.text if 'DEG' in str_tmp: t_flag = True break if not t_flag: self.Case.fail("DEG 角度切换失败") self.test.find_byid(calc_advanced_DEG).click() time.sleep(1) self.test.find_byid(calc_advanced_pct).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '%' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("% 功能失效") self.test.find_byid(calc_advanced_arcsin).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'sin⁻¹(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("sin⁻¹按钮失效") self.test.find_byid(calc_advanced_arccos).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'cos⁻¹(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("cos⁻¹按钮失效") self.test.find_byid(calc_advanced_arctan).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'tan⁻¹(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("tan⁻¹按钮失败") self.test.find_byid(calc_advanced_exp).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'exp(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("eˣ按钮失效") self.test.find_byid(calc_advacnced_tPow).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '10^' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("10ˣ按钮失效") self.test.find_byid(calc_advanced_fact).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '!' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("!按钮失效") self.test.find_byid(calc_advanced_pi).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'π' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("π按钮失效") self.test.find_byid(calc_advanced_e).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'e' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("e按钮失效") self.test.find_byid(calc_advanced_pow).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '^' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("^按钮失效") self.test.find_byid(calc_advanced_lparen).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '^(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("(按钮失效") self.test.find_byid(calc_advanced_rparen).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if ')' in str_tmp: text_flag = True break if not text_flag: self.Case.fail(")按钮失效") self.test.find_byid(calc_advanced_sqr).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if ')²' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("x²按钮失效") self.test.find_byid(calc_advanced_INV).click() time.sleep(1) self.test.find_byid(calc_advanced_sin).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'sin(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("sin按钮失效") self.test.find_byid(calc_advanced_cos).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'cos(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("cos按钮失效") self.test.find_byid(calc_advanced_tan).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'tan(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("tan按钮失效") self.test.find_byid(calc_advanced_ln).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'ln(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("ln按钮失效") self.test.find_byid(calc_advanced_log).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'log(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("log按钮失效") self.test.find_byid(calc_advanced_sqrt).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '√' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("√按钮失效")
def should_true(test: unittest.TestCase, except_value, real_value): return test.assertTrue(except_value)
temp = s.peek() if temp is not None and delim_openers.index( temp) == delim_closers.index(d): s.pop() else: return False return s.empty() # In[21]: # (1 point) from unittest import TestCase tc = TestCase() tc.assertTrue(check_delimiters('()')) tc.assertTrue(check_delimiters('[]')) tc.assertTrue(check_delimiters('{}')) tc.assertTrue(check_delimiters('<>')) # In[22]: # (1 point) from unittest import TestCase tc = TestCase() tc.assertTrue(check_delimiters('([])')) tc.assertTrue(check_delimiters('[{}]')) tc.assertTrue(check_delimiters('{<()>}')) tc.assertTrue(check_delimiters('<({[]})>'))