Files
upstream-mirror db69de1c11
Some checks failed
Frontend / Unit Tests & Coverage (push) Has been skipped
Regenerate POT file (translatable strings) / Regenerate POT file (develop) (push) Failing after 1m13s
Regenerate POT file (translatable strings) / Regenerate POT file (main-hotfix) (push) Failing after 6s
Server / Tests (frappe ${{ matrix.frappe-branch }}) (push) Has been skipped
Server / Resolve frappe matrix (push) Failing after 1s
Frontend / Lint (push) Failing after 1s
Frontend / Production Build (push) Failing after 1s
Server / Coverage Wrap Up (push) Has been skipped
Frontend / Coverage Wrap Up (push) Has been skipped
snapshot of https://github.com/frappe/crm.git (develop, 2026-09-18; blobs > 131072B omitted)
2026-09-18 01:36:01 +05:00

43 lines
1.9 KiB
Python

# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
"""Pure unit tests for config-layer pattern compilation (``config._compile_pattern``).
Fully offline: no DB, no network. Covers the word-boundary fix -- an un-anchored
short substring keyword like "erp" or "api" previously matched inside unrelated
words ("waterproofing", "capital"), causing false industry-classification hits.
"""
from __future__ import annotations
from frappe.tests import UnitTestCase
from crm.domain_enrichment.config import _compile_pattern
class CompilePatternTest(UnitTestCase):
def test_substring_pattern_does_not_match_inside_unrelated_word(self):
erp_rx = _compile_pattern("erp", is_regex=0)
self.assertIsNone(erp_rx.search("Industrial Adhesives, Paints and Waterproofing Solutions"))
self.assertIsNone(erp_rx.search("enterprise value creation"))
def test_substring_pattern_still_matches_standalone_word(self):
erp_rx = _compile_pattern("erp", is_regex=0)
self.assertIsNotNone(erp_rx.search("Our ERP rollout finished on schedule"))
def test_api_pattern_does_not_match_inside_capital_or_rapid(self):
api_rx = _compile_pattern("api", is_regex=0)
self.assertIsNone(api_rx.search("venture capital and rapid growth"))
self.assertIsNotNone(api_rx.search("a public REST API for developers"))
def test_multi_word_phrase_pattern_still_matches(self):
rx = _compile_pattern("enterprise resource planning", is_regex=0)
self.assertIsNotNone(rx.search("our Enterprise Resource Planning suite"))
def test_is_regex_patterns_are_left_unanchored(self):
# An admin-authored regex (is_regex=1) is compiled as-is -- no word-boundary
# wrapping, so existing admin patterns (e.g. social-profile URL regexes) keep
# their exact intended behavior.
rx = _compile_pattern(r"linkedin\.com/(company|in|school)/", is_regex=1)
self.assertIsNotNone(rx.search("https://www.linkedin.com/company/acme"))