Spaces:
Sleeping
Sleeping
Download tests/test_seed_csvs.py from Code-Father/store: direct link, hf CLI and curl.
- Browser
- Download file 11 kB
-
https://huggingface.co/spaces/Code-Father/store/resolve/main/tests/test_seed_csvs.py
- Command line
-
hf download hf://spaces/Code-Father/store/tests/test_seed_csvs.py
-
curl -L -o test_seed_csvs.py https://huggingface.co/spaces/Code-Father/store/resolve/main/tests/test_seed_csvs.py
11 kB
| import csv | |
| import math | |
| from pathlib import Path | |
| DATA_DIR = Path(__file__).resolve().parents[1] / "data" | |
| PLAN_PATH = Path(__file__).resolve().parents[2] / "plan2.md" | |
| EXPECTED_PRODUCTS = [ | |
| "Rice", | |
| "Wheat Flour", | |
| "Other Flours", | |
| "Dals", | |
| "Pulses", | |
| "Salt", | |
| "Sugar", | |
| "Jaggery", | |
| "Cooking Oil", | |
| "Ghee", | |
| "Spices", | |
| "Masalas", | |
| "Dry Fruits", | |
| "Nuts", | |
| "Seeds", | |
| "Poha", | |
| "Suji / Rava", | |
| "Besan", | |
| "Maida", | |
| "Breakfast Cereals", | |
| "Oats", | |
| "Pasta", | |
| "Noodles", | |
| "Vermicelli", | |
| "Ready-to-Cook Mixes", | |
| "Ready-to-Eat Foods", | |
| "Biscuits", | |
| "Cookies", | |
| "Rusk", | |
| "Snacks", | |
| "Namkeen", | |
| "Chips", | |
| "Sweets", | |
| "Chocolates", | |
| "Candies", | |
| "Bakery Products", | |
| "Bread", | |
| "Cakes", | |
| "Jams & Spreads", | |
| "Peanut Butter", | |
| "Honey", | |
| "Pickles", | |
| "Sauces", | |
| "Ketchup", | |
| "Chutneys", | |
| "Vinegar", | |
| "Tea", | |
| "Coffee", | |
| "Health Drinks", | |
| "Soft Drinks", | |
| "Packaged Juices", | |
| "Energy Drinks", | |
| "Bottled Water", | |
| "Dairy Products", | |
| "Milk", | |
| "Curd", | |
| "Butter", | |
| "Paneer", | |
| "Cheese", | |
| "Eggs", | |
| "Frozen Foods", | |
| "Frozen Snacks", | |
| "Frozen Vegetables", | |
| "Fruits", | |
| "Vegetables", | |
| "Leafy Vegetables", | |
| "Exotic Fruits", | |
| "Exotic Vegetables", | |
| "Cut Fruits & Vegetables", | |
| "Sprouts", | |
| "Detergents", | |
| "Fabric Care", | |
| "Dishwash Products", | |
| "Floor Cleaners", | |
| "Toilet Cleaners", | |
| "Bathroom Cleaners", | |
| "Disinfectants", | |
| "Utensil Cleaners", | |
| "Garbage Bags", | |
| "Tissues & Napkins", | |
| "Air Fresheners", | |
| "Bath Soap", | |
| "Handwash", | |
| "Shampoo", | |
| "Hair Oil", | |
| "Toothpaste", | |
| "Toothbrushes", | |
| "Oral Care Products", | |
| "Skincare Products", | |
| "Personal Hygiene Products", | |
| "Sanitary Products", | |
| "Baby Care Products", | |
| "Diapers & Wipes", | |
| "Stationery", | |
| "Notebooks", | |
| "Pens & Pencils", | |
| "Kitchen Tools", | |
| "Storage Containers", | |
| "Kitchen Appliances", | |
| "Household Utility Items", | |
| ] | |
| def read_csv(name: str) -> list[dict[str, str]]: | |
| with (DATA_DIR / name).open(newline="", encoding="utf-8") as handle: | |
| return list(csv.DictReader(handle)) | |
| def header(name: str) -> list[str]: | |
| with (DATA_DIR / name).open(newline="", encoding="utf-8") as handle: | |
| return next(csv.reader(handle)) | |
| def test_required_files_exist() -> None: | |
| expected_files = { | |
| "store_state.csv", | |
| "stock.csv", | |
| "pending_orders.csv", | |
| "seller_profiles.csv", | |
| "market_offers.csv", | |
| "marketing_actions.csv", | |
| } | |
| assert expected_files == {path.name for path in DATA_DIR.glob("*.csv")} | |
| def test_headers_match_contract() -> None: | |
| assert header("store_state.csv") == [ | |
| "day", | |
| "current_daily_expense_inr", | |
| "bank_balance_inr", | |
| "customer_satisfaction", | |
| "order_processing_capacity", | |
| "cumulative_profit_inr", | |
| ] | |
| assert header("stock.csv") == [ | |
| "product_name", | |
| "unit", | |
| "buying_price_inr", | |
| "selling_price_inr", | |
| "demand_score", | |
| "quantity_on_hand", | |
| "stock_value_inr", | |
| ] | |
| assert header("pending_orders.csv") == [ | |
| "order_id", | |
| "product_name", | |
| "quantity", | |
| "seller_name", | |
| "buy_price_inr", | |
| "days_remaining", | |
| "status", | |
| "created_day", | |
| ] | |
| assert header("seller_profiles.csv") == [ | |
| "seller_name", | |
| "timeline_behavior", | |
| "reliability_note", | |
| "default_etd_days", | |
| ] | |
| assert header("market_offers.csv") == [ | |
| "product_name", | |
| "category", | |
| "unit", | |
| "demand_score", | |
| "seller_a_price_inr", | |
| "seller_a_etd_days", | |
| "seller_b_price_inr", | |
| "seller_b_etd_days", | |
| "seller_c_price_inr", | |
| "seller_c_etd_days", | |
| "seller_d_price_inr", | |
| "seller_d_etd_days", | |
| ] | |
| assert header("marketing_actions.csv") == [ | |
| "action_id", | |
| "description", | |
| "customer_satisfaction_delta", | |
| "cost_inr", | |
| "recurring_cost_inr", | |
| "order_processing_capacity_delta", | |
| ] | |
| def test_stock_has_30_rows_and_consistent_values() -> None: | |
| stock_rows = read_csv("stock.csv") | |
| assert len(stock_rows) == 30 | |
| for row in stock_rows: | |
| buying_price = int(row["buying_price_inr"]) | |
| quantity = int(row["quantity_on_hand"]) | |
| stock_value = int(row["stock_value_inr"]) | |
| assert stock_value == buying_price * quantity | |
| total_value = sum(int(r["stock_value_inr"]) for r in stock_rows) | |
| assert 220_000 <= total_value <= 260_000 | |
| def test_store_state_matches_realistic_opening_values() -> None: | |
| rows = read_csv("store_state.csv") | |
| assert rows == [ | |
| { | |
| "day": "1", | |
| "current_daily_expense_inr": "3000", | |
| "bank_balance_inr": "120000", | |
| "customer_satisfaction": "70", | |
| "order_processing_capacity": "500", | |
| "cumulative_profit_inr": "0", | |
| } | |
| ] | |
| def test_perishable_stock_levels_fit_kirana_scale() -> None: | |
| stock = {row["product_name"]: row for row in read_csv("stock.csv")} | |
| assert int(stock["Milk"]["quantity_on_hand"]) <= 120 | |
| assert int(stock["Bread"]["quantity_on_hand"]) <= 50 | |
| assert int(stock["Eggs"]["quantity_on_hand"]) <= 40 | |
| assert int(stock["Vegetables"]["quantity_on_hand"]) <= 80 | |
| assert int(stock["Fruits"]["quantity_on_hand"]) <= 60 | |
| assert int(stock["Bottled Water"]["quantity_on_hand"]) <= 96 | |
| assert int(stock["Biscuits"]["quantity_on_hand"]) <= 80 | |
| def test_stocked_products_exist_in_market_offers() -> None: | |
| market_products = {row["product_name"] for row in read_csv("market_offers.csv")} | |
| for row in read_csv("stock.csv"): | |
| assert row["product_name"] in market_products | |
| def test_pending_orders_starts_empty() -> None: | |
| assert read_csv("pending_orders.csv") == [] | |
| def test_market_offers_contain_all_expected_products() -> None: | |
| market_rows = read_csv("market_offers.csv") | |
| product_names = [row["product_name"] for row in market_rows] | |
| assert product_names == EXPECTED_PRODUCTS | |
| assert len(set(product_names)) == len(EXPECTED_PRODUCTS) | |
| for row in market_rows: | |
| assert row["category"] != "" | |
| assert row["unit"] != "" | |
| for column in ( | |
| "seller_a_price_inr", | |
| "seller_a_etd_days", | |
| "seller_b_price_inr", | |
| "seller_b_etd_days", | |
| "seller_c_price_inr", | |
| "seller_c_etd_days", | |
| "seller_d_price_inr", | |
| "seller_d_etd_days", | |
| ): | |
| assert row[column] != "" | |
| def test_market_offers_have_varied_seller_patterns() -> None: | |
| market_rows = read_csv("market_offers.csv") | |
| etd_patterns = { | |
| ( | |
| row["seller_a_etd_days"], | |
| row["seller_b_etd_days"], | |
| row["seller_c_etd_days"], | |
| row["seller_d_etd_days"], | |
| ) | |
| for row in market_rows | |
| } | |
| assert len(etd_patterns) >= 8 | |
| c_beats_b = sum( | |
| int(row["seller_c_price_inr"]) < int(row["seller_b_price_inr"]) | |
| for row in market_rows | |
| ) | |
| d_beats_b = sum( | |
| int(row["seller_d_price_inr"]) < int(row["seller_b_price_inr"]) | |
| for row in market_rows | |
| ) | |
| a_not_cheapest = sum( | |
| int(row["seller_a_price_inr"]) | |
| > min( | |
| int(row["seller_a_price_inr"]), | |
| int(row["seller_b_price_inr"]), | |
| int(row["seller_c_price_inr"]), | |
| int(row["seller_d_price_inr"]), | |
| ) | |
| for row in market_rows | |
| ) | |
| assert c_beats_b >= 25 | |
| assert d_beats_b >= 25 | |
| assert a_not_cheapest >= 10 | |
| bc_deltas = {int(row["seller_c_price_inr"]) - int(row["seller_b_price_inr"]) for row in market_rows} | |
| bd_deltas = {int(row["seller_d_price_inr"]) - int(row["seller_b_price_inr"]) for row in market_rows} | |
| assert len(bc_deltas) >= 12 | |
| assert len(bd_deltas) >= 12 | |
| def test_marketing_actions_have_15_unique_ids() -> None: | |
| rows = read_csv("marketing_actions.csv") | |
| action_ids = [row["action_id"] for row in rows] | |
| assert len(rows) == 15 | |
| assert len(set(action_ids)) == 15 | |
| def test_marketing_actions_match_realistic_catalog() -> None: | |
| rows = {row["action_id"]: row for row in read_csv("marketing_actions.csv")} | |
| assert rows["7"] == { | |
| "action_id": "7", | |
| "description": "Local delivery partner tie-up", | |
| "customer_satisfaction_delta": "5", | |
| "cost_inr": "5000", | |
| "recurring_cost_inr": "600", | |
| "order_processing_capacity_delta": "40", | |
| } | |
| assert rows["11"] == { | |
| "action_id": "11", | |
| "description": "Open second branch (deposit + fit-out)", | |
| "customer_satisfaction_delta": "12", | |
| "cost_inr": "750000", | |
| "recurring_cost_inr": "3000", | |
| "order_processing_capacity_delta": "350", | |
| } | |
| assert rows["15"] == { | |
| "action_id": "15", | |
| "description": "Always-on targeted social ads", | |
| "customer_satisfaction_delta": "3", | |
| "cost_inr": "4000", | |
| "recurring_cost_inr": "1200", | |
| "order_processing_capacity_delta": "0", | |
| } | |
| def test_doc_scenarios_match_seed_data() -> None: | |
| plan_text = PLAN_PATH.read_text(encoding="utf-8") | |
| stock = {row["product_name"]: row for row in read_csv("stock.csv")} | |
| market = {row["product_name"]: row for row in read_csv("market_offers.csv")} | |
| for phrase in ( | |
| "Rice at `138` vs Seller B at `160`", | |
| "Cooking Oil at `156` vs Seller B at `180`", | |
| "Spices at `345` vs Seller B at `400`", | |
| "Bread at `31` vs Seller B at `35`", | |
| "Eggs at `64` vs Seller B at `72`", | |
| "Curd at `33` vs Seller B at `35`", | |
| "Vegetables at `38` vs Seller B at `40`", | |
| "Always-on targeted social ads", | |
| "Kitchen Appliances", | |
| "Biscuits | 40", | |
| "Bottled Water | 48", | |
| ): | |
| assert phrase in plan_text | |
| assert int(stock["Milk"]["selling_price_inr"]) <= math.ceil(int(stock["Milk"]["buying_price_inr"]) * 1.05) | |
| assert int(stock["Bread"]["selling_price_inr"]) <= math.ceil(int(stock["Bread"]["buying_price_inr"]) * 1.05) | |
| assert int(stock["Eggs"]["selling_price_inr"]) <= math.ceil(int(stock["Eggs"]["buying_price_inr"]) * 1.05) | |
| assert int(stock["Sugar"]["selling_price_inr"]) <= math.ceil(int(stock["Sugar"]["buying_price_inr"]) * 1.06) | |
| assert int(stock["Biscuits"]["quantity_on_hand"]) == 40 | |
| assert int(stock["Bottled Water"]["quantity_on_hand"]) == 48 | |
| assert int(stock["Kitchen Appliances"]["quantity_on_hand"]) == 4 | |
| assert int(market["Rice"]["seller_a_price_inr"]) == 138 | |
| assert int(market["Cooking Oil"]["seller_a_price_inr"]) == 156 | |
| assert int(market["Spices"]["seller_a_price_inr"]) == 345 | |
| assert int(market["Bread"]["seller_c_price_inr"]) == 31 | |
| assert int(market["Eggs"]["seller_c_price_inr"]) == 64 | |
| assert int(market["Curd"]["seller_c_price_inr"]) == 33 | |
| assert int(market["Vegetables"]["seller_c_price_inr"]) == 38 | |