#!/usr/bin/env python from dataclasses import dataclass, field from collections import Counter import sys, re, os, enum, itertools, inspect from functools import partial, partialmethod from time import sleep from subprocess import Popen, PIPE, DEVNULL from operator import itemgetter from defl import ( log, cl, Dath, Undefined, Null, Assert, Time, Obj, IterableType, isIterableType, Run, checkType, richReprAuto, quoteSh, ) from defl import CLIError from defl._typing_ import * from defl._typing_ import T, F, N, U from defl._rich_ import * import defl from defl.testing_ import Tester tester = Tester(name=__file__) @tester.add() def testStackLocalValue(): def a(): dog = T return b() def b(): return c() def c(): return d() def d(): return defl.stackLocalValue(leaf='dog') Assert(a()) == T @tester.add() def testStackLocalValue(): def a(): dog = T return b() def b(): return c() def c(): return d() def d(): return defl.stackLocalValue(leaf='dog', stem='cat') Assert(a()) == N @tester.add() def testStackLocalValue(): def a(): dog = T return b() def b(): cat = T return c() def c(): cat = T return d() def d(): # cat = T return defl.stackLocalValue(leaf='dog', stem='cat') Assert(a()) == T def testStackInfo_a(): dog = T return testStackInfo_b() def testStackInfo_b(): cat = F return testStackInfo_c() def testStackInfo_c(): cat = T return testStackInfo_d() def testStackInfo_d(): return [i for i in defl.stackInfo()] @tester.add() def testStackInfo(): s = defl.stackInfo() s = next(s) print(s.toJson()) assert isinstance(s, defl.StackItem), print(type(s)) assert isinstance(s.f, FrameType), print(type(s.f)) assert isinstance(s.c, CodeType), print(type(s.c)) s = testStackInfo_a() Assert(s[0].name) == 'StackItem.FullStack' Assert(s[1].name) == 'testStackInfo_d' Assert(s[2].name) == 'testStackInfo_c' Assert(s[3].name) == 'testStackInfo_b' Assert(s[4].name) == 'testStackInfo_a' Assert(s[0].locals()) == {'frame': N} Assert(s[1].locals()) == {} Assert(s[2].locals()) == {'cat': T} Assert(s[3].locals()) == {'cat': F} Assert(s[4].locals()) == {'dog': T} Assert(s[4].dog) == T @tester.add() def testAmEntry(): def amEntry1(): CLI_LEAF = T return amEntry2() def amEntry2(): CLI_STEM = T return amEntry3() def amEntry3(): return defl.amCliEntryPoint() assert not defl.amCliEntryPoint() assert amEntry1() assert not amEntry2() assert not amEntry3() log.info(tester.run()) tester.exitWithStatus()