parent
commit
868d2af03d
3 changed files with 89 additions and 0 deletions
  1. +47
    -0
      py/cfg_aux_test.py
  2. +22
    -0
      py/cfg_test.py
  3. +20
    -0
      py/do-test.py

+ 47
- 0
py/cfg_aux_test.py View File

@@ -0,0 +1,47 @@
from cfg_aux import *

def test_cfg_aux_tree(
) -> str:
lines = [
"[abc]",
"width = 100",
"wrongSep=another",
"[def]",
"anotherWrongSep -> whatever",
"title = yo",
"subtitle = whoa",
]
tree = cfg_aux_tree(lines)
if (
cld_len(tree) == 2 and
cld_len(tree["abc"]) == 1 and
cld_len(tree["def"]) == 2
):
return "OK: cfg_aux_tree"
return "ERR: cfg_aux_tree"

def test_cfg_aux_treeCreateSection(
) -> str:
tree: dict[str, dict[str, str]] = {}
line = "[abc]"
sectionName = cfg_aux_treeCreateSection(tree, line)
if (
sectionName == "abc" and
cld_len(tree) == 1
):
return "OK: cfg_aux_treeCreateSection"
return "ERR: cfg_aux_treeCreateSection"

def test_cfg_aux_treeSetKeyValue(
) -> str:
tree: dict[str, dict[str, str]] = {}
line = "[abc]"
sectionName = cfg_aux_treeCreateSection(tree, line)
line = "title = wazup"
cfg_aux_treeSetKeyValue(tree, sectionName, line)
if (
cld_len(tree[sectionName]) == 1 and
tree[sectionName]["title"] == "wazup"
):
return "OK: cfg_aux_treeSetKeyValue"
return "ERR: cfg_aux_treeSetKeyValue"

+ 22
- 0
py/cfg_test.py View File

@@ -0,0 +1,22 @@
from cfg import *
from ht_Context import *

def test_cfg_parseConfigTree(
) -> str:
c = ht_createContext()
c.cfgContents = [
"[abc]",
"width = 100",
"wrongSep=another",
"[def]",
"anotherWrongSep -> whatever",
"title = yo",
"subtitle = whoa",
]
c.recentField = "cfgContents"
c = cfg_parseConfigTree(c)
if (
cld_len(c.cfgTree) == 2
):
return "OK: cfg_parseConfigTree"
return "ERR: cfg_parseConfigTree"

+ 20
- 0
py/do-test.py View File

@@ -0,0 +1,20 @@
#!/usr/bin/env python3

import os
import sys

SCRIPT_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
sys.path.append(f"{SCRIPT_DIR}/../../cross-language-dialect/lib")

from cfg_aux_test import *
from cfg_test import *

functions = [
test_cfg_parseConfigTree,
test_cfg_aux_tree,
test_cfg_aux_treeCreateSection,
test_cfg_aux_treeSetKeyValue,
]

for f in functions:
print(f())

Loading…
Cancel
Save