defl/tests.old/test_cliWrap.py

64 lines
1.5 KiB
Python
Raw Permalink Normal View History

2024-09-11 11:14:03 -04:00
#!/usr/bin/env python
import enum
import itertools
import json
import os
import re
import sys
from dataclasses import KW_ONLY, dataclass, field
from functools import partial, partialmethod
from operator import itemgetter
from tabnanny import verbose
from time import sleep
from traceback import print_list
import defl
from defl import CLIError, DotDict, Null, Path, Undefined, cl, log
from defl._assert_ import Assert
from defl._typing_ import *
from defl.testing_ import Tester
from defl.cliWrapper_ import *
tester = Tester(name=__file__)
2025-03-09 09:17:53 -04:00
2024-09-11 11:14:03 -04:00
@dataclass(slots=T, kw_only=T, frozen=T)
2025-03-09 09:17:53 -04:00
class Opt(CliOptions):
2024-09-11 11:14:03 -04:00
_OptionsMap = {'a': '--aaa', 'b': '-b', 'c': '-c', 'd': '-d', 'e': '-e', 'f': '-f'}
a: str | N = N
b: str | N = N
c: str | N = N
d: str | N = N
e: str | N = N
f: str | N = N
listt: list[str] | N = N
2025-03-09 09:17:53 -04:00
2024-09-11 11:14:03 -04:00
@tester.add()
def join():
a = Opt(a='a')
b = Opt(b='b')
c = Opt(c='c')
d = Opt(d='d')
e = Opt(e='e')
f = Opt(f='f')
la = Opt(listt=['la'])
lb = Opt(listt=['lb'])
Assert(a | b | c | d | e | f) == Opt(a='a', b='b', c='c', d='d', e='e', f='f')
Assert(la | lb) == Opt(listt=['la', 'lb'])
Assert(la | lb | la) == Opt(listt=['la', 'lb', 'la'])
2025-03-09 09:17:53 -04:00
2024-09-11 11:14:03 -04:00
@tester.add()
def cli():
Assert((a | b | c | d | e | f).cli) == ['--aaa=a', '-b=b', '-c=c', '-d=d', '-e=e', '-f=f']
Assert((la | lb | la).cli) == ['--listt=la', '--listt=lb', '--listt=la']
2025-03-09 09:17:53 -04:00
2024-09-11 11:14:03 -04:00
log.info(tester.run())
tester.exitWithStatus()
# for i in ch:
# print(defl.printTable([[y for y in x] for x in ch], squareFill=True))