Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Food·Ka9# File : tests/test_normalize.py10# Module : tests11# Repository : https://git.spboucher.ai/food-ka12# Created : 2026-08-1213# Last Modified : 2026-08-1214#15# =============================================================================16# AUTHOR & PROFESSIONAL AFFILIATION17# =============================================================================18#19# Author : Simon-Pierre Boucher20# Position : Professor of Finance21# Institution : Université du Québec en Outaouais (UQO)22# Department : Département des sciences administratives23# Organization : SP Boucher24#25# Website : https://spboucher.ai26# Git : https://git.spboucher.ai27#28# =============================================================================29# OFFICIAL CONTACT DIRECTORY30# =============================================================================31#32# General : info@spboucher.ai33# Professional : contact@spboucher.ai34# Direct : simon@spboucher.ai35# Research : research@spboucher.ai36# Development : dev@spboucher.ai37# Support : support@spboucher.ai38# Security/Admin : admin@spboucher.ai39# Notifications : notifications@spboucher.ai40#41# Preferred Contact: contact@spboucher.ai42#43# =============================================================================44# COPYRIGHT & INTELLECTUAL PROPERTY45# =============================================================================46#47# Copyright (c) 202648# Simon-Pierre Boucher49#50# All rights reserved where applicable.51#52# This file is governed by the applicable project license,53# copyright notices, institutional agreements and relevant law.54#55# Unless expressly authorized by the applicable license or56# rights holder, copying, redistribution, sublicensing,57# publication and commercial exploitation are not permitted.58#59# Existing third-party rights and notices remain unaffected.60#61# =============================================================================62# CONFIDENTIALITY & SECURITY63# =============================================================================64#65# Classification : Public66# Distribution : Public repository; use is governed by the project license67# Security Contact : admin@spboucher.ai68#69# Access to this source does not independently grant permission70# to redistribute or disclose confidential materials.71#72# Do not embed credentials, private keys, access tokens,73# certificates or confidential personal information.74#75# =============================================================================76# LICENSE & MAINTENANCE77# =============================================================================78#79# License : None specified (no license file in this repository)80# Maintainer : Simon-Pierre Boucher81# Technical Contact: dev@spboucher.ai82#83# =============================================================================84# END OF SP BOUCHER SOURCE HEADER85# =============================================================================8687from foodka.normalize import (88 normalize_category,89 parse_price,90 parse_size,91 unit_price,92)93from foodka.schema import Product949596def test_parse_price():97 assert parse_price("3,49 $") == 3.4998 assert parse_price("$3.49") == 3.4999 assert parse_price("2 / 5,00 $") == 2.5100 assert parse_price("3 pour 12,00 $") == 4.0101 assert parse_price("99 ¢") == 0.99102 assert parse_price("1 249,99 $") == 1249.99103 assert parse_price(4.29) == 4.29104 assert parse_price("prix en magasin") is None105 assert parse_price(None) is None106107108def test_parse_size():109 assert parse_size("450 g") == (450.0, "g")110 assert parse_size("2 L") == (2000.0, "ml")111 assert parse_size("1,5 L") == (1500.0, "ml")112 assert parse_size("12 x 355 ml") == (4260.0, "ml")113 assert parse_size("6 un") == (6.0, "un")114 assert parse_size("1 lb") == (453.592, "g")115 assert parse_size("") is None116117118def test_unit_price():119 assert unit_price(3.5, "500 g") == (0.7, "100 g")120 assert unit_price(6.0, "2 L") == (0.3, "100 ml")121 assert unit_price(12.0, "6 un") == (2.0, "un")122 assert unit_price(None, "500 g") is None123124125def test_normalize_category():126 assert normalize_category("Fruits et légumes frais") == "Fruits et légumes"127 assert normalize_category("Dairy & Eggs") == "Produits laitiers et œufs"128 assert normalize_category("Boissons gazeuses") == "Boissons"129 assert normalize_category("Surgelés") == "Surgelés"130 assert normalize_category("Mystère") == "Autres"131132133def test_product_finalize_sale():134 p = Product(source="t", external_id="1", url="u", name=" Beurre ",135 price_label="4,99 $", size_label="454 g",136 regular_price=6.49).finalize()137 assert p.price == 4.99138 assert p.on_sale is True139 assert p.unit_price is not None140 assert p.category == "Autres"141142143def test_product_finalize_bogus_regular():144 # prix régulier <= prix courant : pas un solde, on le laisse tomber145 p = Product(source="t", external_id="1", url="u", name="x",146 price=5.0, regular_price=5.0).finalize()147 assert p.regular_price is None148 assert p.on_sale is False149