Best Python code snippet using pandera_python
test_inclusive_metrics_evaluator.py
...31 # Should read: column with some nulls contains a null value32 assert InclusiveMetricsEvaluator(schema, Expressions.is_null("some_nulls")).eval(file)33 # Should skip: non-null column contains no null values34 assert not InclusiveMetricsEvaluator(schema, Expressions.is_null("no_nulls")).eval(file)35def test_required_column(schema, file):36 assert InclusiveMetricsEvaluator(schema, Expressions.not_null("required")).eval(file)37 assert not InclusiveMetricsEvaluator(schema, Expressions.is_null("required")).eval(file)38def test_missing_column(schema, file):39 with raises(RuntimeError):40 InclusiveMetricsEvaluator(schema, Expressions.less_than("missing", 5)).eval(file)41def test_missing_stats(schema, missing_stats, missing_stats_exprs):42 assert InclusiveMetricsEvaluator(schema, missing_stats_exprs).eval(missing_stats)43def test_zero_record_file(schema, empty, zero_rows_exprs):44 assert not InclusiveMetricsEvaluator(schema, zero_rows_exprs).eval(empty)45def test_not(schema, file):46 assert InclusiveMetricsEvaluator(schema, Expressions.not_(Expressions.less_than("id", 5))).eval(file)47 assert not InclusiveMetricsEvaluator(schema,48 Expressions.not_(Expressions.greater_than("id", 5))).eval(file)49def test_and(schema, file):...
test_input_validation.py
Source: test_input_validation.py
1import corna.constants as constant2import os3import pandas as pd4import pytest5from corna import custom_exception6from corna import dataframe_validator7from corna import input_validation8def test_check_if_file_exist():9 dir_path = os.path.dirname(os.path.abspath(__file__))10 file_not_exist_path = os.path.join(dir_path, "test_input_validation_data", "maven_data.py")11 assert dataframe_validator.check_if_file_exist(file_not_exist_path) == False12def test_check_file_empty():13 dir_path = os.path.dirname(os.path.abspath(__file__))14 empty_file_path = os.path.join(dir_path, "test_input_validation_data", "nacorr_test_1.txt")15 assert dataframe_validator.check_file_empty(empty_file_path) == True16def test_read_input_file():17 dir_path = os.path.dirname(os.path.abspath(__file__))18 other_extension_file_path = os.path.join(dir_path, "test_input_validation_data", "nacorr_test_1.pdf")19 with pytest.raises(custom_exception.FileExtensionError) as e:20 dataframe_validator.read_input_file(other_extension_file_path)21 assert e.value.message == 'Only CSV , TXT , XLS ,XLSX file extension are allowed.'22def test_data_frame_empty():23 data_frame=pd.DataFrame()24 assert dataframe_validator.check_df_empty(data_frame) == True25def test_required_column_missing():26 dir_path = os.path.dirname(os.path.abspath(__file__))27 file_path = os.path.join(dir_path, "test_input_validation_data", "test_maven_upload_acetic.csv")28 df = pd.read_csv(file_path)29 test_required_column = ['NaMe','LABEl','Formula','XYZ']30 assert dataframe_validator.check_required_column(df,*test_required_column)[0] == False31def test_check_positive_numerical_value():32 assert input_validation.check_intensity_value(14) == constant.VALID_STATE33 assert input_validation.check_intensity_value(-19) == constant.INTENSITY_STATE_NEGATIVE34 assert input_validation.check_intensity_value('test123') == constant.INTENSITY_STATE_INVALID35def test_check_label_column_format():36 assert input_validation.check_label_column_format('C12 PARENT') == constant.VALID_STATE37 assert input_validation.check_label_column_format('C13-label-2') == constant.VALID_STATE38 assert input_validation.check_label_column_format('C13-2') == constant.LABEL_STATE_INVALID39 assert input_validation.check_label_column_format('C13-label-a') == constant.LABEL_STATE_INVALID40 assert input_validation.check_label_column_format('C11-N15-label-1-2') == constant.LABEL_STATE_INVALID41def test_label_in_formula():42 assert input_validation.check_label_in_formula('C13-label-2','C10H12N5O6P') == constant.VALID_STATE43 assert input_validation.check_label_in_formula('C13-label-6', 'C5H12N5O6P') == constant.LABEL_STATE_NUMBER_MORE_FORMULA44 assert input_validation.check_label_in_formula('C13-label-6', 'H12N5O6P') == \45 constant.LABEL_STATE_NOT_FORMULA46def test_get_label():47 assert input_validation.get_label('C12 PARENT') == {'C': 0, 'N': 0}48 assert input_validation.get_label('C13-label-6') == {'C': 6}49 assert input_validation.get_label('C13N15-label-4-5') == {'C': 4, 'N': 5}50def test_check_formula_is_correct():51 assert input_validation.check_formula_is_correct('C5H12N5O6P') == constant.VALID_STATE52 assert input_validation.check_formula_is_correct('C5H12N5O6PLO') == constant.FORMULA_STATE_INVALID53def test_check_duplicate():54 dir_path = os.path.dirname(os.path.abspath(__file__))55 maven_correct_raw_file = os.path.join(dir_path, "test_input_validation_data",56 "test_maven_upload_acetic.csv")57 maven_df_correct = pd.read_csv(maven_correct_raw_file)58 maven_duplicate_entry_file=os.path.join(dir_path, "test_input_validation_data",59 "test_maven_upload_duplicate_entry.csv")60 maven_df_duplicate_entry=pd.read_csv(maven_duplicate_entry_file)61 print input_validation.check_duplicate(maven_df_duplicate_entry,0,[['Name','Label']])62 print input_validation.check_duplicate(maven_df_correct,0,[['Name','Label']]).empty63def test_check_missing():64 dir_path = os.path.dirname(os.path.abspath(__file__))65 maven_missing_entry_raw_file = os.path.join(dir_path, "test_input_validation_data",66 "test_maven_upload_missing_entry.csv")67 maven_missing_entry_df = pd.read_csv(maven_missing_entry_raw_file)68 assert len(input_validation.check_missing(maven_missing_entry_df)) == 269def test_validator_for_two_column():70 dir_path = os.path.dirname(os.path.abspath(__file__))71 maven_raw_label_not_in_formula_raw_file = os.path.join(dir_path, "test_input_validation_data",72 "test_maven_upload_acetic_label_incorrect.csv")73 maven_df = pd.read_csv(maven_raw_label_not_in_formula_raw_file)74 result_df = input_validation.validator_for_two_column(maven_df,constant.LABEL_COL,constant.FORMULA_COL,75 input_validation.check_label_in_formula)76 assert result_df.iloc[0]['row_number'] == 177def test_validator_column_wise():78 dir_path = os.path.dirname(os.path.abspath(__file__))79 maven_raw_intensity_not_correct_raw_file = os.path.join(dir_path, "test_input_validation_data",80 "test_maven_upload_acetic_intensity_incorrect.csv")81 maven_df = pd.read_csv(maven_raw_intensity_not_correct_raw_file)82 result_df = input_validation.validator_column_wise(maven_df,0,['sample_1'],83 [input_validation.check_intensity_value])84 assert result_df.iloc[0]['state'] == 'negative'85 assert result_df.iloc[1]['state'] == 'invalid_intensity_value'86def test_get_isotope_name():87 assert input_validation.get_isotope_name(['C13','N15']) == ['C','N']88def test_get_istopes_name_and_number():89 label = 'C13N15-label-1-2'90 label_isotopes,label_number = input_validation.get_isotopes_name_and_number(label)91 assert label_isotopes == ['C','N']92 assert label_number == [1,2]93def test_get_split_isotopes():94 joined_isotopes = 'C13N15'...
Check out the latest blogs from LambdaTest on this topic:
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
Have you ever visited a website that only has plain text and images? Most probably, no. It’s because such websites do not exist now. But there was a time when websites only had plain text and images with almost no styling. For the longest time, websites did not focus on user experience. For instance, this is how eBay’s homepage looked in 1999.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!