def test_pivot_funcs_df_merge(_create_pivot, join_type, test_case): """Test calling function with DF input attributes.""" func = getattr(getattr(test_case.entity, test_case.provider), test_case.pivot_func) # Test DF input val = enumerate(test_case.value.keys()) in_df = pd.DataFrame(val, columns=["idx", test_case.src_df_col]) in_df["extra_col1"] = "test1" in_df["extra_col2"] = "test2" result_no_merge_df = func(data=in_df, src_column=test_case.src_df_col) result_df = func(data=in_df, src_column=test_case.src_df_col, join=join_type) in_cols = in_df.shape[1] no_merge_cols = result_no_merge_df.shape[1] merge_cols = result_df.shape[1] # merged DF should have result + input cols - join key col check.greater_equal(no_merge_cols + in_cols, merge_cols) if join_type in ("left", "inner"): # inner and left joins should have same or greater length as input check.greater_equal(result_df.shape[0], in_df.shape[0]) # all the keys from the input should be in the merged output for key in in_df[test_case.src_df_col]: check.is_in(key, result_df[test_case.key_col].values) if join_type == "right": # We don't know how many results we get back from right join # (although should not be zero) check.greater(len(result_df), 0) # but all of its key values should be present in input for key in result_df[test_case.key_col].values: check.is_in(key, in_df[test_case.src_df_col].values)
def test_it_fetches_a_time_distance_matrix(ors_client, member_list, meeting_location_list): subject = GroupDistanceCalculator(ors_client, member_list, meeting_location_list) matrix = subject.getMatrix() check.greater(len(matrix['durations']), 0) check.greater(len(matrix['distances']), 0)
def test_misc_functions(_create_pivot_ns): """Test some additional methods of pivot.py.""" check.greater(len(_create_pivot_ns.providers), 2) t_span = TimeSpan(end=datetime.utcnow(), period="1D") _create_pivot_ns.edit_query_time(timespan=t_span) check.equal(_create_pivot_ns.start, t_span.start) check.equal(_create_pivot_ns.end, t_span.end) check.equal(_create_pivot_ns.timespan, t_span)
def test_add_role(self, add_role_page, db, selenium): roleName = '测试角色' roleMark = '测试角色' if db.check_role(roleName): #环境检查 db.del_role(roleName) add_role_page.add_Role(roleName, roleMark) lens = len( selenium.find_elements('xpath', f'//span[text()="{roleName}"]')) ck.greater(lens, 0) #断言 db.del_role(roleName) # 环境清理
def testLenght(self): x = len('nameTEST') a = 1 b = 100 c = range(2, 101) d = 102 check.greater(x, a) check.less_equal(x, b) check.is_in(x, c, "Lenght ok") check.is_not_in(d, c, "Lenght not ok")
def test_classify_frames(): frame_list1 = example_job2.classify_frames() frame_list = example_job1.classify_frames() check.equal(frame_list1[0][0], 0) check.less(frame_list1[0][1], 0.7) check.not_equal(frame_list1[1][0], 5) check.greater(frame_list1[1][1], 0.7) check.equal(frame_list[0][0], 0) check.less(frame_list[0][1], 0.7) check.not_equal(frame_list[1][0], 4) check.greater(frame_list[1][1], 0.7)
def test_entity_instantiation(): """Test that we can instantiate all entities.""" for attrib in dir(entities): attr_cls = getattr(entities, attrib) if (isinstance(attr_cls, type) and issubclass(attr_cls, entities.Entity) and attr_cls != entities.Entity): ent_obj = attr_cls() check.greater(len(ent_obj.properties), 0) # Check that we can access properties without incident for attr in (attr for attr in dir(ent_obj) if not attr.startswith("_")): getattr(ent_obj, attr)
def test_class_methods(): """Test method.""" for _, nblt in nblts.iter_classes(): check.is_not_none(nblt.description()) check.is_not_none(nblt.name()) all_opts = len(nblt.all_options()) check.greater_equal(all_opts, len(nblt.default_options())) check.greater(len(nblt.keywords()), 0) check.greater(len(nblt.entity_types()), 0) metadata = nblt.get_settings(print_settings=False) check.is_not_none(metadata) check.is_in("mod_name", metadata) check.is_in("default_options", metadata) check.is_in("keywords", metadata)
def test_class_doc(): """Test class documentation.""" for _, nblt in nblts.iter_classes(): html_doc = nblt.get_help() check.not_equal(html_doc, "No documentation available.") check.greater(len(html_doc), 100) md_doc = nblt.get_help(fmt="md") html_doc2 = markdown(md_doc) check.equal(html_doc, html_doc2) _html_parser = etree.HTMLParser(recover=False) elem_tree = etree.parse(StringIO(html_doc), _html_parser) check.is_not_none(elem_tree)
def test_read_modules(): """Test method.""" nbklts = discover_modules() check.greater_equal(len(list(nbklts.iter_classes())), 4) # pylint: disable=no-member match, m_count = nblts.azsent.host.HostSummary.match_terms( "host, linux, azure") check.is_true(match) check.equal(m_count, 3) for key, value in nbklts.iter_classes(): check.is_instance(key, str) check.is_true(issubclass(value, Notebooklet)) find_res = find("host windows azure") check.greater(len(find_res), 0) not_found = find("monkey stew") check.equal(len(not_found), 0)
def test_file_browser(): """Function_docstring.""" f_brow = FileBrowser(".", select_cb=_callback) starting_folder = f_brow.current_folder check.greater(len(f_brow.select_file.options), 0) check.greater(len(f_brow.select_folder.options), 0) check.is_in("..", f_brow.select_folder.options) curr_files = f_brow.select_file.options check.equal(curr_files, f_brow.select_file.options) f_brow._open_folder(tgt_folder="msticpy") check.not_equal(curr_files, f_brow.select_file.options) f_brow.txt_path.value = str(starting_folder) f_brow._enter_folder(event=None) check.greater(len(f_brow.select_file.options), 0) f_brow.select_file.selected_index = 1 f_brow._return_file(btn=None) check.equal(file_name, f_brow.file) f_brow.txt_search.value = "*.py" f_brow._search(f_brow.btn_search) check.greater(len(f_brow.select_search.options), 0)
def test_greater(): check.greater(2, 1)
def test_entity_list_piv_functions(_create_pivot_list, entity, expected_funcs): """Test the pivot_funcs property.""" check.greater(len(entity.get_pivot_list()), expected_funcs)
def test_pivot_funcs_df_merge(_create_pivot, join_type, test_case): """Test calling function with DF input attributes.""" func = getattr(getattr(test_case.entity, test_case.provider), test_case.pivot_func) # Test DF input val = test_case.value in_df = pd.DataFrame(val, columns=[test_case.src_df_col]) params = {test_case.func_param: test_case.src_df_col} in_df["extra_col1"] = "test1" in_df["extra_col2"] = "test2" result_no_merge_df = func(data=in_df, **params) if test_case.entity not in (entities.Account, entities.Host): # The IP test uses a list param so we cannot do index joins # with it with pytest.warns(UserWarning): result_df = func(data=in_df, **params, join=join_type) return # should work ok with Account and Host result_df = func(data=in_df, **params, join=join_type) in_cols = in_df.shape[1] no_merge_cols = result_no_merge_df.shape[1] merge_cols = result_df.shape[1] # merged DF should have result + input cols - join key col check.greater_equal(no_merge_cols + in_cols, merge_cols) if join_type in ("left", "inner"): # inner and left joins should have same or greater length as input check.greater_equal(result_df.shape[0], in_df.shape[0]) # all the keys from the input should be in the merged output for row_val in in_df[test_case.src_df_col]: check.is_in(row_val, result_df[test_case.src_df_col].values) if join_type == "right": # We don't know how many results we get back from right join # (although should not be zero) check.greater(len(result_df), 0) # but all of its key values should be present in input for row_val in result_df[test_case.src_df_col].values: check.is_in(row_val, in_df[test_case.src_df_col].values) join_in_data = { 0: "0x3e7", 1: "0xc90e957", 2: "0xc90ea44", 3: "0xc912d62", 4: "0xc913737", 10: "0x3e3", 14: "0x3e4", 15: "0xaddd", 16: "0xafff", 17: "0x3e5", 23: "no_match", } in_df = pd.DataFrame( pd.Series(join_in_data), columns=["TargetLogonId"] ).reset_index() result_no_merge_df = func(data=in_df, **params) result_df = func( data=in_df, **params, join=join_type, left_on="TargetLogonId", right_on="TargetLogonId", ) check.is_not_none(result_df) if join_type in ("inner", "right"): check.equal(len(result_df), len(result_no_merge_df)) for val in join_in_data.values(): if val != "no_match": check.is_in(val, result_df["TargetLogonId"].values) else: check.is_not_in(val, result_df["TargetLogonId"].values) if join_type == "left": check.equal(len(result_df), len(result_no_merge_df) + 1) for val in join_in_data.values(): check.is_in(val, result_df["TargetLogonId"].values)
def check_greater(self, actual, expected, message=None): if message is None: message = "Actual and expected results do not match" check.greater(actual, expected, message)