60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
from pathlib import Path
|
|
|
|
from pattern_mining import mine_patterns
|
|
from semantic_kernel import index_project
|
|
|
|
|
|
def test_mine_patterns_finds_repeated_table_writes(tmp_path: Path):
|
|
(tmp_path / "module.bsl").write_text(
|
|
"""
|
|
Процедура ПровестиЗаказ()
|
|
Движения.ОстаткиТоваров.Записать();
|
|
КонецПроцедуры
|
|
|
|
Процедура ОтменитьЗаказ()
|
|
Движения.ОстаткиТоваров.Записать();
|
|
КонецПроцедуры
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
snapshot = index_project(tmp_path, project_id="patterns")
|
|
|
|
patterns = mine_patterns(snapshot)
|
|
|
|
repeated_writes = [pattern for pattern in patterns if pattern.kind == "REPEATED_TABLE_WRITE"]
|
|
assert repeated_writes
|
|
assert repeated_writes[0].support == 2
|
|
assert repeated_writes[0].targets[0].name == "ОстаткиТоваров"
|
|
|
|
|
|
def test_mine_patterns_finds_repeated_query_reads(tmp_path: Path):
|
|
(tmp_path / "module.bsl").write_text(
|
|
"""
|
|
Процедура ПроверитьОстатки()
|
|
Запрос = Новый Запрос;
|
|
Запрос.Текст =
|
|
"ВЫБРАТЬ
|
|
Остатки.Номенклатура
|
|
ИЗ
|
|
РегистрНакопления.ОстаткиТоваров КАК Остатки";
|
|
КонецПроцедуры
|
|
|
|
Процедура РассчитатьОстатки()
|
|
Запрос = Новый Запрос;
|
|
Запрос.Текст =
|
|
"ВЫБРАТЬ
|
|
Остатки.Номенклатура
|
|
ИЗ
|
|
РегистрНакопления.ОстаткиТоваров КАК Остатки";
|
|
КонецПроцедуры
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
snapshot = index_project(tmp_path, project_id="patterns")
|
|
|
|
patterns = mine_patterns(snapshot)
|
|
|
|
repeated_reads = [pattern for pattern in patterns if pattern.kind == "REPEATED_TABLE_READ"]
|
|
assert repeated_reads
|
|
assert repeated_reads[0].support == 2
|