Download test_sanitizer.py from peft-internal-testing/PEFT-method-comparison-embed: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/peft-internal-testing/PEFT-method-comparison-embed/resolve/main/test_sanitizer.py
- Command line
-
hf download hf://spaces/peft-internal-testing/PEFT-method-comparison-embed/test_sanitizer.py
-
curl -L -o test_sanitizer.py https://huggingface.co/spaces/peft-internal-testing/PEFT-method-comparison-embed/resolve/main/test_sanitizer.py
1.39 kB
| import pandas as pd | |
| import pytest | |
| from .sanitizer import parse_and_filter | |
| 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) | |
| def test_operations(df_products, expression, ids): | |
| mask1 = parse_and_filter(df_products, expression) | |
| assert sorted(df_products[mask1].product_id) == sorted(ids) | |