test_contains_link_feature.py
1 import pandas as pd 2 3 from evidently.legacy.features.contains_link_feature import ContainsLink 4 from evidently.legacy.pipeline.column_mapping import ColumnMapping 5 from evidently.legacy.utils.data_preprocessing import create_data_definition 6 7 8 def test_contains_link_feature(): 9 # Initialize the ContainsLink feature generator for column_1 10 feature_generator = ContainsLink("column_1") 11 12 # Sample data with varying texts that contain or don't contain links 13 data = pd.DataFrame( 14 dict( 15 column_1=[ 16 "Check out https://example.com for more info", # Contains a valid link 17 "Visit our website at http://www.test.com.", # Contains a valid link 18 "No link here, just plain text", # No link 19 "Another string without a link", # No link 20 "Here is a malformed link: www.test.com", # Invalid link (missing scheme) 21 ] 22 ) 23 ) 24 25 # Generate the feature 26 result = feature_generator.generate_feature( 27 data=data, 28 data_definition=create_data_definition(None, data, ColumnMapping()), 29 ) 30 31 # Expected result: True for valid links, False otherwise 32 expected_result = pd.DataFrame(dict(column_1=[True, True, False, False, False])) 33 34 # Assert that the generated result matches the expected result 35 assert result.equals(expected_result)