spb/company-atlas
Public
Python 66.3%
TypeScript 22.7%
JavaScript 8.6%
HTML 1.4%
CSS 0.7%
1"""Industry taxonomy file + deterministic label → slug mapping."""2from __future__ import annotations34import pytest56from companyatlas.registry.industries import (7 industry_index,8 is_valid_slug,9 load_industries,10 map_industry,11 map_label,12 map_sic,13 top_level_of,14 top_level_slugs,15)1617EXPECTED = {18 "software industry": ["software"],19 "Software": ["software"],20 "banking": ["banking"],21 "bank": ["banking"],22 "video game industry": ["gaming"],23 "automotive industry": ["automotive"],24 "insurance": ["insurance"],25 "pharmaceutical industry": ["pharmaceuticals"],26 "semiconductor industry": ["semiconductors"],27 "e-commerce": ["e-commerce"],28 "retail": ["retail"],29 "telecommunications industry": ["telecommunications"],30 "airline": ["airlines"],31 "film industry": ["entertainment"],32 "financial services": ["financial-services"],33 "oil and gas industry": ["oil-gas"],34 "renewable energy": ["renewables"],35 "biotechnology": ["biotechnology"],36 "hospitality industry": ["hospitality"],37 "aerospace manufacturer": ["aerospace-defense"],38 "arms industry": ["defense"],39 "food industry": ["food-beverage"],40 "fashion": ["apparel"],41 "mass media": ["media"],42 "real estate": ["real-estate"],43 "construction industry": ["construction"],44 "steel industry": ["mining"],45 "chemical industry": ["chemicals"],46 "cloud computing": ["cloud-infrastructure"],47 "artificial intelligence": ["artificial-intelligence"],48 "payment system": ["payments"],49 "asset management": ["asset-management"],50 "management consulting": ["consulting"],51 "agriculture": ["agriculture"],52 "robotics": ["robotics"],53 "machinery industry": ["industrial-machinery"],54 "public utility": ["utilities"],55 "glass industry": ["materials"],56 "health care industry": ["healthcare"],57 "medical device": ["medical-devices"],58 "toy industry": ["consumer-goods"],59 "logistics": ["logistics"],60 "shipping": ["shipping"],61 "education": ["education"],62 "tourism": ["travel"],63 "think tank": ["education"], # longest keyword wins over "tank" (defense)64 "cybersecurity": ["cybersecurity"],65 "social media": ["internet"],66}676869@pytest.mark.parametrize(("label", "slugs"), sorted(EXPECTED.items()))70def test_map_label(label: str, slugs: list[str]) -> None:71 assert map_industry(label) == slugs727374def test_unknown_and_empty() -> None:75 assert map_industry("") == []76 assert map_industry(None) == []77 assert map_industry("zzz nothing here") == []78 assert map_label("post-production") == [] # hyphenated words are not split into keywords798081def test_multi_label_order_and_dedupe() -> None:82 assert map_industry(["banking", "insurance", "banking", "software industry"]) == ["banking", "insurance", "software"]83 assert map_industry(["a", "b", "c", "d", "e"] + ["banking"] * 3, limit=1) == ["banking"]848586def test_taxonomy_integrity() -> None:87 inds = load_industries()88 slugs = [i.slug for i in inds]89 assert len(slugs) == len(set(slugs)) >= 4590 for i in inds:91 assert i.name and i.description92 assert len(i.keywords) >= 3, i.slug93 assert i.parent is None or i.parent in slugs94 assert i.parent is None or industry_index()[i.parent].parent is None, "max two levels"95 required = {"technology", "software", "artificial-intelligence", "semiconductors", "cloud-infrastructure", "cybersecurity", "internet",96 "e-commerce", "fintech", "payments", "banking", "insurance", "asset-management", "real-estate", "construction", "retail",97 "consumer-goods", "food-beverage", "apparel", "energy", "oil-gas", "renewables", "utilities", "mining", "chemicals", "materials",98 "manufacturing", "industrial-machinery", "automotive", "aerospace-defense", "transportation", "logistics", "airlines", "shipping",99 "telecommunications", "media", "entertainment", "gaming", "healthcare", "biotechnology", "pharmaceuticals", "medical-devices",100 "hospitality", "travel", "education", "professional-services", "consulting", "agriculture", "robotics", "defense"}101 assert required <= set(slugs)102 assert "technology" in top_level_slugs() and "software" not in top_level_slugs()103 assert top_level_of("software") == "technology" and top_level_of("technology") == "technology"104 assert is_valid_slug("banking") and not is_valid_slug("banks")105106107def test_map_sic() -> None:108 assert map_sic(7372) == "software"109 assert map_sic("3674") == "semiconductors"110 assert map_sic(6021) == "banking"111 assert map_sic(2836) == "biotechnology"112 assert map_sic(4512) == "airlines"113 assert map_sic(1311) == "oil-gas"114 assert map_sic(9999) is None115 assert map_sic(None) is None and map_sic("") is None and map_sic("abc") is None116