Files
wehub-resource-sync caf324b09d
tests / check_code_quality (push) Waiting to run
tests / tests (ubuntu-latest, 3.10) (push) Blocked by required conditions
tests / tests (ubuntu-latest, 3.11) (push) Blocked by required conditions
Deploy "method_comparison" Gradio to Spaces / deploy (push) Waiting to run
Deploy "PEFT shop" Gradio app to Spaces / deploy (push) Waiting to run
tests on transformers main / tests (push) Waiting to run
tests / tests (ubuntu-latest, 3.12) (push) Blocked by required conditions
tests / tests (ubuntu-latest, 3.13) (push) Blocked by required conditions
tests / tests (windows-latest, 3.10) (push) Blocked by required conditions
tests / tests (windows-latest, 3.11) (push) Blocked by required conditions
tests / tests (windows-latest, 3.12) (push) Blocked by required conditions
tests / tests (windows-latest, 3.13) (push) Blocked by required conditions
Secret Leaks / trufflehog (push) Waiting to run
CI security linting / zizmor latest via Cargo (push) Waiting to run
Build documentation / build (push) Failing after 0s
chore: import upstream snapshot with attribution
2026-07-13 13:24:42 +08:00

39 lines
1.4 KiB
Python

import pandas as pd
import pytest
from .sanitizer import parse_and_filter
@pytest.fixture
def df_products():
data = {
'product_id': [101, 102, 103, 104, 105, 106],
'category': ['Electronics', 'Books', 'Electronics', 'Home Goods', 'Books', 'Electronics'],
'price': [799.99, 19.99, 49.50, 120.00, 24.99, 150.00],
'stock': [15, 300, 50, 25, 150, 0]
}
return pd.DataFrame(data)
def test_exploit_fails(df_products):
with pytest.raises(ValueError) as e:
mask1 = parse_and_filter(df_products,
"""price < 50 and @os.system("/bin/echo password")""")
assert 'Invalid filter syntax' in str(e)
@pytest.mark.parametrize('expression,ids', [
("price < 50", [102, 103, 105]),
("product_id in [101, 102]", [101, 102]),
("price < 50 and category == 'Electronics'", [103]),
("stock < 100 or category == 'Home Goods'", [101, 103, 104, 106]),
("(price > 100 and stock < 20) or category == 'Books'", [101, 102, 105, 106]),
("not (price > 50 or stock > 100)", [103]),
("not price > 50", [102, 103, 105]),
("(price < 50) & (category == 'Electronics')", [103]),
("(stock < 100) | (category == 'Home Goods')", [101, 103, 104, 106]),
])
def test_operations(df_products, expression, ids):
mask1 = parse_and_filter(df_products, expression)
assert sorted(df_products[mask1].product_id) == sorted(ids)