I am a Test-Case.
#!/usr/bin/env python3
import io
import subprocess
import tempfile
import unittest
from contextlib import redirect_stdout
from pathlib import Path
import Dings_Gpt_Cmd_Show as Cmd_Show
import Dings_Gpt_Cmd_Graph as Cmd_Graph
import Dings_Gpt_Build as Build
import Dings_Gpt_Completion as Completion
import Dings_Gpt_Graph as Graph
import Dings_Lib_Sm as Sm
def _Write_Text(File_Path: Path, Text: str) -> None:
File_Path.parent.mkdir(parents=True, exist_ok=True)
File_Path.write_text(Text, encoding="utf-8")
def _I_Have_Claim(
Subject_Name: str,
Subject_Number: str,
Predicate_Name: str,
Predicate_Number: str,
Object_Name: str,
Object_Number: str,
) -> dict:
return {
"Subject": {"Dings_Name": Subject_Name, "Dings_Number": Subject_Number},
"Predicate_Base": "I_Have",
"Predicate_Role_Key": Predicate_Number,
"Predicate_Role": {"Dings_Name": Predicate_Name, "Dings_Number": Predicate_Number},
"Object": {"Dings_Name": Object_Name, "Dings_Number": Object_Number},
"Claimer": {"Dings_Name": Subject_Name, "Dings_Number": Subject_Number},
}
class Dings_Gpt_Graph_Tests(unittest.TestCase):
def _Write_Classes_Fixture(Self, Root_Path: Path) -> None:
Repo_Path = Root_Path / ".Dings" / "Repositories" / "300000007"
Repo_Path.mkdir(parents=True)
_Write_Text(
Repo_Path / "640062.md",
"# Domain-specific-Language\n\n"
"I am a [Language](600041.md).\n\n"
"## Also\n\n"
"- I am a [Formal-Language](640000.md).\n"
"- I am a [Tool](250000001.md).\n",
)
_Write_Text(
Repo_Path / "600041.md",
"# Language\n\n"
"I am a [Thing](60003.md).\n",
)
_Write_Text(
Repo_Path / "60003.md",
"# Thing\n\n",
)
_Write_Text(
Repo_Path / "640000.md",
"# Formal-Language\n\n"
"I am a [Language](600041.md).\n",
)
_Write_Text(
Repo_Path / "250000001.md",
"# Tool\n\n"
"I am a [Thing](60003.md).\n",
)
def _Write_Todo_Fixture(Self, Root_Path: Path) -> None:
Repo_Path = Root_Path / ".Dings" / "Repositories" / "300000007"
Repo_Path.mkdir(parents=True)
_Write_Text(
Repo_Path / "60203.md",
"# Todo\n\n"
"I am a [Task](60083.md).\n",
)
_Write_Text(
Repo_Path / "60083.md",
"# Task\n\n",
)
_Write_Text(
Repo_Path / "60003.md",
"# Thing\n\n",
)
_Write_Text(
Repo_Path / "600051.md",
"# Topic\n\n"
"I am a [Thing](60003.md).\n",
)
_Write_Text(
Repo_Path / "60048.md",
"# Name\n\n"
"I am a [Thing](60003.md).\n",
)
_Write_Text(
Repo_Path / "60204.md",
"# Feature\n\n",
)
_Write_Text(
Repo_Path / "270100000.md",
"# Sports\n\n"
"I am a [Thing](60003.md).\n",
)
_Write_Text(
Repo_Path / "270100001.md",
"# Basketball\n\n"
"I am a [Thing](60003.md).\n",
)
_Write_Text(
Repo_Path / "270110000.md",
"# Soccer\n\n"
"I am a [Sports](270100000.md).\n\n"
"## Also\n\n"
"- I am a [Super-Topic](600051.md).\n",
)
_Write_Text(
Repo_Path / "270200000.md",
"# Tennis\n\n"
"I am a [Thing](60003.md).\n",
)
_Write_Text(
Repo_Path / "260030000.md",
"# Botanics\n\n"
"I am a [Thing](60003.md).\n",
)
_Write_Text(
Repo_Path / "260030001.md",
"# Garden-Plant\n\n"
"I am a [Botanics-Plant](260030000.md).\n",
)
_Write_Text(
Repo_Path / "90000000.md",
"# Music\n\n"
"I am a [Thing](60003.md).\n",
)
_Write_Text(
Repo_Path / "91001014.md",
"# Rock-Music\n\n"
"I am a [Thing](60003.md).\n\n"
"## About\n\n"
"- My [Topic](600051.md) is [Music](90000000.md).\n",
)
_Write_Text(
Repo_Path / "180000000.md",
"# Tennis-Club\n\n"
"I am a [Thing](60003.md).\n",
)
_Write_Text(
Repo_Path / "270000011.md",
"# Tennis-Club-Tübingen\n\n"
"I am a [Tennis-Club](180000000.md).\n\n"
"## About\n\n"
"- My [TÜ-Topic](600051.md) is [Tennis](270200000.md).\n",
)
_Write_Text(
Repo_Path / "300101001.md",
"# Dings-Feature-Md-Embedding\n\n"
"I am a [Feature](60204.md).\n\n"
"## Also\n\n"
"- I am a [Todo](60203.md).\n",
)
_Write_Text(
Repo_Path / "300101002.md",
"# Dings-Feature-Sm-Todo-List\n\n"
"I am a [Feature](60204.md).\n\n"
"## Also\n\n"
"- I am a [Todo](60203.md).\n",
)
_Write_Text(
Repo_Path / "300101003.md",
"# Dings-Feature-Browse-Graph\n\n"
"I am a [Feature](60204.md).\n",
)
_Write_Text(
Repo_Path / "300101010.md",
"# Todo-Feature\n\n"
"I am a [Todo](60203.md).\n",
)
_Write_Text(
Repo_Path / "300101004.md",
"# Dings-Feature-Derived-Todo\n\n"
"I am a [Todo-Feature](300101010.md).\n",
)
_Write_Text(
Repo_Path / "4711.md",
"# Super-Topic-Source\n\n"
"I am a [Thing](60003.md).\n\n"
"## About\n\n"
"- My [Super-Topic](600051.md) is [Sports](270100000.md).\n",
)
_Write_Text(
Repo_Path / "4712.md",
"# Topic-Source\n\n"
"I am a [Thing](60003.md).\n\n"
"## About\n\n"
"- My [Topic](600051.md) is [Basketball](270100001.md).\n",
)
_Write_Text(
Repo_Path / "700000001.md",
"# Person-A\n\n"
"I am a [Thing](60003.md).\n\n"
"## About\n\n"
"- My [Name](60048.md) is [Michael](0.md).\n"
"- My [Topic](600051.md) is [Room-Mate](0.md).\n",
)
_Write_Text(
Repo_Path / "700000002.md",
"# Person-B\n\n"
"I am a [Thing](60003.md).\n\n"
"Because our [Informtaticer](0.md) was not able to stream.\n",
)
_Write_Text(
Repo_Path / "70000213.md",
"# Georg_Cantor\n\n"
"I am a [Thing](60003.md).\n\n"
"Some text mentions [Cantor](70000213.md).\n",
)
_Write_Text(
Repo_Path / "70000225.md",
"# Ridley_Scott\n\n"
"I am a [Thing](60003.md).\n",
)
_Write_Text(
Repo_Path / "70000226.md",
"# Cantor-Source\n\n"
"I am a [Thing](60003.md).\n\n"
"Some text mentions [Cantor](70000213.md).\n",
)
_Write_Text(
Repo_Path / "400007354.md",
"# Ein-Bug-Report-LWD-Movie.mov\n\n"
"I am a [Thing](60003.md).\n\n"
"## About\n\n"
"- My [Topic](600051.md) is [Music](90000000.md).\n",
)
_Write_Text(
Repo_Path / "0.md",
"# Michael-Georg_Holzheu\n\n"
"I am a [Thing](60003.md).\n",
)
def _Write_Ambiguous_Super_Topic_Fixture(Self, Root_Path: Path) -> None:
Repo_Path = Root_Path / ".Dings" / "Repositories" / "300000007"
_Write_Text(
Repo_Path / "4713.md",
"# Ambiguous-Super-Topic-Source\n\n"
"I am a [Thing](60003.md).\n\n"
"## About\n\n"
"- My [Super-Topic](60203.md) is [Dings-Feature-Md-Embedding](300101001.md).\n",
)
def _Write_All_Dings_Sm2_For_Todo_Fixture(Self, Root_Path: Path) -> None:
Workdir_Path = Root_Path / "Work-Dir"
Dings_File_Map = Build._Get_Dings_File_Map(Root_Path=Root_Path)
Sm_Dict_List = []
for Dings_Number in sorted(Dings_File_Map.keys(), key=lambda Value: int(Value)):
Sm2_Data = Build._Ensure_Sm2_Json_From_Dings_Number(
Root_Path=Root_Path,
Dings_Number=Dings_Number,
Workdir_Path=Workdir_Path,
Dings_File_Map=Dings_File_Map,
)
Sm_Dict = Sm2_Data.get("Sm_Dict") or {}
if isinstance(Sm_Dict, dict):
Sm_Dict_List.append(Sm_Dict)
All_Dings_Sm2_Dict = Sm._Build_All_Dings_Sm_Dict(
Sm_Dict_List=Sm_Dict_List,
Dings_File_Name="All-Dings.sm2.json",
)
Build._Write_Sm_Json_File(
Output_Path=Build._Get_All_Dings_Sm2_Json_File_Path(Workdir_Path=Workdir_Path),
Sm_Dict=All_Dings_Sm2_Dict,
)
def test_graph_classes_builds_gr_result_from_sm1_main_base_class_chain(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
Gr_Dict = Graph._Build_Classes_Gr_From_Dings_Number(
Root_Path=Root_Path,
Dings_Number="640062",
Class_Type="main",
)
Self.assertEqual(Gr_Dict["Channel"], "gr")
Self.assertEqual(Gr_Dict["Source_Channel"], "sm1")
Self.assertEqual(Gr_Dict["Source_Field"], "Dings_SM_Base_Class_Main")
Self.assertEqual(Gr_Dict["Graph_View"], "Class_Hierarchy")
Self.assertEqual(Gr_Dict["Edge_Type"], "Base_Class")
Self.assertEqual(Gr_Dict["Class_Type"], "main")
Self.assertEqual(Gr_Dict["Class_Type_List"], ["main"])
Self.assertEqual(Gr_Dict["Root_Dings_Number"], "640062")
Self.assertEqual(
Gr_Dict["Graph_Node_List"],
[
{"Dings_Number": "640062", "Dings_Name": "Domain-specific-Language"},
{"Dings_Number": "600041", "Dings_Name": "Language"},
{"Dings_Number": "60003", "Dings_Name": "Thing"},
],
)
Self.assertEqual(
Gr_Dict["Graph_Edge_List"],
[
{
"Source_Dings_Number": "640062",
"Target_Dings_Number": "600041",
"Edge_Type": "Base_Class",
"Class_Type": "main",
"Chain_Type": "main",
"Source_Channel": "sm1",
"Source_Field": "Dings_SM_Base_Class_Main",
},
{
"Source_Dings_Number": "600041",
"Target_Dings_Number": "60003",
"Edge_Type": "Base_Class",
"Class_Type": "main",
"Chain_Type": "main",
"Source_Channel": "sm1",
"Source_Field": "Dings_SM_Base_Class_Main",
},
],
)
def test_graph_classes_defaults_to_all(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Graph._Cmd_Graph(["-root", str(Root_Path), "Classes", "640062"])
Output = Stdout.getvalue()
Self.assertIn("Main:\n\n\u2514\u2500\u2500 Language (600041)", Output)
Self.assertIn("Also:\n\n\u251c\u2500\u2500 Formal-Language (640000)", Output)
def test_graph_classes_without_selection_renders_all_dings_with_separator(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Graph._Cmd_Graph(["-root", str(Root_Path), "Classes", "-type", "main"])
Output = Stdout.getvalue()
Self.assertIn("# Thing (60003)", Output)
Self.assertIn("# Language (600041)", Output)
Self.assertIn("# Domain-specific-Language (640062)", Output)
Self.assertIn("\n---\n# Language (600041)", Output)
Self.assertTrue(Output.rstrip().endswith("---"))
def test_graph_classes_selection_renders_selected_dings(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Graph._Cmd_Graph(["-root", str(Root_Path), "Classes", "-type", "main", "60003,640062"])
Output = Stdout.getvalue()
Self.assertIn("# Thing (60003)", Output)
Self.assertIn("# Domain-specific-Language (640062)", Output)
Self.assertNotIn("# Language (600041)", Output)
Self.assertIn("\n---\n# Domain-specific-Language (640062)", Output)
Self.assertTrue(Output.rstrip().endswith("---"))
def test_graph_classes_rejects_invalid_selection(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
with Self.assertRaises(SystemExit):
Cmd_Graph._Cmd_Graph(["-root", str(Root_Path), "Classes", "not-a-dings"])
def test_show_sm_dings_rejects_include_exclude_selection(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
with Self.assertRaises(SystemExit) as Context:
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "dings", "60003,640062"])
Self.assertIn("Unknown Dings-Name: 60003,640062", str(Context.exception))
def test_show_sm_accepts_md_suffix_selection(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "dings", "640062.md"])
Output = Stdout.getvalue()
Self.assertIn("Dings: [Domain-specific-Language](640062.md)", Output)
def test_all_dings_sm2_persists_class_member_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
All_Dings_Sm2_Dict = Build._Read_Sm_Json_File(
File_Path=Build._Get_All_Dings_Sm2_Json_File_Path(Workdir_Path=Root_Path / "Work-Dir"),
)
Class_Member_Map = All_Dings_Sm2_Dict["Dings_SM_Class_Member_Map"]
Self.assertEqual(
Class_Member_Map["60203"],
[
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
{"Dings_Name": "Dings-Feature-Sm-Todo-List", "Dings_Number": "300101002"},
{"Dings_Name": "Dings-Feature-Derived-Todo", "Dings_Number": "300101004"},
{"Dings_Name": "Todo-Feature", "Dings_Number": "300101010"},
],
)
Self.assertEqual(
Class_Member_Map["Super-Topic#600051"],
[
{"Dings_Name": "Sports", "Dings_Number": "270100000"},
{"Dings_Name": "Soccer", "Dings_Number": "270110000"},
],
)
Self.assertEqual(
Class_Member_Map["TÜ-Topic#600051"],
[
{"Dings_Name": "Tennis", "Dings_Number": "270200000"},
],
)
Self.assertIn({"Dings_Name": "Sports", "Dings_Number": "270100000"}, Class_Member_Map["600051"])
Self.assertIn({"Dings_Name": "Soccer", "Dings_Number": "270110000"}, Class_Member_Map["600051"])
Self.assertIn({"Dings_Name": "Basketball", "Dings_Number": "270100001"}, Class_Member_Map["600051"])
Self.assertIn({"Dings_Name": "Tennis", "Dings_Number": "270200000"}, Class_Member_Map["600051"])
Virtual_Class_Map = {
str(Virtual_Class_Dict.get("Virtual_Class_Key") or ""): Virtual_Class_Dict
for Virtual_Class_Dict in All_Dings_Sm2_Dict["Dings_SM_Virtual_Class_List"]
}
Self.assertEqual(
Virtual_Class_Map["Super-Topic#600051"]["Base_Class"],
{"Dings_Name": "Topic", "Dings_Number": "600051"},
)
Self.assertIn(
{
"Source_Dings": "4711",
"Source_Ref": {"Dings_Name": "Super-Topic", "Dings_Number": "600051"},
},
Virtual_Class_Map["Super-Topic#600051"]["Source_Refs"],
)
Self.assertIn(
{
"Source_Dings": "270110000",
"Source_Ref": {"Dings_Name": "Super-Topic", "Dings_Number": "600051"},
},
Virtual_Class_Map["Super-Topic#600051"]["Source_Refs"],
)
Self.assertEqual(
Virtual_Class_Map["TÜ-Topic#600051"]["Base_Class"],
{"Dings_Name": "Topic", "Dings_Number": "600051"},
)
Self.assertEqual(
All_Dings_Sm2_Dict["Dings_SM_Relation_Source_Map"]["TÜ-Topic#600051"]["270200000"],
[
{"Dings_Name": "Tennis-Club-Tübingen", "Dings_Number": "270000011"},
],
)
Self.assertEqual(
All_Dings_Sm2_Dict["Dings_SM_Relation_Source_Map"]["600051"]["270200000"],
[
{"Dings_Name": "Tennis-Club-Tübingen", "Dings_Number": "270000011"},
],
)
Self.assertIn(
{"Dings_Name": "Soccer", "Dings_Number": "270110000"},
All_Dings_Sm2_Dict["Dings_SM_Relation_Source_Map"]["Super-Topic#600051"]["270100000"],
)
Claim_By_Subject_Map = All_Dings_Sm2_Dict["Dings_SM_Claim_By_Subject_Map"]
Self.assertIn(
{
"Subject": {"Dings_Name": "Tennis-Club-Tübingen", "Dings_Number": "270000011"},
"Predicate_Base": "I_Have",
"Predicate_Role_Key": "TÜ-Topic#600051",
"Predicate_Role": {"Dings_Name": "TÜ-Topic", "Dings_Number": "600051"},
"Object": {"Dings_Name": "Tennis", "Dings_Number": "270200000"},
"Claimer": {"Dings_Name": "Tennis-Club-Tübingen", "Dings_Number": "270000011"},
"Line_Number": 7,
},
Claim_By_Subject_Map["270000011"],
)
Self.assertNotIn(
{
"Subject": {"Dings_Name": "Tennis-Club-Tübingen", "Dings_Number": "270000011"},
"Predicate_Base": "I_Have",
"Predicate_Role_Key": "600051",
"Predicate_Role": {"Dings_Name": "Topic", "Dings_Number": "600051"},
"Object": {"Dings_Name": "Tennis", "Dings_Number": "270200000"},
"Claimer": {"Dings_Name": "Tennis-Club-Tübingen", "Dings_Number": "270000011"},
"Line_Number": 7,
},
Claim_By_Subject_Map["270000011"],
)
Self.assertIn(
{
"Subject": {"Dings_Name": "Person-A", "Dings_Number": "700000001"},
"Predicate_Base": "I_Have",
"Predicate_Role_Key": "60048",
"Predicate_Role": {"Dings_Name": "Name", "Dings_Number": "60048"},
"Object": {"Dings_Name": "Michael-Georg_Holzheu", "Dings_Number": "0"},
"Claimer": {"Dings_Name": "Person-A", "Dings_Number": "700000001"},
"Line_Number": 7,
},
Claim_By_Subject_Map["700000001"],
)
Self.assertIn(
{
"Subject": {"Dings_Name": "Person-A", "Dings_Number": "700000001"},
"Predicate_Base": "I_Have",
"Predicate_Role_Key": "600051",
"Predicate_Role": {"Dings_Name": "Topic", "Dings_Number": "600051"},
"Object": {"Dings_Name": "Michael-Georg_Holzheu", "Dings_Number": "0"},
"Claimer": {"Dings_Name": "Person-A", "Dings_Number": "700000001"},
"Line_Number": 8,
},
Claim_By_Subject_Map["700000001"],
)
Self.assertIn(
{
"Subject": {"Dings_Name": "Soccer", "Dings_Number": "270110000"},
"Predicate_Base": "I_Am",
"Predicate_Role_Key": "",
"Predicate_Role": {},
"Object": {"Dings_Name": "Super-Topic", "Dings_Number": "600051"},
"Claimer": {"Dings_Name": "Soccer", "Dings_Number": "270110000"},
},
Claim_By_Subject_Map["270110000"],
)
Self.assertIn("Dings_SM_Claim_By_Predicate_Map", All_Dings_Sm2_Dict)
Self.assertIn("Dings_SM_Claim_By_Object_Map", All_Dings_Sm2_Dict)
Self.assertIn("Dings_SM_Claim_By_Claimer_Map", All_Dings_Sm2_Dict)
Target_Virtual_Name_Map = All_Dings_Sm2_Dict["Dings_SM_Target_Virtual_Name_Map"]
Self.assertEqual(
Target_Virtual_Name_Map["0"]["Remote_Names"],
[
{
"Context_Key": "600051",
"Context_Class": {"Dings_Name": "Topic", "Dings_Number": "600051"},
"Dings_Ref": {"Dings_Name": "Room-Mate", "Dings_Number": "0"},
"Count": 1,
"From": {"Dings_Name": "Person-A", "Dings_Number": "700000001"},
"Source_Refs": [
{
"Source_Dings": "700000001",
"Source_Ref": {"Dings_Name": "Room-Mate", "Dings_Number": "0"},
"Line_Number": 8,
},
],
},
{
"Context_Key": "60048",
"Context_Class": {"Dings_Name": "Name", "Dings_Number": "60048"},
"Dings_Ref": {"Dings_Name": "Michael", "Dings_Number": "0"},
"Count": 1,
"From": {"Dings_Name": "Person-A", "Dings_Number": "700000001"},
"Source_Refs": [
{
"Source_Dings": "700000001",
"Source_Ref": {"Dings_Name": "Michael", "Dings_Number": "0"},
"Line_Number": 7,
},
],
},
{
"Context_Key": "Observed_Ref_Label",
"Context_Class": {"Dings_Name": "Observed-Ref-Label", "Dings_Number": ""},
"Dings_Ref": {"Dings_Name": "Informtaticer", "Dings_Number": "0"},
"Count": 1,
"From": {"Dings_Name": "Person-B", "Dings_Number": "700000002"},
"Source_Refs": [
{
"Source_Dings": "700000002",
"Source_Ref": {"Dings_Name": "Informtaticer", "Dings_Number": "0"},
},
],
},
],
)
def test_show_sm_list_todo_reads_class_member_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Workdir_Path = Root_Path / "Work-Dir"
Build._Write_Sm_Json_File(
Output_Path=Build._Get_All_Dings_Sm2_Json_File_Path(Workdir_Path=Workdir_Path),
Sm_Dict={
"Dings_File": "All-Dings.sm2.json",
"Dings_List": [
{"Dings_Name": "Todo", "Dings_Number": "60203"},
],
"Dings_SM_Virtual_Class_List": [],
"Dings_SM_Class_Member_Map": {
"60203": [
{"Dings_Name": "Persisted-Todo", "Dings_Number": "123"},
],
},
"Dings_SM_Relation_Source_Map": {},
},
)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "Todo"])
Output = Stdout.getvalue()
Self.assertEqual(Output, "[Todo](60203.md):\n [Persisted-Todo](123.md)\n")
def test_show_sm_list_todo_ref_reads_class_member_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Workdir_Path = Root_Path / "Work-Dir"
Build._Write_Sm_Json_File(
Output_Path=Build._Get_All_Dings_Sm2_Json_File_Path(Workdir_Path=Workdir_Path),
Sm_Dict={
"Dings_File": "All-Dings.sm2.json",
"Dings_List": [
{"Dings_Name": "Todo", "Dings_Number": "60203"},
],
"Dings_SM_Virtual_Class_List": [],
"Dings_SM_Class_Member_Map": {
"60203": [
{"Dings_Name": "Persisted-Todo", "Dings_Number": "123"},
],
},
"Dings_SM_Relation_Source_Map": {},
},
)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "[Todo](60203.md)"])
Output = Stdout.getvalue()
Self.assertEqual(Output, "[Todo](60203.md):\n [Persisted-Todo](123.md)\n")
def test_show_sm_list_target_where_intersects_class_and_relation_maps(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Workdir_Path = Root_Path / "Work-Dir"
Build._Write_Sm_Json_File(
Output_Path=Build._Get_All_Dings_Sm2_Json_File_Path(Workdir_Path=Workdir_Path),
Sm_Dict={
"Dings_File": "All-Dings.sm2.json",
"Dings_List": [
{"Dings_Name": "Todo", "Dings_Number": "60203"},
{"Dings_Name": "State", "Dings_Number": "60069"},
{"Dings_Name": "State_New", "Dings_Number": "60206"},
{"Dings_Name": "State_Started", "Dings_Number": "60207"},
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
{"Dings_Name": "Dings-Feature-Sm-Todo-List", "Dings_Number": "300101002"},
],
"Dings_SM_Virtual_Class_List": [],
"Dings_SM_Class_Member_Map": {
"60203": [
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
{"Dings_Name": "Dings-Feature-Sm-Todo-List", "Dings_Number": "300101002"},
],
},
"Dings_SM_Relation_Source_Map": {
"60069": {
"60206": [
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
{"Dings_Name": "Non-Todo-With-State", "Dings_Number": "999"},
],
"60207": [
{"Dings_Name": "Dings-Feature-Sm-Todo-List", "Dings_Number": "300101002"},
],
},
},
"Dings_SM_Claim_By_Claimer_Map": {
"300101001": [
_I_Have_Claim("Dings-Feature-Md-Embedding", "300101001", "State", "60069", "State_New", "60206"),
],
"300101002": [
_I_Have_Claim("Dings-Feature-Sm-Todo-List", "300101002", "State", "60069", "State_Started", "60207"),
],
"999": [
_I_Have_Claim("Non-Todo-With-State", "999", "State", "60069", "State_New", "60206"),
],
},
},
)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "Todo", "where", "State=State_New"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"[Todo](60203.md) where [State](60069.md)=[State_New](60206.md):\n"
" [Dings-Feature-Md-Embedding](300101001.md)\n",
)
def test_show_sm_list_where_reads_relation_source_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Workdir_Path = Root_Path / "Work-Dir"
Build._Write_Sm_Json_File(
Output_Path=Build._Get_All_Dings_Sm2_Json_File_Path(Workdir_Path=Workdir_Path),
Sm_Dict={
"Dings_File": "All-Dings.sm2.json",
"Dings_List": [
{"Dings_Name": "State", "Dings_Number": "60069"},
{"Dings_Name": "State_New", "Dings_Number": "60206"},
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
],
"Dings_SM_Virtual_Class_List": [],
"Dings_SM_Class_Member_Map": {},
"Dings_SM_Relation_Source_Map": {
"60069": {
"60206": [
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
],
},
},
"Dings_SM_Claim_By_Claimer_Map": {
"300101001": [
_I_Have_Claim("Dings-Feature-Md-Embedding", "300101001", "State", "60069", "State_New", "60206"),
],
},
},
)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "where", "State=State_New"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"where [State](60069.md)=[State_New](60206.md):\n"
" [Dings-Feature-Md-Embedding](300101001.md)\n",
)
def test_show_sm_list_target_where_object_wildcard_shows_values(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Workdir_Path = Root_Path / "Work-Dir"
Build._Write_Sm_Json_File(
Output_Path=Build._Get_All_Dings_Sm2_Json_File_Path(Workdir_Path=Workdir_Path),
Sm_Dict={
"Dings_File": "All-Dings.sm2.json",
"Dings_List": [
{"Dings_Name": "Todo", "Dings_Number": "60203"},
{"Dings_Name": "State", "Dings_Number": "60069"},
{"Dings_Name": "State_New", "Dings_Number": "60206"},
{"Dings_Name": "State_Started", "Dings_Number": "60207"},
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
{"Dings_Name": "Dings-Feature-Sm-Todo-List", "Dings_Number": "300101002"},
],
"Dings_SM_Virtual_Class_List": [],
"Dings_SM_Class_Member_Map": {
"60203": [
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
{"Dings_Name": "Dings-Feature-Sm-Todo-List", "Dings_Number": "300101002"},
],
},
"Dings_SM_Relation_Source_Map": {
"60069": {
"60206": [
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
],
"60207": [
{"Dings_Name": "Dings-Feature-Sm-Todo-List", "Dings_Number": "300101002"},
],
},
},
"Dings_SM_Claim_By_Claimer_Map": {
"300101001": [
_I_Have_Claim("Dings-Feature-Md-Embedding", "300101001", "State", "60069", "State_New", "60206"),
],
"300101002": [
_I_Have_Claim("Dings-Feature-Sm-Todo-List", "300101002", "State", "60069", "State_Started", "60207"),
],
},
},
)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "Todo", "where", "State=*"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"[Todo](60203.md) where [State](60069.md)=*:\n"
" [Dings-Feature-Md-Embedding](300101001.md) [State](60069.md)=[State_New](60206.md)\n"
" [Dings-Feature-Sm-Todo-List](300101002.md) [State](60069.md)=[State_Started](60207.md)\n",
)
def test_show_sm_list_target_where_predicate_wildcard_shows_relations(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Workdir_Path = Root_Path / "Work-Dir"
Build._Write_Sm_Json_File(
Output_Path=Build._Get_All_Dings_Sm2_Json_File_Path(Workdir_Path=Workdir_Path),
Sm_Dict={
"Dings_File": "All-Dings.sm2.json",
"Dings_List": [
{"Dings_Name": "Todo", "Dings_Number": "60203"},
{"Dings_Name": "Abstraction", "Dings_Number": "60056"},
{"Dings_Name": "State", "Dings_Number": "60069"},
{"Dings_Name": "State_New", "Dings_Number": "60206"},
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
],
"Dings_SM_Virtual_Class_List": [],
"Dings_SM_Class_Member_Map": {
"60203": [
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
],
},
"Dings_SM_Relation_Source_Map": {
"60056": {
"60206": [
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
],
},
"60069": {
"60206": [
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
],
},
},
"Dings_SM_Claim_By_Claimer_Map": {
"300101001": [
_I_Have_Claim("Dings-Feature-Md-Embedding", "300101001", "State", "60069", "State_New", "60206"),
],
},
},
)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "Todo", "where", "*=State_New"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"[Todo](60203.md) where *=[State_New](60206.md):\n"
" [Dings-Feature-Md-Embedding](300101001.md) [State](60069.md)=[State_New](60206.md)\n",
)
Self.assertNotIn("[Abstraction](60056.md)=[State_New](60206.md)", Output)
def test_show_sm_list_target_where_all_wildcards_shows_relation_blocks(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Workdir_Path = Root_Path / "Work-Dir"
Build._Write_Sm_Json_File(
Output_Path=Build._Get_All_Dings_Sm2_Json_File_Path(Workdir_Path=Workdir_Path),
Sm_Dict={
"Dings_File": "All-Dings.sm2.json",
"Dings_List": [
{"Dings_Name": "Todo", "Dings_Number": "60203"},
{"Dings_Name": "Abstraction", "Dings_Number": "60056"},
{"Dings_Name": "State", "Dings_Number": "60069"},
{"Dings_Name": "State_New", "Dings_Number": "60206"},
{"Dings_Name": "State_Started", "Dings_Number": "60207"},
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
{"Dings_Name": "Dings-Feature-Sm-Todo-List", "Dings_Number": "300101002"},
],
"Dings_SM_Virtual_Class_List": [],
"Dings_SM_Class_Member_Map": {
"60203": [
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
{"Dings_Name": "Dings-Feature-Sm-Todo-List", "Dings_Number": "300101002"},
],
},
"Dings_SM_Relation_Source_Map": {
"60056": {
"60206": [
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
],
},
"60069": {
"60206": [
{"Dings_Name": "Dings-Feature-Md-Embedding", "Dings_Number": "300101001"},
],
"60207": [
{"Dings_Name": "Dings-Feature-Sm-Todo-List", "Dings_Number": "300101002"},
],
},
},
"Dings_SM_Claim_By_Claimer_Map": {
"300101001": [
_I_Have_Claim("Dings-Feature-Md-Embedding", "300101001", "State", "60069", "State_New", "60206"),
],
"300101002": [
_I_Have_Claim("Dings-Feature-Sm-Todo-List", "300101002", "State", "60069", "State_Started", "60207"),
],
},
},
)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "Todo", "where", "*=*"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"[Todo](60203.md) where *=*:\n"
" [Dings-Feature-Md-Embedding](300101001.md)\n"
" [State](60069.md)=[State_New](60206.md)\n"
"\n"
" [Dings-Feature-Sm-Todo-List](300101002.md)\n"
" [State](60069.md)=[State_Started](60207.md)\n",
)
Self.assertNotIn("[Abstraction](60056.md)=[State_New](60206.md)", Output)
def test_show_sm_list_where_rejects_missing_predicate_or_object(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
for Relation_Text in ["State=", "=State_New", "State"]:
with Self.subTest(Relation_Text=Relation_Text):
with Self.assertRaises(SystemExit) as Context:
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "Todo", "where", Relation_Text])
Error_Text = str(Context.exception)
Self.assertIn("Show Sm List Where expects PREDICATE=OBJECT", Error_Text)
def test_show_sm_list_number_with_md_suffix_reads_class_member_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Workdir_Path = Root_Path / "Work-Dir"
Build._Write_Sm_Json_File(
Output_Path=Build._Get_All_Dings_Sm2_Json_File_Path(Workdir_Path=Workdir_Path),
Sm_Dict={
"Dings_File": "All-Dings.sm2.json",
"Dings_List": [
{"Dings_Name": "Todo", "Dings_Number": "60203"},
],
"Dings_SM_Virtual_Class_List": [],
"Dings_SM_Class_Member_Map": {
"60203": [
{"Dings_Name": "Persisted-Todo", "Dings_Number": "123"},
],
},
"Dings_SM_Relation_Source_Map": {},
},
)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "60203.md"])
Output = Stdout.getvalue()
Self.assertEqual(Output, "[Todo](60203.md):\n [Persisted-Todo](123.md)\n")
def test_show_sm_todo_alias_is_rejected(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Workdir_Path = Root_Path / "Work-Dir"
Build._Write_Sm_Json_File(
Output_Path=Build._Get_All_Dings_Sm2_Json_File_Path(Workdir_Path=Workdir_Path),
Sm_Dict={
"Dings_File": "All-Dings.sm2.json",
"Dings_List": [
{"Dings_Name": "Todo", "Dings_Number": "60203"},
],
"Dings_SM_Virtual_Class_List": [],
"Dings_SM_Class_Member_Map": {
"60203": [
{"Dings_Name": "Persisted-Todo", "Dings_Number": "123"},
],
},
"Dings_SM_Relation_Source_Map": {},
},
)
with Self.assertRaises(SystemExit) as Context:
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "todo"])
Error_Text = str(Context.exception)
Self.assertIn("Show Sm Todo is no longer supported", Error_Text)
Self.assertIn("show sm list Todo", Error_Text)
def test_show_sm_dings_resolves_name_and_refs(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Test_Case_List = [
"Ridley_Scott",
"[Ridley_Scott](70000225)",
"[Ridley_Scott](70000225.md)",
]
for Target_Text in Test_Case_List:
with Self.subTest(Target_Text=Target_Text):
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "dings", Target_Text])
Output = Stdout.getvalue()
Self.assertIn("Dings: [Ridley_Scott](70000225.md)", Output)
def test_show_sm_dings_ambiguous_name_rejected(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Repo_Path = Root_Path / ".Dings" / "Repositories" / "300000007"
_Write_Text(
Repo_Path / "270001000.md",
"# Michael\n\n"
"I am a [Thing](60003.md).\n",
)
_Write_Text(
Repo_Path / "270001001.md",
"# Michael\n\n"
"I am a [Thing](60003.md).\n",
)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
with Self.assertRaises(SystemExit) as Context:
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "dings", "Michael"])
Error_Text = str(Context.exception)
Self.assertIn("Error: Ambiguous Dings-Name: Michael", Error_Text)
Self.assertIn("[Michael](270001000.md)", Error_Text)
Self.assertIn("[Michael](270001001.md)", Error_Text)
Self.assertIn("Use Dings-Number or Dings-Ref.", Error_Text)
def test_show_sm_list_virtual_name_reads_class_member_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "Super-Topic"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"[Super-Topic](600051.md):\n"
" [Sports](270100000.md)\n"
" [Soccer](270110000.md)\n",
)
def test_show_sm_list_accepts_virtual_ref_md(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "[Botanics-Plant](260030000.md)"])
Output = Stdout.getvalue()
Self.assertEqual(Output, "[Botanics-Plant](260030000.md):\n [Garden-Plant](260030001.md)\n")
def test_show_sm_list_rejects_invalid_ref_syntax(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
with Self.assertRaises(SystemExit) as Context:
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "Botanics-Plant[260030000.md]"])
Error_Text = str(Context.exception)
Self.assertIn("Invalid Dings-Ref Syntax: Botanics-Plant[260030000.md]", Error_Text)
Self.assertIn("[Dings_Name](DINGS_NUMBER.md)", Error_Text)
def test_show_sm_list_virtual_ref_reads_class_member_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "[Super-Topic](600051.md)"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"[Super-Topic](600051.md):\n"
" [Sports](270100000.md)\n"
" [Soccer](270110000.md)\n",
)
def test_show_sm_list_virtual_tue_topic_ref_reads_class_member_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "[TÜ-Topic](600051.md)"])
Output = Stdout.getvalue()
Self.assertEqual(Output, "[TÜ-Topic](600051.md):\n [Tennis](270200000.md)\n")
def test_show_sm_relation_virtual_tue_topic_reads_relation_source_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "where", "[TÜ-Topic](600051.md)=270200000"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"where [TÜ-Topic](600051.md)=[Tennis](270200000.md):\n"
" [Tennis-Club-Tübingen](270000011.md)\n",
)
def test_show_sm_relation_virtual_super_topic_reads_relation_source_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "where", "[Super-Topic](600051.md)=270100000"])
Output = Stdout.getvalue()
Self.assertIn("[Super-Topic-Source](4711.md)", Output)
Self.assertNotIn("[Soccer](270110000.md)", Output)
def test_show_sm_relation_canonical_topic_does_not_expand_virtual_base_relation(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "where", "[Topic](600051.md)=270200000"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"where [Topic](600051.md)=[Tennis](270200000.md):\n"
)
def test_show_sm_where_accepts_ref_md_predicate_and_object(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "where", "[Topic](600051.md)=[Music](90000000.md)"])
Output = Stdout.getvalue()
Self.assertIn("where [Topic](600051.md)=[Music](90000000.md):\n", Output)
Self.assertIn(" [Rock-Music](91001014.md)\n", Output)
Self.assertIn(" [Ein-Bug-Report-LWD-Movie.mov](400007354.md)\n", Output)
def test_show_sm_relation_accepts_md_suffix_targets(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "where", "600051.md=90000000.md"])
Output = Stdout.getvalue()
Self.assertIn("where [Topic](600051.md)=[Music](90000000.md):\n", Output)
Self.assertIn("[Rock-Music](91001014.md)", Output)
Self.assertIn("[Ein-Bug-Report-LWD-Movie.mov](400007354.md)", Output)
def test_show_sm_relation_debug_shows_spoc_derivation(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-debug", "-root", str(Root_Path), "Sm", "list", "where", "[TÜ-Topic](600051.md)=270200000"])
Output = Stdout.getvalue()
Self.assertIn(
"Claim: Subject=[Tennis-Club-Tübingen](270000011.md) Predicate_Base=I_Have Predicate_Role=[TÜ-Topic](600051.md) Object=[Tennis](270200000.md) Claimer=[Tennis-Club-Tübingen](270000011.md)",
Output,
)
Self.assertIn(
"Derived_Claim: Subject=[Tennis](270200000.md) Predicate_Base=I_Am Predicate_Role= Object=[TÜ-Topic](600051.md) Claimer=[Tennis-Club-Tübingen](270000011.md) Derived_From=Claim",
Output,
)
def test_show_sm_claims_from_reads_claim_claimer_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "claims-from", "270000011", "[TÜ-Topic](600051.md)"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"Claimer: [Tennis-Club-Tübingen](270000011.md)\n"
" Subject=[Tennis-Club-Tübingen](270000011.md) Predicate_Base=I_Have Predicate_Role=[TÜ-Topic](600051.md) Object=[Tennis](270200000.md)\n",
)
def test_show_sm_claims_from_accepts_concrete_ref_md(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show([
"-root",
str(Root_Path),
"Sm",
"claims-from",
"[Ein-Bug-Report-LWD-Movie.mov](400007354.md)",
])
Output = Stdout.getvalue()
Self.assertIn("Claimer: [Ein-Bug-Report-LWD-Movie.mov](400007354.md)\n", Output)
Self.assertIn("Predicate_Role=[Topic](600051.md) Object=[Music](90000000.md)", Output)
def test_show_sm_claims_from_does_not_expand_base_claim_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "claims-from", "270000011", "[Topic](600051.md)"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"Claimer: [Tennis-Club-Tübingen](270000011.md)\n",
)
def test_show_sm_claims_from_without_predicate_lists_claims(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "claims-from", "700000001"])
Output = Stdout.getvalue()
Self.assertIn("Claimer: [Person-A](700000001.md)\n", Output)
Self.assertIn(" Subject=[Person-A](700000001.md) Predicate_Base=I_Have Predicate_Role=[Topic](600051.md) Object=[Michael-Georg_Holzheu](0.md)", Output)
Self.assertIn(" Subject=[Person-A](700000001.md) Predicate_Base=I_Have Predicate_Role=[Name](60048.md) Object=[Michael-Georg_Holzheu](0.md)", Output)
def test_show_sm_claims_from_filters_by_predicate_role(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "claims-from", "700000001", "[Topic](600051.md)"])
Output = Stdout.getvalue()
Self.assertIn("Claimer: [Person-A](700000001.md)\n", Output)
Self.assertIn(" Subject=[Person-A](700000001.md) Predicate_Base=I_Have Predicate_Role=[Topic](600051.md) Object=[Michael-Georg_Holzheu](0.md)", Output)
Self.assertNotIn("Predicate_Role=[Name](60048.md)", Output)
def test_show_sm_claims_from_debug_shows_spoc_derivation(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-debug", "-root", str(Root_Path), "Sm", "claims-from", "270000011", "[TÜ-Topic](600051.md)"])
Output = Stdout.getvalue()
Self.assertIn(
"Claim: Subject=[Tennis-Club-Tübingen](270000011.md) Predicate_Base=I_Have Predicate_Role=[TÜ-Topic](600051.md) Object=[Tennis](270200000.md) Claimer=[Tennis-Club-Tübingen](270000011.md)",
Output,
)
Self.assertIn(
"Derived_Claim: Subject=[Tennis](270200000.md) Predicate_Base=I_Am Predicate_Role= Object=[TÜ-Topic](600051.md) Claimer=[Tennis-Club-Tübingen](270000011.md) Derived_From=Claim",
Output,
)
def test_show_sm_claims_from_accepts_command_local_debug(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "claims-from", "270000011", "-debug", "[TÜ-Topic](600051.md)"])
Output = Stdout.getvalue()
Self.assertIn(
"Claim: Subject=[Tennis-Club-Tübingen](270000011.md) Predicate_Base=I_Have Predicate_Role=[TÜ-Topic](600051.md) Object=[Tennis](270200000.md) Claimer=[Tennis-Club-Tübingen](270000011.md)",
Output,
)
Self.assertIn(
"Derived_Claim: Subject=[Tennis](270200000.md) Predicate_Base=I_Am Predicate_Role= Object=[TÜ-Topic](600051.md) Claimer=[Tennis-Club-Tübingen](270000011.md) Derived_From=Claim",
Output,
)
def test_show_sm_claims_is_rejected(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
with Self.assertRaises(SystemExit) as Context:
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "claims", "270000011", "[TÜ-Topic](600051.md)"])
Error_Text = str(Context.exception)
Self.assertIn("Show Sm Claims is no longer supported", Error_Text)
Self.assertIn("show sm -debug claims-from CLAIMER [PREDICATE]", Error_Text)
def test_show_sm_removed_v1_forms_are_rejected(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Test_Case_List = [
(["Sm", "names", "0"], "Show Sm Names is no longer supported", "show sm names-of TARGET [BASE]"),
(["Sm", "[Topic](600051.md)=270200000"], "Show Sm Relation without `where` is no longer supported", "show sm list where PREDICATE=OBJECT"),
(["Sm", "0"], "Show Sm Selection without `dings` is no longer supported", "show sm dings TARGET"),
]
for Arg_List, Message_Text, Hint_Text in Test_Case_List:
with Self.subTest(Arg_List=Arg_List):
with Self.assertRaises(SystemExit) as Context:
Cmd_Show._Cmd_Show(["-root", str(Root_Path)] + Arg_List)
Error_Text = str(Context.exception)
Self.assertIn(Message_Text, Error_Text)
Self.assertIn(Hint_Text, Error_Text)
def test_show_sm_names_of_target_reads_target_virtual_name_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "names-of", "0"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"Dings: [Michael-Georg_Holzheu](0.md)\n"
"View: [Dings_SM_Language](300043400.md)\n"
"\n"
"Remote_Names:\n"
" [Room-Mate](0.md) Count=1 From=[Person-A](700000001.md)\n"
" [Michael](0.md) Count=1 From=[Person-A](700000001.md)\n"
" [Informtaticer](0.md) Count=1 From=[Person-B](700000002.md)\n",
)
def test_show_sm_names_of_accepts_concrete_ref_md(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "names-of", "[Georg_Cantor](70000213.md)"])
Output = Stdout.getvalue()
Self.assertIn("Dings: [Georg_Cantor](70000213.md)", Output)
Self.assertIn("[Cantor](70000213.md) Count=1", Output)
def test_show_sm_names_of_rejects_non_canonical_concrete_ref(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
with Self.assertRaises(SystemExit) as Context:
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "names-of", "[Super-Topic](600051.md)"])
Error_Text = str(Context.exception)
Self.assertIn("Non-canonical Dings-Ref in Concrete Dings Mode", Error_Text)
Self.assertIn("Canonical Dings-Ref: [Topic](600051.md)", Error_Text)
def test_show_sm_names_of_base_filter_reads_target_virtual_name_map(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "names-of", "0", "[Name](60048.md)"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"Dings: [Michael-Georg_Holzheu](0.md)\n"
"View: [Dings_SM_Language](300043400.md)\n"
"Filter: [Name](60048.md)\n"
"\n"
"Remote_Names:\n"
" [Michael](0.md) Count=1 From=[Person-A](700000001.md)\n",
)
Self.assertNotIn("[Informtaticer](0.md)", Output)
def test_show_sm_names_of_debug_shows_source_refs(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-debug", "-root", str(Root_Path), "Sm", "names-of", "0", "[Name](60048.md)"])
Output = Stdout.getvalue()
Self.assertIn(" [Michael](0.md) Count=1 From=[Person-A](700000001.md)", Output)
Self.assertIn(" Source: [Person-A](700000001.md) Ref=[Michael](0.md) Line=7", Output)
Self.assertNotIn("[Informtaticer](0.md)", Output)
def test_show_sm_names_of_debug_shows_all_aggregated_source_refs(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Workdir_Path = Root_Path / "Work-Dir"
Build._Write_Sm_Json_File(
Output_Path=Build._Get_All_Dings_Sm2_Json_File_Path(Workdir_Path=Workdir_Path),
Sm_Dict={
"Dings_File": "All-Dings.sm2.json",
"Dings_List": [
{"Dings_Name": "Topic", "Dings_Number": "600051"},
{"Dings_Name": "Source-A", "Dings_Number": "307100003"},
{"Dings_Name": "Source-B", "Dings_Number": "688007"},
],
"Dings_SM_Target_Virtual_Name_Map": {
"600051": {
"Remote_Names": [
{
"Context_Key": "600051",
"Context_Class": {"Dings_Name": "Topic", "Dings_Number": "600051"},
"Dings_Ref": {"Dings_Name": "Creator", "Dings_Number": "600051"},
"Count": 2,
"From": {"Dings_Name": "Source-A", "Dings_Number": "307100003"},
"Source_Refs": [
{
"Source_Dings": "307100003",
"Source_Ref": {"Dings_Name": "Creator", "Dings_Number": "600051"},
"Line_Number": 8,
},
{
"Source_Dings": "688007",
"Source_Ref": {"Dings_Name": "Creator", "Dings_Number": "600051"},
"Line_Number": 9,
},
],
},
],
},
},
},
)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-debug", "-root", str(Root_Path), "Sm", "names-of", "[Topic](600051.md)"])
Output = Stdout.getvalue()
Self.assertIn(" [Creator](600051.md) Count=2 From=[Source-A](307100003.md)", Output)
Self.assertIn(" Source: [Source-A](307100003.md) Ref=[Creator](600051.md) Line=8", Output)
Self.assertIn(" Source: [Source-B](688007.md) Ref=[Creator](600051.md) Line=9", Output)
def test_show_sm_names_of_accepts_md_suffix_target_and_base(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "names-of", "0.md", "60048.md"])
Output = Stdout.getvalue()
Self.assertIn("Filter: [Name](60048.md)", Output)
Self.assertIn("[Michael](0.md) Count=1", Output)
Self.assertNotIn("[Room-Mate](0.md)", Output)
def test_show_sm_names_of_help_documents_use_cases(Self):
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["Sm", "names-of", "-h"])
Output = Stdout.getvalue()
Self.assertIn("Dings-Gpt Show Sm Names-Of", Output)
Self.assertIn("Use-Cases:", Output)
Self.assertIn("dings-gpt show sm names-of 0 '[Name](60048.md)'", Output)
Self.assertIn("dings-gpt show sm names-of 0 60048.md", Output)
Self.assertIn("Self_Names / Remote_Names keep Count and From", Output)
Self.assertIn("With -debug: Also show all Source-Refs", Output)
def test_show_sm_claims_from_help_documents_use_cases(Self):
for Help_Arg in ["-h", "-help", "--help"]:
with Self.subTest(Help_Arg=Help_Arg):
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["Sm", "claims-from", Help_Arg])
Output = Stdout.getvalue()
Self.assertIn("Dings-Gpt Show Sm Claims-From", Output)
Self.assertIn("CLAIMER:", Output)
Self.assertIn("PREDICATE:", Output)
Self.assertIn("dings-gpt show sm claims-from 400007354", Output)
Self.assertIn("dings-gpt show sm -debug claims-from 400007354", Output)
Self.assertIn("With -debug: Also show raw Claim and Derived_Claim details", Output)
Self.assertNotIn("Dings-Gpt Show Sm [OPTIONS] COMMAND", Output)
def test_show_sm_help_documents_v1_commands(Self):
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["Sm", "-h"])
Output = Stdout.getvalue()
Self.assertIn("COMMAND:", Output)
Self.assertIn("dings TARGET Show SM2 View for TARGET", Output)
Self.assertIn("names-of TARGET [BASE] Show virtual Names / Ref-Labels for TARGET", Output)
Self.assertIn("list [TARGET] [where PREDICATE=OBJECT]", Output)
Self.assertIn("Show a Dings Set:", Output)
Self.assertIn("list TARGET", Output)
Self.assertIn("list where PREDICATE=OBJECT", Output)
Self.assertIn("list TARGET where PREDICATE=OBJECT", Output)
Self.assertIn("Wildcards:", Output)
Self.assertIn("PREDICATE=*", Output)
Self.assertIn("*=OBJECT", Output)
Self.assertIn("*=*", Output)
Self.assertIn("Show all direct persisted Source Relations for matching Dings", Output)
Self.assertIn("claims-from CLAIMER [PREDICATE]", Output)
Self.assertIn("-debug claims-from CLAIMER [PREDICATE]", Output)
Self.assertIn("DINGS_NUMBER, DINGS_NUMBER.md, DINGS_NAME, DINGS_REF, or DINGS_REF_MD", Output)
Self.assertNotIn("where PREDICATE=OBJECT Show Dings matching SM Relation", Output)
Self.assertNotIn("Legacy:", Output)
Self.assertIn("dings-gpt show sm dings 0", Output)
Self.assertIn("dings-gpt show sm list Todo where '[State](60069.md)'=State_New", Output)
Self.assertIn("dings-gpt show sm list Todo where State=*", Output)
Self.assertIn("dings-gpt show sm list Todo where *=State_New", Output)
Self.assertIn("dings-gpt show sm list Todo where *=*", Output)
Self.assertIn("dings-gpt show sm list where State=*", Output)
Self.assertIn("dings-gpt show sm list where '[Topic](600051.md)'=90000000", Output)
Self.assertIn("dings-gpt show sm names-of 0 '[Name](60048.md)'", Output)
Self.assertIn("dings-gpt show sm claims-from 400007354", Output)
Self.assertIn("dings-gpt show sm claims-from 400007354 '[Topic](600051.md)'", Output)
Self.assertIn("dings-gpt show sm -debug claims-from 400007354", Output)
Self.assertNotIn("about SUBJECT [PREDICATE]", Output)
Self.assertNotIn("dings-gpt show sm about", Output)
Self.assertNotIn("Todo: Alias", Output)
Self.assertNotIn("claims CLAIMER [PREDICATE]", Output)
Self.assertNotIn("names TARGET [BASE]", Output)
def test_show_help_documents_generic_sm_commands(Self):
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Show._Cmd_Show(["-h"])
Output = Stdout.getvalue()
Self.assertIn("Dings-Gpt Show [REPRESENTATION] [SELECTION|COMMAND]", Output)
Self.assertIn("dings TARGET Show SM2 View for TARGET", Output)
Self.assertIn("names-of TARGET [BASE]", Output)
Self.assertIn("list [TARGET] [where PREDICATE=OBJECT]", Output)
Self.assertIn("claims-from CLAIMER [PREDICATE]", Output)
Self.assertIn("dings-gpt show sm list '[Super-Topic](600051.md)'", Output)
Self.assertIn("dings-gpt show sm claims-from 400007354", Output)
Self.assertIn("dings-gpt show sm claims-from 400007354 '[Topic](600051.md)'", Output)
Self.assertIn("dings-gpt show sm list Todo where '[State](60069.md)'=State_New", Output)
Self.assertIn("dings-gpt show sm list Todo where State=*", Output)
Self.assertIn("dings-gpt show sm list Todo where *=State_New", Output)
Self.assertIn("dings-gpt show sm list Todo where *=*", Output)
Self.assertIn("dings-gpt show sm list where '[Topic](600051.md)'=90000000", Output)
Self.assertIn("dings-gpt show sm names-of 0", Output)
Self.assertNotIn("about SUBJECT [PREDICATE]", Output)
Self.assertNotIn("dings-gpt show sm about", Output)
Self.assertNotIn("Todo: Alias", Output)
Self.assertNotIn("dings-gpt show sm todo", Output)
Self.assertNotIn("dings-gpt show sm '[Topic](600051.md)'=6666", Output)
def test_show_sm_legacy_fields_are_rejected(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
for Field_Text in ["Alias", "Topic", "Parent", "Predecessor", "Statements"]:
with Self.subTest(Field_Text=Field_Text):
with Self.assertRaises(SystemExit) as Context:
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "0", Field_Text])
Error_Text = str(Context.exception)
Self.assertIn("Show Sm Selection without `dings` is no longer supported", Error_Text)
Self.assertIn("show sm dings TARGET", Error_Text)
def test_show_sm_about_is_reserved(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
with Self.assertRaises(SystemExit) as Context:
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "about", "270000011"])
Error_Text = str(Context.exception)
Self.assertIn("Show Sm About is reserved for a future derived Claim View", Error_Text)
Self.assertIn("show sm claims-from CLAIMER [PREDICATE]", Error_Text)
Self.assertIn("show sm list where PREDICATE=OBJECT", Error_Text)
def test_show_sm_names_ambiguous_base_name_rejected(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Repo_Path = Root_Path / ".Dings" / "Repositories" / "300000007"
_Write_Text(
Repo_Path / "60049.md",
"# Name\n\n"
"I am a [Thing](60003.md).\n",
)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
with Self.assertRaises(SystemExit) as Context:
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "names-of", "0", "Name"])
Error_Text = str(Context.exception)
Self.assertIn("Error: Ambiguous Class Name: Name", Error_Text)
Self.assertIn("[Name](60048.md)", Error_Text)
Self.assertIn("[Name](60049.md)", Error_Text)
def test_show_sm_list_ambiguous_virtual_name_rejected(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Todo_Fixture(Root_Path=Root_Path)
Self._Write_Ambiguous_Super_Topic_Fixture(Root_Path=Root_Path)
Self._Write_All_Dings_Sm2_For_Todo_Fixture(Root_Path=Root_Path)
with Self.assertRaises(SystemExit) as Context:
Cmd_Show._Cmd_Show(["-root", str(Root_Path), "Sm", "list", "Super-Topic"])
Error_Text = str(Context.exception)
Self.assertIn("Error: Ambiguous Class Name: Super-Topic", Error_Text)
Self.assertIn("[Super-Topic](600051.md)", Error_Text)
Self.assertIn("[Super-Topic](60203.md)", Error_Text)
Self.assertIn("Use Dings-Number or Dings-Ref.", Error_Text)
def test_graph_classes_type_also_renders_also_class_forest(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Graph._Cmd_Graph(["-root", str(Root_Path), "Classes", "-type", "also", "640062"])
Output = Stdout.getvalue()
Self.assertEqual(
Output,
"# Domain-specific-Language (640062)\n"
"\n"
"Classes:\n"
"\n"
"\u251c\u2500\u2500 Formal-Language (640000)\n"
"\u2502 \u2514\u2500\u2500 Language (600041)\n"
"\u2502 \u2514\u2500\u2500 Thing (60003)\n"
"\u2514\u2500\u2500 Tool (250000001)\n"
" \u2514\u2500\u2500 Thing (60003)\n",
)
def test_graph_classes_type_option_can_follow_dings(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Graph._Cmd_Graph(["Classes", "640062", "-root", str(Root_Path), "-type", "also"])
Output = Stdout.getvalue()
Self.assertIn("\u251c\u2500\u2500 Formal-Language (640000)", Output)
Self.assertNotIn("Main:", Output)
def test_graph_classes_type_all_renders_main_and_also_sections(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Graph._Cmd_Graph(["-root", str(Root_Path), "Classes", "-type", "all", "640062"])
Output = Stdout.getvalue()
Self.assertIn("Main:\n\n\u2514\u2500\u2500 Language (600041)", Output)
Self.assertIn("Also:\n\n\u251c\u2500\u2500 Formal-Language (640000)", Output)
def test_graph_classes_type_all_without_main_renders_also(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Graph._Cmd_Graph(["-root", str(Root_Path), "Classes", "-type", "all,!main", "640062"])
Output = Stdout.getvalue()
Self.assertIn("\u251c\u2500\u2500 Formal-Language (640000)", Output)
Self.assertNotIn("Main:", Output)
def test_graph_classes_type_all_without_also_renders_main(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Graph._Cmd_Graph(["-root", str(Root_Path), "Classes", "-type", "all,!also", "640062"])
Output = Stdout.getvalue()
Self.assertIn("\u2514\u2500\u2500 Language (600041)", Output)
Self.assertNotIn("Also:", Output)
def test_graph_classes_type_list_renders_sections_in_requested_order(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
Stdout = io.StringIO()
with redirect_stdout(Stdout):
Cmd_Graph._Cmd_Graph(["-root", str(Root_Path), "Classes", "-type", "also,main", "640062"])
Output = Stdout.getvalue()
Self.assertLess(Output.index("Also:"), Output.index("Main:"))
Self.assertIn("Also:\n\n\u251c\u2500\u2500 Formal-Language (640000)", Output)
Self.assertIn("Main:\n\n\u2514\u2500\u2500 Language (600041)", Output)
def test_graph_classes_type_exclusion_needs_positive_value(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
with Self.assertRaises(SystemExit):
Graph._Build_Classes_Gr_From_Dings_Number(
Root_Path=Root_Path,
Dings_Number="640062",
Class_Type="!main",
)
def test_graph_classes_type_rejects_old_primary_value(Self):
with tempfile.TemporaryDirectory() as Temp_Dir:
Root_Path = Path(Temp_Dir) / "111"
Self._Write_Classes_Fixture(Root_Path=Root_Path)
with Self.assertRaises(SystemExit):
Graph._Build_Classes_Gr_From_Dings_Number(
Root_Path=Root_Path,
Dings_Number="640062",
Class_Type="primary",
)
def test_graph_classes_type_completion_lists_known_values(Self):
Candidate_List = Completion._Get_Bash_Candidate_List(
Word_List=["graph", "classes", "-type", ""],
Cword=3,
)
Self.assertEqual(Candidate_List, ["main", "also", "all"])
if __name__ == "__main__":
unittest.main()
|
|
|
|