def _compile_float(scmgr: StructureCheckerManager, x: JDef): Assert.isEqual(x.dataType, "float") #assert x.dataType == "float" return FloatValueChecker(scmgr, minValue=x.minValue, maxValue=x.maxValue, required=x.required, nullable=x.nullable)
def _compile_list(scmgr: StructureCheckerManager, x: JDef): Assert.isEqual(x.dataType, "list") #assert x.dataType == "list" return ListValueChecker(scmgr, minLength=x.minLength, maxLength=x.maxLength, allowedElementTypes=__compile_allowedElements( scmgr, x.elementTypes), required=x.required, nullable=x.nullable)
def connect(self) -> fabric.Connection: if self.__c is None: pwd = self.__passwordProvider(self.__hostName, self.__userName) config = fabric.Config(overrides={'sudo': {'password': pwd}}) self.__c = fabric.Connection(self.__hostName, self.__userName, self.__port, config=config, connect_kwargs={"password": pwd}) r = self.__c.run( self._encodeSSHCmdLine("/bin/echo", "foo \" \" bar"), hide=True) Assert.isTrue(self.__c.is_connected) Assert.isEqual(r.exited, 0) Assert.isEqual(r.stderr, "") Assert.isEqual(r.stdout, "foo \" \" bar\n") return self.__c
]], ["|c|*|d", None, []], ["|a|b", None, []], ] for p in PATTERNS: print("NOW PROCESSING:", p) if len(p) == 3: spath, result = FlexDataSelector(p[0]).getOne(dataTree) print("\tspath = " + repr(spath)) print("\tresult = " + repr(result)) if p[1] is None: Assert.isNone(result) Assert.isNone(spath) else: Assert.isInstance(result, p[1]) Assert.isInstance(spath, str) Assert.isIn(spath, p[2]) elif len(p) == 4: spath, result = FlexDataSelector(p[0]).getOne(dataTree) if p[1] is None: Assert.isNone(spath) Assert.isNone(result) else: Assert.isInstance(result, p[1]) Assert.isEqual(result, p[2]) Assert.isInstance(spath, str) Assert.isIn(spath, p[3]) else: raise Exception()
#!/usr/bin/python3 from jk_utils.datetime import * from jk_testing import Assert d1 = D.now() d2 = d1.nextDay().nextDay() Assert.isEqual(d2 - d1, 2) Assert.isEqual((d1.dayOfWeek + 2) % 7, d2.dayOfWeek) d1 = D.now().startOfWeek() d2 = d1.nextWeek() Assert.isEqual(d2 - d1, 7) d1 = D.now() d2 = d1.nextWeek() Assert.isTrue((d2 - d1) > 0) Assert.isTrue((d2 - d1) <= 7) Assert.isTrue(d2.dayOfWeek == 1) Assert.isTrue((d2 - 1).dayOfWeek == 7) Assert.isTrue(d2 >= d1) Assert.isTrue(d1 <= d2) d1 = D.now() d2 = d1.nextWeek().previousWeek() Assert.isTrue(d1 >= d2) for d in dateRange(d1.startOfWeek(), d2.nextWeek()): print(d, "\t", d.toJSON()) Assert.isEqual(len(list(dateRange(d1.startOfWeek(), d2.nextWeek()))), 7)
TEST_VECTOR_1 = ( ( "A1", "/", "/ab.cd", "/ab.cd" ), ( "A2", "/", "ab.cd", "/ab.cd" ), ( "A3", "/xy/z/", "ab.cd", "/xy/z/ab.cd" ), ( "A4", "/xy/z/", "../ab.cd", "/xy/ab.cd" ), ( "A5", "/xy/z/", ".././ab.cd", "/xy/ab.cd" ), ( "A6", "/xy/z/", ".././../ab.cd", "/ab.cd" ), ( "A7", "/xy/z/", ".././../../ab.cd", "/../ab.cd" ), ( "A8", "/xy/z/", "/a/ab.cd", "/a/ab.cd" ), ( "A9", "/xy/z/", "/../ab.cd", "/../ab.cd" ), ) for label, mergeURL1, mergeURL2, validationURL in TEST_VECTOR_1: print(label) Assert.isEqual( mergeURLPaths(mergeURL1, mergeURL2), validationURL ) print() urlCanonicalizer = URLCanonicalizer("https://www.xyz/startx/") TEST_VECTOR_2 = ( ( "B1", "http://test.abc/def.yz", "http://test.abc/def.yz", ), ( "B2", "//test.abc/def.yz", "https://test.abc/def.yz", ), ( "B3", "http:///def.yz", "http://www.xyz/def.yz", ), ( "B4", "/def.yz", "https://www.xyz/def.yz", ),
def _compile_null(scmgr: StructureCheckerManager, x: JDef): Assert.isEqual(x.dataType, "null") #assert x.dataType == "null" return NullValueChecker(scmgr, required=x.required)
#!/usr/bin/python3 from jk_testing import Assert from jk_trioinput import ConsoleInputHistory h = ConsoleInputHistory() h.append("123") h.append("wieu") h.append("LODJFKJHS") h.resetCursor() Assert.isEqual(h.prev(), "LODJFKJHS") Assert.isEqual(h.prev(), "wieu") Assert.isEqual(h.next(), "LODJFKJHS") Assert.isEqual(h.prev(), "wieu") Assert.isEqual(h.prev(), "123") Assert.isEqual(h.next(), "wieu") Assert.isEqual(h.prev(), "123") Assert.isEqual(h.prev(), None) Assert.isEqual(h.next(), "wieu") Assert.isEqual(h.next(), "LODJFKJHS") Assert.isEqual(h.next(), None) h = ConsoleInputHistory() h.append("123") h.append("wieu") h.append("LODJFKJHS") h.resetCursor()
import datetime import jk_utils.datetime from jk_utils.datatypes import * from jk_testing import Assert t = getTypeAsStr(123) print(t) Assert.isEqual(t, "int") t = getTypeAsStr(3.14) print(t) Assert.isEqual(t, "float") t = getTypeAsStr("abc") print(t) Assert.isEqual(t, "str") t = getTypeAsStr(True) print(t) Assert.isEqual(t, "bool") t = getTypeAsStr(False) print(t)
( D.parseFromStr("2020-01-02"), 4, 1 ), ( D.parseFromStr("2020-01-03"), 5, 1 ), ( D.parseFromStr("2020-01-04"), 6, 1 ), ( D.parseFromStr("2020-01-05"), 7, 1 ), ( D.parseFromStr("2020-01-06"), 1, 2 ), ( D.parseFromStr("2021-01-01"), 5, 1 ), ( D.parseFromStr("2021-01-02"), 6, 1 ), ( D.parseFromStr("2021-01-03"), 7, 1 ), ( D.parseFromStr("2021-01-04"), 1, 2 ), ) for d, dayOfWeek, weekNo in DATE_DATA: print(d) print("dayOfWeek") Assert.isEqual(d.dayOfWeek, dayOfWeek) print("weekNo") Assert.isEqual(d.weekNo, weekNo) for y in range(2000, 2200): d = D.createFrom(y, 1, 1) Assert.isEqual(d.weekNo, 1) d = d.nextWeek() Assert.isEqual(d.weekNo, 2) print() print("Success!")
#!/usr/bin/python3 from jk_testing import Assert from jk_bincontainer import BinContainer BYTE_BLOCKS = { "abcd": b"\x01\x02\x03", "defg": b"\x02\x03\x04", "yyyy": b"\x03\x04" * 123, "xxxx": b"\x03\x04" * 1024 * 512, } bc = BinContainer() for k, v in BYTE_BLOCKS.items(): bc.addBinaryBlock(k, v) raw = bc.toBytes() #print(raw) bc2 = BinContainer() bc2.loadFromData(raw) bc2.dump() for k, v in BYTE_BLOCKS.items(): blockType, blockData = bc2.getBlockByKeyE(k) Assert.isEqual(v, blockData)